Programming Examples

Arduino program representing smart street light concept


LDR Sensor

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

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz