• KJ Ha

Simple Circuit


Completed circuit.



First, I defined the pins that LED and switch are connected to. On the breadboard, the red LED is connected to 13 pin and the switch is connected to 2 pin respectively.

The variable "LedOn" stores the current state of LED. Depending on its value LED is being turned on or turned off. I set the initial value of the LED pin to LOW, letting the off state be the initial state.

Inside the loop function, the state of the switch is being read. Depending on it states, LED is being turned on or turned off. When the switch is pressed, LedOn is false, LED is turned on and LedOn value is then changed into true. Otherwise LED is turned off and LedOn value will be changed into false.

Since I used a 9V battery as a power supply, an ideal value of the resistor would be 450Ω, according to Ohm's Law (450Ω = 9V/0.02A); however, I used a 220Ω resistor, the resistor with the closest value at my disposal.




© 2020 Kyungjoo Ha. All Rights Reserved