Programming Examples
Arduino program representing smart street light concept

Write a program to interface LED at PWM pin and LDR, in such a way that when the light intensity falling on LDR rises the LED glow should be reduced and after a threshold value the LED should be put off. (representing smart street light concept)
void setup()
{
pinMode(A0, OUTPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int ledBrightness = 0;
int ldrValue = 0;
ldrValue = analogRead(A0);
Serial.println(ldrValue);
if (ldrValue > 700) // Threshold
{
analogWrite(9, 0);
}
else
{
ledBrightness = map(ldrValue, 0, threshold, 255, 0);
analogWrite(9, ledBrightness);
}
delay(200);
}Output