Lab 3: Sensing: Potentiometers

Assignment: Sensing: Potentiometers

Collaborators:

Assignment: Sensing: Potentiometers

Heather Dolan

Assignment: Sensing: Potentiometers

Two potentiometers were added to the circuit with three LEDs from the previous lab.  One controls the brightness of the LEDs and the other the rate at which they blink.

Materials Used:

  • Breadboard
  • Two Potentiometers
  • Solder and soldering iron
  • Arduino
  • LEDs (x3)
  • 220 ohm resistors (x3)
  • Lots of wire

Arduino Code for controling three LEDs with two potentiometers simultaneoulsy.

/*
* Heather Dolan
* September 23, 2009
* Potentiometer Lab
* Modified Tutorial Code - added additional LEDs
*
* one pot dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 0;   // select the input pin for the potentiometer 1
int pot2Pin = 1;   // select the input pin for the potentiometer 2
int pot1Val = 0;   // variableasa to store the value coming from pot 1
int pot2Val = 0;   // variable to store the value coming from pot 2
int led1Pin = 9;   // select the pin for the LED 1
int led2Pin = 10;  // select the pin for the LED 2
int led3Pin = 11;  // select the pin for the LED 3
void setup() {
pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led2Pin, pot1Val/4);   // dim LED to value from pot1
analogWrite(led1Pin, pot1Val/4);
analogWrite(led3Pin, pot1Val/4);
delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
analogWrite(led2Pin, 0);         // dim LED to completely dark (zero)
analogWrite(led1Pin, 0);         // dim LED to completely dark (zero)
analogWrite(led3Pin, 0);         // dim LED to completely dark (zero)
delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
}

 

I also mapped the position of the pot to which LED was turned on based on the position on my bread board.  When the pot was turned all the way to the left the left most LED was on, when it was in the center positions, the center LED was on, and when it was all the way to the right, the right most light was on.  The other pot controlled how bright the lights were.

Arduino Code: Part 2

/*
* Heather Dolan
* September 23, 2009
* Potentiometer Lab
* Modified Tutorial Code - added additional LEDs
*
* One pot dims, and the other, based on it's position (turned left, center, right), determines
* which LED is on.  The rotation corresponds to the place on the board (assuming
* left is toward arduino and right is near the empty end of the bread board)
* The other pot changes the brighness of all three LEDs
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 0;   // select the input pin for the potentiometer 1
int pot2Pin = 1;   // select the input pin for the potentiometer 2
int pot1Val = 0;   // variableasa to store the value coming from pot 1
int pot2Val = 0;   // variable to store the value coming from pot 2
int led1Pin = 9;   // select the pin for the LED 1
int led2Pin = 10;  // select the pin for the LED 2
int led3Pin = 11;  // select the pin for the LED 3
void setup() {
pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1024, for blinking

if (pot2Val <= 250) {  //If the value of the Pot 1 is less than 250, assume
// the position is to the left and light up the left most LED
analogWrite(led3Pin, pot1Val/4);    // Light up left most LED (on my breadboard)
// use the brightess value from the other pot

} else if(pot2Val > 250 && pot2Val<=750){ //if the value from Pot 1 is between 250 and 750
//the position is somewhere in the middle, light the
//middle (on my breadboard) LED.  Use brightness other pot
analogWrite(led1Pin, pot1Val/4);
}

else if (pot2Val > 750  ) {
//if the value is between 750 and 1024 assume pot is turned to the
//right, light up the right most LED (again, on my breadboard - pins would
//need to be changed on other breadboards)

analogWrite(led2Pin, pot1Val/4);
}

delay(5);                  // modify this to blink, but I wanted the LEDS to not blink, just flicker
analogWrite(led2Pin, 0);         // dim LED to completely dark (zero)
analogWrite(led1Pin, 0);         // dim LED to completely dark (zero)
analogWrite(led3Pin, 0);         // dim LED to completely dark (zero)
delay(5);                  // modify this to blink, but I wanted the LEDS to not blink, just flicker

}