Monday 28 April 2008

Week 2 - Analogue Input Potentiometer


In week 2 we were instructed to create a circuit once again using a LED but this time with a Potentiometer. A potentiometer is a variable resistor which allows you to control the amount of current or voltage going through a particular circuit. The objective of this circuit was to control the speed of the blink the LED depending on the position of the potentiometer. 
Here are images and a video of my completed circuit:

The code used was taken from the arduino official website:
int potPin = 2;    // select the input pin for the potentiometer 
int ledPin = 13;   // select the pin for the LED 
int val = 0;       // variable to store the value coming from the sensor  

void setup() {  
 pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT 
 }  

 void loop() {   
 val = analogRead(potPin);    // read the value from the sensor   
 digitalWrite(ledPin, HIGH);  // turn the ledPin on   
 delay(val);                  // stop the program for some time   
 digitalWrite(ledPin, LOW);   // turn the ledPin off   
 delay(val);                  // stop the program for some time 
 }

No comments: