Use a Potentiometer to control the time interval between an LED turning off and on.
Equipment:
- 1x Arduino Uno
- 1x Breadboard
- 1x Potentiometer
- 1x 330 Ohm Resistor
- 1x LED
- 6x Wires
Reference:
Program Details:
In terms of hardware, one new piece of hardware is introduced. This is another user controlled device, like the pushbutton. The difference being this one has more than two values, as it returns a 10 bit signal. This is helpful as it gives us more control than a pushbutton. For this Potentiometer to work, it needs 3 connections. The first two is a 5 Volt signal passing through it, with one end receiving the electricity, and the other end being grounded. The final pin, the one in the middle, is needed to give data to an analog pin.The number which it gives out is between 0 (0 volts) and 1024(5 volts). This number changes depend on the angle which the knob it twisted by the user. This particular Potentiometer has a 10k Ohm resistor.
In terms of programming, we are introduced to a new yet familiar method. This method is anologRead(pin #). This means that this is the first time we are working with an actual analog pin, rather that a PWM digital pin. The anologRead behaves just like digitalRead(pin #), but this time it reads more than just HIGH and LOW. This is needed because the Potentiometer sends an analog signal, not a digital one.
Finally, to assemble this we need to fist create two independent circuits. The first circuit is a very simple single LED circuit; which looks just like the one from Experiment 1and Experiment 7. Then we create another circuit for the Potentiometer, but this one is a bit more complex. The two end pins have a circuit flowing through it, with 5V coming from one end, and being grounded at the other. Then a wire carries the signal from the center to Pin 0.
Results:
It worked at intended the first time we uploaded the code and supplied power.
Tips:
If the Potentiometer is not consistent, try taping it down. This should secure the connection.
Further Work:
You can change how long the delay lasts by altering the sensorValue. Dividing it or multiplying it by numbers can increase or decrease the delay time.
Program Modifications:
The program its identical to the one from:
Program:
int sensorPin = 0; // Analog Pin 0 will take in the data from the Potentiometer
int ledPin = 13; // LED is controlled by Pin 13
int sensorValue = 0; // Stores the info given to Pin 0
void setup
{
pinMode( ledPin, OUTPUT); //Pin 13 is set to only Output
}
void loop()
{
sensorValue = analogRead(sensorPin); //Become the value given by the Potentiometer
digitalWrite(ledPin, HIGH); //Turns the LED on
delay(sensorValue); //Waits for however long the user wants
digitalWrite(ledPin, LOW); //Turns the LED off
delay(sensorValue); //Waits again for however long the user wants
}
No comments:
Post a Comment