To turn on and off a LED by using the potentiometer.
EQUIPMENT:
- 1 x Yellow LED
- 1 x Potentiometer (10k ohm)
- 1 x 330 Ohm Resistor (Orange-Orange-Brown)
- 6 x Wire (any colour)
- 1 x CIRC-08 Breadboard Sheet
- 1 x Arduino Uno
- 1 x Arduino Holder
- 1 x Breadbaord
In this circuit lab, a potentiometer was introduced. A potentiometer is an useful device that provides a variable resistance dependant on the angle to which it turns. An Arduino microcontroller has digital pins and 6 analog pins for analog input. These inputs take in a volt of 0-5 and convert it to a digital number between 0 and 1024. The potentiometer is called called a variable resistor. If connected with 5V across its outer pins the middle pin will give some value between 0 and 5 volts dependant on the angular location of the shaft (e.g. 2.5V in the middle). The returned values can be used as a variable in the program.
In the programming part, we learned how to deal with things that aren't digital. Although, the Arduino is a digital machine, it has the ability to operate with the analog pins and inputs. The analogRead(pin) method was used in this lab. When the analog input pins are set to input you can read their voltage which is a integer between 0(0 volts) and 1024(5volts). Therefore, this method gave a value which helped to determine the amount of time the LED should be on and off.
Simple circuits can sometimes be a headache while you attach the parts on to the breadboard. So we chose to start off with the main component (for this lab, it's the potentiometer) and we left the wiring for the very last. We studied the schematic diagram at the start as well , as we knew that it will give us a better understanding of the current flow path in our circuit.
Fritzing Diagram of CIRC-08. (Image Link) |
Click ME for the Image Link! |
TIME TO COMPLETE:
7 minutes to build, 5 minutes to program.
RESULTS:
Our potentiometer was not working from time to time. We guessed that it was most likely due to a slightly dodgy connection with the potentiometer's pins. So we taped the potentiometer down to obtain better connections. Afterwards, it worked successfully and the yellow LED turned on and off as it was programmed to do so.
PHOTOS OF PROJECT:
Ultimate Functional Twisting Circuit (CIRC-08) |
TIPS:
Things not working out? Check to see if you have accidentally connected the potentiometer's wiper to digital pin 2, rather than analog pin 2.
Still backward? You can try operating your circuit upside down because sometimes this helps.
FURTHER WORK:
There are two things I would like to try to expand my knowledge on this circuit lab:
1) Threshold switching: Switching an output when a value exceeds a specific threshold. This can be done with a potentiometer by changing the loop() code to:
void loop() {
int threshold = 512;
if(analogRead(sensorPin)> threshold){
digitalWrite(ledPin, HIGH);}
else{digitalWrite(ledPin, LOW);}
}
This will make the LED turn on when the value is above 512(hallway), sensitivity can be adjusted by changing the threshold value.
2)Fading: Controlling brightness of LED directly from the potentiometer. To do this the pin the LED is connected to must be moved ( for instance, moving the wire from pin 13 to pin 9 will do so). Then I need to change only one line of code. int ledPin = 13; -----> int ledPin = 9; Lastly, the loop code needs to be modified to the follwoing:
void loop() {
int value = analogRead(potPin) / 4;
analogWrite(ledPin, value);
}
The above codes will make the LED fade in relation to our potentiometer spining.
PROGRAM MODIFICATIONS:
My program is the very same as the one in the Sparkfun Inventor's Guide (Pg. 22 and 23).
It's also the same as the one in this LINK.
PROGRAM (with comments):
*/
int sensorPin = 0; // select the input pin for the potentiometerint ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for
delay(sensorValue);
}
REFERENCE:
- http://ardx.org/POTE
- http://ardx.org/CIRC04
- http://ardx.org/VIDE04
- http://arduino.cc/en/Tutorial/AnalogInput
No comments:
Post a Comment