Surilli
Published © LGPL

Traffic Light Switching Through LDR Using Surilli Basic M0

Reading an analog sensor (LDR) to switch an LED on and off. Working of street lights.

BeginnerFull instructions provided15 minutes974
Traffic Light Switching Through LDR Using Surilli Basic M0

Things used in this project

Hardware components

Surilli Basic
Surilli Basic
×1
Photo resistor
Photo resistor
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Traffic Light Switching Through LDR Using Surilli Basic

Code

LDR

C/C++
int sensorPin =A0 ; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0;// variable to store the value coming from the sensor
int Intensity = 200; // Light intensity at which you want to do LED switching (0-1023)
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() 
{ 
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
//Serial.println(sensorValue);
if(sensorValue>Intensity)
{
digitalWrite(ledPin, LOW);
}
else if(sensorValue<Intensity)
{
digitalWrite(ledPin, HIGH);
}
}

Credits

Surilli
196 projects • 65 followers
Surilli is a premiere Internet of Things centric Technology Company aimed at providing cutting edge innovative solutions.

Comments