17 oct 2015

Arduino smart light response system - Basic concepts



Easy and impressive as usual, Arduino boards allow any ignorant such as me myself and I to develop a unique and relatively cheap controller capable of reading the light state surrounding a given sensor and translate it to some command, hereby light a brand new second hand led -that is on or off according to environmental needs-. Simple, fast and closed circuit. Adding a relay is just a matter of time isn't it?


Want to see it in action?. Check out this video of the gadget at work:


Here is the code that runs it. No more, no less:

//     ____                 //
//    /    /___             //
//   /    /    /___         //
//  /____/    /    /____    //
//  |   /____/    /    /|   //
//  |___|   /____/    / |   //
//      |___|   /____/  /   //
//          |___|    | /    //
//              |____|/     //


// ArduLightResponseSystem
// Led on only when the light is out.


int photoRPin = 0; 
int lightLevel;
int LEDpin = 13;


void setup() 
{
 Serial.begin(9600);
}

void loop()
{
 lightLevel=analogRead(photoRPin);

 Serial.println(lightLevel);{       
   
 if(lightLevel > 526)
 {
   digitalWrite(13, HIGH);

 }
 else if(lightLevel <= 526){
 digitalWrite(13, LOW);
 }


 delay(250);

}
}


//......................................................................
// Luis Rodriguez Alonso. October 2015. habitainer@gmail.com
// http://habican.blogspot.com.es/
// publicado bajo GNU GENERAL PUBLIC LICENSE
// https://gnu.org/licenses/gpl-3.0.en.html



Just enjoy it!


No hay comentarios:

Publicar un comentario