Lab 3 - Sensing with Potentiometers
Description
Use multiple pots to control your LEDs.
I decided to do a variation of option 1 (one pot controls brightness, one controls blinking) for this lab. My idea was to create a more tangible thermostat. One pot maps the change in temperature with changes in the LED colors. The LEDs change from blue (cold) to red (hot) via a mixture of purples. The second pot adjusts the blinking speed, which corresponds to fan speed. I also tried a new color diffuser made out of one cup coffee filters.
Components Used
- Light Emitting Diodes (LED): red and blue
- Resistors (220 ohms) x 2
- Arduino board
- potentiometers x 2
- one cup coffee filters x4
Arduino Code
/*
* one pot adjusts the brightness of the red and blue LEDs,
* the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 0; // brightness
int pot2Pin = 1; // blink rate
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // red
int led3Pin = 11; // blue
void setup() {
pinMode(led1Pin, OUTPUT); // declare the LED pins as OUTPUT
pinMode(led3Pin, 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(led1Pin, pot1Val/4); // dim red LED to value from pot1
analogWrite(led3Pin, 255 - (pot1Val/4)); // dim blue LED to inverse value from pot1
delay(pot2Val); // stop the program for some time, LED is on for this time
analogWrite(led1Pin, 0); // dim LEDs to completely dark (zero)
analogWrite(led2Pin, 0);
analogWrite(led3Pin, 0);
delay(pot2Val); //stop the program for some time, LED is off for this time
}
Video
If this were actually implemented, I would only have the LEDs blink when the user is either adjusting the temperature or checking the current setting. Letting it blink constantly is too much like police cruiser lights. Also, since the controls in this POC are analog rather than some modern digital thermostats, the user would have less adjustment precision, an obvious disadvantage, but this is meant to be a novel display exercise rather than a viable alternative.