EQUIPMENT:
- 2 x Pushbuttons
- 2 x 10k Ohm Resistor
- 4 x 330 Ohm Resistor
- 4 x LED
- 10 x Wire (any colour)
- 1 x Arduino Uno
- 1 x Arduino Holder
- 1 x Arduino Breadboard
- 1 x Reference Sheet
PROGRAM DETAILS:
In this assignment, we are asked to make a circuit with 4 LEDs and 2 pushbuttons that does the following:
1. When one button is pressed, all even LED's will turn on for 0.5 seconds then go off.
2. When the other button is pressed, all odd LED's will turn on for 0.5 seconds then go off.
The main hardware component used is called the Pushbutton which is a device controlled by the user. When pressed, the pushbutton completes a circuit, and it can complete up to two different circuits. It looks like a small black square with four silver leads outat the bottom and a button on the top.
One of the methods used to code the PART 1 of these assignments is pinMode(pin, INPUT) which declares pushbutton as input. Here, the Arduino takes in an input so we must use the digitalRead(pin) method, rather than digitalWirte(pin). The method digitalRead(pin) returns whether it is HIGH(pulled to +5volts) or LOW(pulled to ground).
Putting this circuit together and wiring up the pushbuttons was fairly easy. However, the component, pull up resistor can seem out of place at times. The pull up resistor is included in the circuit because the Arduino Uno doesn’t sense the same way humans do. Instead it requires checking the voltage on the pin and then it decides whether it is HIGH or LOW.
One of the methods used to code the PART 1 of these assignments is pinMode(pin, INPUT) which declares pushbutton as input. Here, the Arduino takes in an input so we must use the digitalRead(pin) method, rather than digitalWirte(pin). The method digitalRead(pin) returns whether it is HIGH(pulled to +5volts) or LOW(pulled to ground).
Putting this circuit together and wiring up the pushbuttons was fairly easy. However, the component, pull up resistor can seem out of place at times. The pull up resistor is included in the circuit because the Arduino Uno doesn’t sense the same way humans do. Instead it requires checking the voltage on the pin and then it decides whether it is HIGH or LOW.
TIME TO COMPLETE: 10 minutes to build the circuit, 20 minutes to code.
RESULTS:
In the first try, the LED was not turning on. The two pushbuttons are small squares and this is why it’s very easy to attach them to the breadboard in the wrong way. Since it was attached it in the wrong way, the LED didn’t blink so I gave it a 90 degree twist and then, it worked as it was supposed to.
PHOTOS OF PROJECT:
4 LEDs, 2 Pushbuttons Circuit (PART 1) |
TIPS:
The first tip I would give is when you press the pushbuttons, make sure you press them hard or else the circuit won’t be complete. Another tip is that you should be carefully choosing the Ohm Resistors. Since there are two different types of resistor (10k and 330) involved in this circuit, you might confuse yourself and choose the wrong one.
FURTHER WORK:
My further work would be completing the PART 2 of this Button Control Assignment.
PROGRAM MODIFICATIONS:
My program looks similar to the one from:THIS LINK! However, I used 4 LEDs and the corresponding number of resistors to build this circuit. Also, I followed the instructions from tiny.cc/ArduinoGuide (CIRC-07 Button Control Assignment PART 1). Thus, there are few minor changes here and there in my program.
PROGRAM (with comments):
//CIRC-07 PART 1
int onButton = 2; // Initializes variables
int offButton = 3;
int ledPin[] = {13,12,11,10}; // Keeps track of the LED pin number
void setup()
{
for(int i = 0; i <4; i++)
{
pinMode(ledPin[i], OUTPUT); // Sets the Pin Mode of LED Pins to OUTPUT
}
pinMode(onButton, INPUT); // Sets the Pin Mode of Button to INPUT
pinMode(offButton, INPUT);
}
void loop() // Everything in the brackets will be looped
{
int delayTime = 500; // Waiting period
if (digitalRead(onButton) == HIGH) // When Button 1 is pressed, the following will occur.
{
digitalWrite(ledPin[0], HIGH);
digitalWrite(ledPin[2], HIGH);
delay(delayTime);
digitalWrite(ledPin[0], LOW);
digitalWrite(ledPin[2], LOW);
}
else if (digitalRead(offButton) == HIGH); // When Button 2 is pressed, the following will occur.
{
digitalWrite(ledPin[1], HIGH);
digitalWrite(ledPin[3], HIGH);
delay(delayTime);
digitalWrite(ledPin[1], LOW);
digitalWrite(ledPin[3], LOW);
}
- Sparkfun Inventor's Guide
- tiny.cc//ArduinoGuide
- http://ardx.org/CIRC07
- http://ardx.org/VIDE07
- http://www.0j0.org
No comments:
Post a Comment