How does it work?
Whenever a press the button the led is switched on.
After 2 seconds the led is switched off.
Things you need:
- a Breadboard
- a led
- a button
- 2 resistors (220Ohms)
- jumper wires.
Connect it up
Now, first make sure that your Arduino is powered off (unplug the USB cable or the external battery).
Then connect everything up like this:
The led
Make sure that your LED is connected the right way with the longer leg connected to Digital pin 8.
The long leg is the Anode of the LED and always must go to the +5V supply (in this cased coming out of Digital pin 8).
And the short leg is the Cathode and is connected to a resistor (to limit the current that goes through the led and then to Gnd (Ground).
The button
Normally the button is not pressed and therefore the circuit is open and 0V(LOW) will be supplied to pin3.
When the button is pressed, the circuit is closed and 5V(HIGH) will be supplied to pin3.
Arduino board will read the PIN3 and if it is HIGH Arduino will send 5V to pin8 so the led will be switched on.
After a while (a delay we introduce in the code) the led will be switched off again until someone presses it again.
The code
We can use Bitbloq free software to easily code the program using blocks.
By adding the different components, the needed blocks will become available.
The program using blocks:
BitBloq Application will translate those blocks into the Arduino code. See how it looks like:
You can see that in the code we are sending the value read in pin3 (variable press) through the serial port to the computer, so we can see the value on the Serial Monitor (view menu)
Comments
Post a Comment