This project uses your new digital input skills. You’ll use the pushbutton component to create a basic LED flashlight where the LED turns on and off as a response to a button push.
Now that you’ve worked with basic digital input with the pushbutton, it’s time for a project! This activity will build on the skills you’ve used in the multi-LED projects as well as the pushbutton lesson.
The core of this activity is to create a circuit where a variety of LEDs will be controlled by a pushbutton. The timing and behavior of the LEDs are completely up to you. The basic concept is that the LEDs will behave one way when the button is OFF (not pressed) and another way when the button is ON (pressed).
One key point to remember is that for every new LED you’re using, you’ll need to make sure that you have a corresponding output pin set in your code!
Instead of the state of the LED being solely determined by your code (blinking on and off in a loop), you’re going to attach a button so that you can control whether the LED is on or off.
Use the above diagram to guide you as you connect the circuit.
– rail on the breadboard connects to GND on UnoOnce your supplies are gathered, connect the breadboard to the Arduino:
+ rail on the breadboard connects to 5V on Uno
Connect both sides of the breadboard: – to – and + to +
Connect the pushbutton so that it straddles the middle notch in the breadboard.
Connect the top leg of the button to the + rail.
Connect the bottom leg of the button to the resistor.
Connect the other leg of the resistor to the – rail on the breadboard.
Connect the opposite leg of the button/resistor to PIN 2 (or whatever pin you set) of the Uno.
Connect the LED to PIN 13 (or whatever pin you set) using the resistor, as you did in previous projects.
You’ll be working from a basic code skeleton. However, for an additional challenge, you should write your own code from scratch! Try to use the code as a reference and write your own so that you understand it.
After completing the base activity and successfully wiring up the LEDs and the button, go ahead and try some of these challenges:
Challenge One: Modify the code so that the LEDs turn on in a specific sequence, but only while the button is pressed. Think of this sequence as if it were a secret code, or a Morse code message that you’re transmitting! Work with one of your peers to create a unique code and communication device!
Challenge Two: Create a physical enclosure for your lights and button, as if you’re creating a dashboard or an interface for the lights and buttons. Consider programming the button in such a way that it powers up the console once it’s activated!
The goal of this experiment is to develop an understanding of pushbuttons and how they fit within a circuit. Once you’ve developed an understanding of this process, you’ll be able to repeat the button circuit and add it to other projects!
Remember, while this particular project used a button to control LEDs, you could easily swap out other components and make a button that controls something else, such as a servo motor!