In this tutorial, we will integrate IR sensors with Surilli WiFi to control the operation of the street lights. These sensors will sense the position of the vehicle and give its signal to Arduino and as a result, it will turn ON the LEDs. If this idea is implemented in any city, it will be helpful in saving enough electricity and money.
What Is an IR Sensor?This IR proximity sensor is a multipurpose infrared sensor which can be used for obstacle sensing, color detection, fire detection, line sensing, etc and also as an encoder sensor. The sensor provides a digital output. In this case, the sensor outputs a logic one (+5V) at the digital output when it detects black line in front of the sensor and a logic zero (0V), when there is white line in front of the sensor. An onboard LED is used to indicate the presence of black and white. This digital output is directly connected to Surilli WiFi.
Components Required- Surilli WiFi
- Connecting wires
- 4 LEDs
- 4 IR sensors
Connections Between Surilli WiFi, IR Sensors, and LEDs:
IR1 (PIN D0) ---> SURILLI WiFi(PIN 4)
IR1(PIN GND) ---> SURILLI WiFi(PIN GND)
IR1(PIN VCC) ---> SURILLI WiFi(PIN USB)
IR2(PIN DO) ---> SURILLI WiFi(PIN 5)
IR2(PIN GND) ---> SURILLI WiFi(PIN GND)
IR2(PIN VCC) ---> SURILLI WiFi(PIN USB)
IR3(PIN DO) ---> SURILLI WiFi(PIN 16)
IR3(PIN GND) ---> SURILLI WiFi(PIN GND)
IR3(PIN VCC) ---> SURILLI WiFi(PIN USB)
IR4(PIN DO) ---> SURILLI WiFi(PIN 13)
IR4(PIN GND) ---> SURILLI WiFi(PIN GND)
IR4(PIN VCC) ---> SURILLI WiFi(PIN USB)
LED 1 (+ PIN) ---> SURILLI WiFi(PIN 0)
LED 1 (- PIN) ---> SURILLI WiFi(PIN GND)
LED 2 (+ PIN) ---> SURILLI WiFi(PIN 2)
LED 2 (- PIN) ---> SURILLI WiFi(PIN GND)
LED 3 (+ PIN) ---> SURILLI WiFi(PIN 12)
LED 3 (- PIN) ---> SURILLI WiFi(PIN GND)
LED 4 (+ PIN) ---> SURILLI WiFi(PIN 14)
LED 4 (- PIN) ---> SURILLI WiFi(PIN GND)
STEP 1: Set Up Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 2: The CircuitryThe circuitry is very simple. Follow the figure below to set up your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.After it is uploaded, the IR sensor will start working and the LEDs will turn OFF when any vehicle passes through that IR sensor.
Arduino Code:
int ir1=4;
int ir2=5;
int ir3=16;
int ir4=13;
int led1=0;
int led2=2;
int led3=12;
int led4=14;
int proxy1=0;
int proxy2=0;
int proxy3=0;
int proxy4=0;
void setup()
{
pinMode(ir1,INPUT);
pinMode(ir2,INPUT);
pinMode(ir3,INPUT);
pinMode(ir4,INPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
}
void loop(){
proxy1=digitalRead(ir1);
proxy2=digitalRead(ir2);
proxy3=digitalRead(ir3);
proxy4=digitalRead(ir4);
if(proxy1==HIGH)
{
digitalWrite(0,LOW);
}
else
{
digitalWrite(0,HIGH);
}
if(proxy2==HIGH)
{
digitalWrite(2,LOW);
}
else
{
digitalWrite(2,HIGH);
}
if(proxy3==HIGH)
{
digitalWrite(12,LOW);
}
else
{
digitalWrite(12,HIGH);
}
if(proxy4==HIGH)
{
digitalWrite(14,LOW);
}
else
{
digitalWrite(14,HIGH);
}
}
Play with the program to see how it reacts to different values and logic. This will develop your understanding about IR sensor so you can use them in your practical application.
If you make something fun and interesting do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with Surilli family for more amazing stuff. :-)
Comments
Please log in or sign up to comment.