In this tutorial we build an interactive arduino project and explore what can be done with just one LED (light emitting diode) and a couple of buttons.
Step 1: Build Your Circuit
In this project, we will use two push buttons (tact switches)
Insert them into a breadboard as shown in the photo - make sure you position them the right way around (metal legs at the sides, rather than top and bottom)
Connect the top left leg of both buttons to GND pins on the arduino (see black wires)
Connect the bottom left leg of one button to pin 8 on the arduino (see orange wire)
Connect the bottom left leg of the other button to pin 7 on the arduino (see blue wire)
Insert an LED (light emitting diode) into the arduino pins 13 and GND (depending on the type of LED you are using, you might need to add a resistor as described in step 1 of this instructable)
Step 2: Write Your Code
The next step is to write some code to control the LED using the buttons.
Download the Dimmer.ino file and open it up in the Arduino application. You can tinker with it if you like, or just use it as it is.
One thing you'll notice is the use of "INPUT_PULLUP" in the code...
If left to themselves, Input pins on arduinos tend to float around a whole range of values (a bit like a balloon drifting in the wind). This can cause problems when reading values from them - is it up or is it down ?
By using "INPUT_PULLUP" in the code, it causes the input pin to be drawn towards the HIGH value (a bit like filling the balloon with helium). The pin will be pulled upwards and will give a high reading.
When the button is pressed, the pin gets connected to ground and immediately jumps to LOW.
When the button is released, the helium effect takes over and the pin rises back up to HIGH
Step 3: Upload Your Program
Make sure you have the your arduino model selected and the correct serial port ticked (see screenshot).
Then just click the upload button
Note: With some arduino models (e.g. Leonardo) you need to reset the arduino when uploading:
- Hold down the plastic/metal reset button on the board
- Click the upload button in the arduino application
- Wait until the "uploading" message appears at the bottom of the arduino window
- Let go of the reset button on the arduino
Your code should now upload (might have to practice your timing to get it right ;o)