Page 1

Anujen Thedchanamoorthy  

Project 1: Pushbutton Controlled LED Start Date: Friday, 6 September, 2013 Completion Date: Friday, 6 September, 2013 Project Duration: 1.5 hours


2   Goal: To use a momentary switch (pushbutton) and Arduino Uno microcontroller to control the state of an LED.

Materials Used: • • • • • • • •

Arduino Uno R3 Breadboard Jumper wires 1 5mm red diffused LED 1 SPST N/O pushbutton 1 220Ω resistor 1 100Ω resistor 1 10kΩ resistor

Schematic:


3

Procedure: 1. Connect 5V pin from Arduino to + (red line) and the GND pin from the Arduino to – (the blue line) at the top of breadboard. Jump wires across the board to have easy access to the power supply at the both ends. 2. Connect a wire from digital pin 2 to an open column on the breadboard and connect it to one leg of the pushbutton. In the same column, connect 1 leg of the 10kΩ resistor and the other to ground. This resistor functions as a pull-down resistor. 3. Connect the open leg of the pushbutton to the 5V power source. 4. Jump a wire from digital pin 11 on the Arduino to the breadboard and connect one leg of the 100Ω resistor to the column in the breadboard that you just connected the wire to. Connect the other leg to an open column. 5. Connect one leg of the 220Ω resistor to the open leg of the 100Ω resistor and the other leg to a new column on the breadboard. 6. Next, connect the anode (+) or long leg of the LED to the open leg of the 220Ω resistor and the cathode (-) or shorter leg to an open column on the breadboard. 7. Finally, use a wire to connect the cathode to the GND supply across the bottom or top of the breadboard.

Code: /* Project 1 - Pushbutton Controlled LED In this project, we will use a momentary switch or pushbutton to control the state of an LED (on or off). By: Anujen Thedchanamoorthy */ int led=11; //declare "led" to be digital input pin 11. int button=2; //declar "button" to be digital input pin 2. int val=0; void setup () { pinMode(led,OUTPUT); //declares the led pin (11) as an output. pinMode(button,INPUT); //declares the button pin (2) as an input. } void loop() { val = digitalRead(button); //reads the pushbutton's state as HIGH or LOW digitalWrite(led,val); //writes the read value to the LED to turn it ON or OFF }


4   Results & Discussion: During this project, I encountered a few obstacles and unexpected results that helped me learn more about the behavior of electronic circuits and the Arduino itself.

While trying to effectively create the required circuit, I encountered difficulties and questions as to why I was experiencing different phenomena. These include: • Case 1: No 10kΩ pull-down resistor • Case 2: Replacing the 10kΩ pull-down resistor with a wire • Case 3: Moving the leg of the pushbutton connected to VCC to GND instead Below, I will be outlining my observations and my explanation as to why the circuit behaved the way it did in each scenario. Case 1

Observations - When the button was pressed, the LED was completely ON and at its brightest state. - When the button was un-pressed, the LED would flicker occasionally and appeared slightly dimmer than the completely ON state described when the pushbutton was pressed.

Explanation - Without the pull-down resistor, the electromagnetic (EM) “noise” of the environment affected the transistors that read the Arduino pin’s states. As a result, the transistor was in a “floating” state in which the state of the pin was read between HIGH and LOW. This accounts for the flickering and dimness. - When the button was fully pressed under these conditions, even more EM noise is allowed to reach the input pin causing it to read HIGH. This made the LED turn completely ON.


Â

5 Â 2

- When the button was un-pressed, the LED was off completely. - When the button was pressed, I got the following error on my computer:

- When the button was un-pressed, there was no voltage being applied however it can also be seen that there is no EM noise. This is because now there is a direct connection to GND via the wire unlike Case 1. - The reason I obtained the error when the button was pressed is because, by pressing the button I am effectively directly connecting VCC to GND causing a short circuit. The error pops up and shuts down my USB ports to protect both my computer and the Arduino.

3

- Similar to Case 1, when the button was un-pressed, the LED would flicker occasionally and appeared slightly dimmer than the completely ON state described when the pushbutton was pressed. - When the pushbutton was pressed, the LED was turned completely OFF.

- Again, the reason why the un-pressed pushbutton would yield these results lies in EM noise in the surroundings. - The LED turned OFF completely because the pushbutton is now directly connected to GND, ensuring that the pin reads LOW. - A pull-up resistor (opposite of a pulldown resistor) can be used to combat this scenario however, this would cause reverse functionality. That is to say, the LED would always be ON until the button was pressed at which time the LED would turn OFF.

Pushbutton un-pressed, LED OFF

Pusbutton pressed, LED ON

After some researching and troubleshooting, I was able to not only complete the project as intended but also learned some core electronics concepts along the way.

Project 1  

Pushbutton Controlled LED