Lab 3: Alarm Lamp

Submitted by shaohan on Tue, 02/19/2013 - 21:16

Components Used:

  • 3 LED lights (red, blue, green)
  • 2 potentiometers
  • 1 Arduino board
  • 1 Breadboard with many cables
  • 1 Plastic Bottle
  • Some cottons and wrapping papers

 

Description:

I used two potentiometers to control the blinking rate and brightness of the LEDs. When the brightness pot value is set between 1~350, the blue and green LEDs turn on and are applied to the pot value. When the brightness pot value is set between 351~700, the green and red LEDs turn on and applied to the pot value (brighter). When the brightness pot value is set between 701~950, the blue and red LEDs turn on and applied to the pot value (much brighter). Finally, when the brightness pot value is set between 951~1024, only red LED will be on. Combined with the blinking controller, this lamp can act like an alarm lamp that the status can be switched from blue (safe) --> blue/green (low-level alarm) --> purple (middle-level alarm) --> red (high-level alarm). 

 

Codes:

 

/*
 * one pot dims, the other pot changes the blinking rate
 * modification of the following
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 
 Modified by Shaohan Chen 2013.02.19
 
 */
 
int pot1Pin = 0;   // select the input pin for the potentiometer 1: brightness
int pot2Pin = 1;   // select the input pin for the potentiometer 2: blinking
 
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 ledBluePin = 9;   // select the pin for the Blue LED
int ledGreenPin = 10;  // select the pin for the Green LED
int ledRedPin = 11;  // select the pin for the Red LED
 
void setup() {
   pinMode(ledBluePin, OUTPUT);  // declare the ledBluePin as an OUTPUT
   pinMode(ledGreenPin, OUTPUT);  // declare the ledGreenPin as an OUTPUT
   pinMode(ledRedPin, OUTPUT);  // declare the ledRedPin 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 (pot1Val >= 00 && pot1Val <= 350) {
     analogWrite(ledBluePin, pot1Val/4);   //dim LED Blue to value from pot1
     analogWrite(ledRedPin, 0);            //turn off the LED Red
     analogWrite(ledGreenPin, pot1Val/4);      //dim LED Green to value from pot1
     delay(pot2Val);                       //stop the program from some time, meaning, LED is on except Green LED
     
     analogWrite(ledRedPin, 0);         // dim LED Red to completely dark (zero) 
     analogWrite(ledBluePin, 0);      // dim LED Red to completely dark (zero) 
     analogWrite(ledGreenPin,0);     // dim LED Green to completely dark (zero)
     delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
   }
   
  else if (pot1Val > 350 && pot1Val <= 700) {
  
     analogWrite(ledBluePin, 0);           //turn off the LED Blue
     analogWrite(ledRedPin, pot1Val/4);      //dim LED Red to value from pot1
     analogWrite(ledGreenPin, pot1Val/4);      //dim LED Green to value from pot1
     delay(pot2Val);                       //stop the program from some time, meaning, LED is on except Green LED
         
     analogWrite(ledRedPin, 0);        // dim LED Red to completely dark (zero) 
     analogWrite(ledBluePin, 0);      // dim LED Blue to completely dark (zero) 
     analogWrite(ledGreenPin,0);     // dim LED Green to completely dark (zero)
     delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
   }
 
else if (pot1Val > 700 && pot1Val < 950) {
     analogWrite(ledBluePin, pot1Val/4);   //dim LED Blue to value from pot1
     analogWrite(ledRedPin, pot1Val/4);     //dim LED Red to value from pot1
     analogWrite(ledGreenPin, 0);             //turn off the LED Green
     delay(pot2Val);                       //stop the program from some time, meaning, LED is on except Green LED
  
     analogWrite(ledRedPin, 0);         // dim LED Red to completely dark (zero) 
     analogWrite(ledBluePin, 0);      // dim LED Blue to completely dark (zero) 
     analogWrite(ledGreenPin,0);     // dim LED Green to completely dark (zero)
     delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
   }
 
else if (pot1Val >= 950 && pot1Val <= 1024) {
     analogWrite(ledBluePin, 0);              //turn off the LED Blue
     analogWrite(ledRedPin, pot1Val/4);      //dim LED Red to value from pot1
     analogWrite(ledGreenPin, 0);            //turn off the LED Green 
     delay(pot2Val);                       //stop the program from some time, meaning, LED is on except Green LED
     
     analogWrite(ledRedPin, 0);         // dim LED Red to completely dark (zero) 
     analogWrite(ledBluePin, 0);      // dim LED Blue to completely dark (zero) 
     analogWrite(ledGreenPin,0);     // dim LED Green to completely dark (zero)
     delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
   }
 
}
 
 

 

0
Your rating: None
Drupal theme by Kiwi Themes.