Saturday, May 17, 2014

using a light sensor to control LED light

Tried going to SIM LIM square to buy an audino to start fidgeting with it. Informed by the people there that it was a  fruitless trip.

spend time going through the source code for using a light sensor to determine the amount of light in the background and based on the analog reading to determine the amount of light the LED light should emit.

 int pin = 0 ;
int LEDpin = 9;

void setup()//working source code
{
 
  Serial.begin(9600);
  pinMode(LEDpin, OUTPUT);
}

void loop()
{
  int val = analogRead(pin);
  val = constrain(val, 750,950);
  int ledlevel = map(val,750,950,255,0);
  analogWrite(LEDpin,ledlevel) ;
 
}

No comments:

Post a Comment