When an opaque material will come closer to the sensor, the buzzer will make sound LED will light up. Here is a Complete Guide to Setup Arduino Regular IR Obstacle Sensor Buzzer With LED With Schematic, Code, Illustration and Video. Upon searching the web, I I found that there is no proper complete guide of this basic thing. In this guide, we will use Regular IR Obstacle Sensor, which cheap; not Sharp IR Sensor. You’ll see that our diagram shown is of Sharp IR Sensor, but actually connection is same and for Regular IR Obstacle Sensor. Itself this guide has little prouction usage. We can only use transistor, resistors, Regular IR Obstacle Sensor, Buzzer without Arduino like programmable microcontrollor do the job at more cheap rate. This guide’s value is in usage of Regular IR Obstacle Sensor as a conditional switch. Here, we are lighting the LED without program. But we can do the reverse – when something will come closer, the LED will be off. This video probably give idea what exactly we will do :
Arduino IR Obstacle Sensor Buzzer With LED : Circuit Diagram and Code
You need following parts for this project :
- Arduino UNO or any such board
- A NPN transistor like BC 548 or 547
- One 1 K Ohm resistor
- One 470 Ohm resistor
- Two LEDs or one LED, one diode
- Regular IR Obstacle Sensor
- Breadboard
- Jumpers
- Craziness
This is kind of infographics with circuit diagram and photo :
---
Here is the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | int analogInPin = A5; int out =13; int sensorValue = 0; // value read from the serial void setup() { Serial.begin(9600); pinMode(out, OUTPUT); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); Serial.print("sensor = " ); Serial.println(sensorValue); delay(200); if(sensorValue>700) { digitalWrite(out,1); delay(100); } else { digitalWrite(out,0); } } |
If you open serial monitor of Arduino IDE, you’ll get values when something is present closer to it or not present. You’ll notice that I have written if(sensorValue>700)
, that 700
is near maximum value I read on serial monitor. It may be different for you and you need to adjust the value. Also you may adjust delay(100)
value for desired effect.