light switch using arduino and LDR

You can make a simple DC light switch without using light sensor module, just with LDR and 10K ohm resistor.
The sensitivity can change by two ways
1-changing the 10k resistor
OR
2-changing "sensor reading" in program code.
light switch using arduino and LDR

Code:

int sensorReading;//analog pin reading
void setup()
{
  Serial.begin(9600);
  pinMode(10,OUTPUT);
}
void loop()
{
  sensorReading=analogRead(0);  //get analog reading
  if (sensorReading<200)
  {
    digitalWrite(10,HIGH);
  }
  else digitalWrite(10,LOW);
  Serial.println(sensorReading);
  delay(1000);
}

Komentar

Postingan populer dari blog ini

Using ultrasonic sensor without arduino

Electronic load using Op-Amp IC 358

Arduino 220V AC Power meter using PZEM004T