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.
The sensitivity can change by two ways
1-changing the 10k resistor
OR
2-changing "sensor reading" in program code.
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);
}
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);
}