Ohm's law in a sketch
Arduino C++Make an Uno do the paper maths and print the current for each jumper row (220, 1000 and 10000 ohm) with a 5 V supply and a 2 V LED, in the form "220 ohm: 13.64 mA". The starter prints 0 mA for all three rows: find out why. Then add one line with the smallest resistor that keeps the LED at 20 mA: "20 mA needs 150 ohm".
Checks
- Not run yet220 ohm: 13.6 mA
- Not run yet1000 ohm: 3.0 mA
- Not run yet10000 ohm: 0.30 mA
- Not run yetPrints 20 mA needs 150 ohm
Hints
- In C++ an int divided by an int is an int: 3 / 220 is 0, and 0 × 1000 is still 0.
- Make the numbers float (5.0, 2.0, 1000.0) and the division keeps its decimals.
- R = (V − V_F) / I, with I in amps: 3.0 / 0.020 = 150. Serial.print(x, 0) prints a float with no decimals.