Wednesday, October 19, 2011

Circuit-08 - Potentiometers

Purpose: To change the LED frequency by turning the potentiometer accordingly

Equipment:
  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC- 08 Breadboard Sheet x 1
  • Potentiometer (10k Ohm) x 1
  • 330 Ohm Resistor x 1
  • LED x 1
  • Wire x 6

References:
Program Details:
In this circuit, we will be twisting a potentiometer to make an LED blink at different time intervals. The only new hardware introduced in this circuit is the potentiometer. What a potentiometer does is it reads some value between 0 and the amount of volts it is connected to, (in this case 5), and generates a value between those volts depending on the angle that the potentiometer is at.

In the program, we will be using the value generated by the potentiometer to cause a delay in the blinking time of the LED. This is done by the line sensorValue = analogRead(sensorPin). The analogRead method reads the position at which the potentiometer is at and then stores it into sensorValue. As we turn the potentiometer farther and farther away from 0 degrees, the delay between the LED going on and off  will increase. And as we turn the potentiometer closer to 0 degrees, the delay between the LED going on and off will decrease. This is shown by the last four lines of code in the program.

Both the program and the circuit are quite easy to understand and create.    


Time to Complete: 5 mins to assemble 
                                10 mins to program

Results: The circuit and program both ran perfectly the first time. As we twisted the potentiometer, the frequency at which the LED was blinking either increased or decreased depending on the way and angle we turn the potentiometer to.

Picture:


Video:





Tips:

  • Since this circuit is easy, use the schematic to create the circuit rather than using the breadboard. Later, double check if you did it right. This will help you understand schematics.

Further Work: I will try to control multiple LEDs by using only one potentiometer. If that is successful, then I will try to control a servo using the potentiometer. 

Program Modifications: This program is the exact same as in the link below.


Program:

int sensorPin = 0;       // sets input pin for the potentiometer
int ledPin = 13;          // sets input pin for the LED to pin13
int sensorValue = 0;  // stores values from the potentiometer

void setup()
{
  pinMode(ledPin, OUTPUT);  // intializes ledPin as an output
}

void loop() 
{
  sensorValue = analogRead(sensorPin);  // Values of sensorPin is read and stored into sensorValue 
  digitalWrite(ledPin, HIGH);                   // Turns on LED
  delay(sensorValue);                              // Delays LED for sensorValue milliseconds       
  digitalWrite(ledPin, LOW);                   // Turns off LED
  delay(sensorValue);                              // Delays LED for sensorValue milliseconds
}// end loop

No comments:

Post a Comment