Amazon Shopping Mall

Sunday, March 31, 2013

Using The Potentiometer to Blink an LED

Project 2

What is Potentiometer?
Potentiometer is a three-terminal resistor which is used to control electrical devices as well as measure the potential(voltage) of a particular electric device.

So in this project, the potentiometer is been used to regulate the amount of current or voltage that the LED can receive in order to light. In our codes, we declared the map function to a range to which the potentiometer can lie within.  

Setting Up the Potentiometer

Components 

  • 1 Arduino
  • 1 LED
  • 1 220 ohm resistor (red red brown)
  • 1 10K ohm potentiometer
  • 2 data wires
Always note that the red wire is for power , the black for ground and the white or yellow for data/signal.

 Images 



Setup for Potentiometer and  LED

The Codes to use on your Arduino IDE

Hi Everybody, this is Elizabeth Yeboah and  this is project 2. Copy and paste this code in your sketch whiles following the video tutorial for the setup.

// Using the Potentiometer codes

/*analogRead()
This is an example of analogRead(). analogRead() listens for a range of voltages (5v - 0v) on an assigned analog port.
This code outputs the data to an led and affects the LEDs brightness using analogWrite().
syntax
analogRead(analog pin); 
*/

//DECLARE YOUR VARIABLES AND PIN NAMES
//Assign a variable name to a pin number.
//Assign the variable name led0 to analog/digital pin 3
//syntax:
//datatype variableName = value;

int led0 = 3;
int variableResistor = A0;        //declare a variable called variableResistor and assign it to analog input A0.
int analogValue;                 //declare a variable called analogValue to hold the data from the variableResistor.

// SETUP ROUTINE
//The setup runs once on startup or reset.

void setup() {

//initialize the serial connection
//syntax
//Serial.begin(baud rate)

Serial.begin(9600);
}

//MAIN LOOP
//this will run forever as long as the arduino has power.
void loop() {
//Read the specified pin.
//Assign to the variable, the reading from the analog input pin.
//syntax
//variableName = digitalRead(analog pin);

analogValue = analogRead(variableResistor); 
analogValue = map(analogValue, 0, 1023, 0, 255);                //map the values from 0 - 1024 to 0-255

//assign a level to the brightness of the led.
//Use the variable analogValue for the level of brightness.
//syntax
//analogWrite(variableName, value);

analogWrite(led0, analogValue);

//Send a label for the data with no carridge return.
//syntax
//Serial.print(data);

Serial.print("analogValue = " );

//Send the data with a carridge return.
//syntax
//Serial.print(data);

 Serial.println(analogValue);
 
delay(5);                                                                     //delay for 5ms to allow the chip to maintain continuity
}

Watch a Potentiometer Video

Please if this tutorial was helpful send me your comments. Thanks
By Lis Brown

No comments:

Post a Comment

Please send me your comments