- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Interface proximity sensor with Arduino
There are various types of proximity sensors available. Ultrasound sensor, which we discussed in another article for measuring distance, can also be used as a proximity sensor. In this article however, we will consider IR proximity sensor.
A typical IR proximity sensor looks like the one below −
There is an IR Emitter LED and an IR Receiver (photodiode). As you can see, the sensor has 3 pins (VCC, GND and OUT). The OUT pin gives a LOW signal when the there is an obstacle which acts as a reflecting surface, and the light from the LED is reflected back to the received.
Using the property of the OUT pin (LOW when obstacle is detected), we can program our Arduino to determine if an object is nearby.
Circuit Diagram
The Circuit Diagram is shown below −
As you can see, the Vcc pin is connected to 5V on Arduino, GND to GND, and OUT to pin 7.
Example Code
The code is quite straightforward, as you can see below −
int signalPin = 7; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(signalPin,INPUT); } void loop() { // put your main code here, to run repeatedly: if (digitalRead(signalPin) == HIGH) { Serial.println("Obstacle present right now!"); } else { Serial.println("No obstacle!"); } delay(1000); }
Try placing your hand in front of the IR sensor, and then removing it. And observe the changes in print statement on the Serial monitor.
- Related Articles
- Interface touch sensor with Arduino
- Interface Arduino with Gas Sensor
- How to check android mobile supports PROXIMITY sensor?
- Interfacing an ultrasonic sensor with Arduino
- Interface Zigbee with Arduino
- Interface Arduino with LoRa module
- Getting data from Vibration sensor using Arduino
- Getting data from temperature and humidity sensor using Arduino
- How to interface Arduino with a GSM Module and read SMS?
- How to interface Arduino with a GSM Module and ping to a website?
- How to interface Arduino with a GSM module and delete all the read SMSes?
- RTOS Introduction with Arduino
- CAN Bus with Arduino
- WiFi with Arduino – Scan Networks
- Interfacing a speaker with Arduino
