In this tutorial, we are going to learn Interfacing Proximity Sensors with Arduino
What is Proximity Sensors:
In simple words, proximity sensors are the devices that are used to detect the presence of an object in its surroundings without any physical contact with the objects. The proximity sensors detect objects by using an electromagnetic field or electromagnetic radiation beam. The sensors detect the presence of an object when the electromagnetic radiation has reflected the sensor. The object which is detected by the proximity sensors is known as targets.
Proximity sensors are available in different sizes, shapes (Circular or rectangular). Different materials (plastic, metallic, etc) some proximity sensors are a combination of both plastic and metallic material. The proximity sensors have more reliability due to the absence of the mechanical parts and it does not have contact with the target object. The proximity sensors which are designed for very short range can be used as touch switches. The proximity sensors are most commonly used in manufacturing industries for counting, detection, positioning, etc. The proximity sensors have longer life as compared to the other sensors.
read more : Interfacing GPS Module with Arduino
Types of Proximity Sensors:
- Inductive Proximity Sensor
- Capacitive Proximity Sensor
- Optical Proximity Sensor
- Magnetic Proximity Sensor
- Ultrasonic Proximity Sensor
Working Principle of Proximity Sensors:
We will now see the working principle of an Inductive proximity sensor. The inductive proximity sensor circuit is used for detecting metal objects and the Inductive proximity sensor does not detect any objects other than metals. The above diagram shows the circuit diagram of an inductive proximity sensor. Which contains a voltage regulator, trigger circuit, an oscillator, electric coil, and magnetic field.
The electric coil produces a magnetic field when the power supply is given. As the circuit contains an oscillator, an alternating magnetic field is produced by the coils. Whenever a metal object is bought in the influence of the magnetic field, an eddy current will be produced in the metal object and circulates within the metal object. This causes an increase in load and a decrease in the amplitude of the magnetic field. When the metal target is moved closer to the metal object causes an increase in eddy current on the metal object and hence load on the oscillator increases and field amplitude decreases.
Read our blog on how proximity sensor works where we discuss what are proximity sensors, how does a proximity sensor work, the different types of proximity sensors available and their potential applications in different scenarios.
We will use an Inductive proximity sensor to detect metal objects without any physical contact with the target. To interfacing proximity sensor with arduino
we need some hardware as mentioned below.
|Inductive proximity sensor LJ12A3-4-Z/BY 3-Wire
|9V Battery Clips with Bare Leads
|Male to Male Jumper wire
read more : Arduino Sensor types and Applications
Circuit Diagram for Interfacing Proximity Sensor with Arduino:
The above figure shows the pinout of the Inductive proximity sensor LJ12A3-4-Z/BY 3-Wire.
VIN pin of the proximity sensor
Positive wire of the battery connector
GND pin of the proximity sensor
Negative pin of the battery connector and GND pin of Arduino
OUT pin of proximity sensor
Pin 2 of Arduino through a 10K resistor in series. And the OUT pin 2 of Arduino is pulled to LOW using a 10K resistor
The connection for Interfacing of Proximity Sensor with Arduino is very easy,
Connect VIN pin of the proximity sensor with Positive wire of the battery connector. GND pin of the sensor with negative pin of the battery connector & GND Pin of Arduino. OUT pin of proximity sensor with Pin 2 of Arduino through a 10K resistor in series. And the OUT pin 2 of Arduino is pulled to LOW using a 10K resistor
(Note: Te resistor in series with OUT pin of the proximity sensor is used to reduce the voltage from 9V to 4.5V. As 9V will damage the Arduino due to Overvoltage. Using a 10K resistor in series is compulsory)
Once, the connection is completed, we will see the code for interfacing proximity sensor with Arduino to detect the presence of metal objects in surroundings.
read more : Temperature Sensor Interfacing with Arduino
const int Pin=2;
int sensorValue = digitalRead(Pin);
The above code is used to detect metal object and display it on the Serial monitor.
First, we have declared a constant integer datatype variable called Pin and assigned number 2 to it. This means we are assigning pin number 2 of the Arduino to read the sensor values.
const int Pin=2;
Next, we are using void setup() function. This function executes only one time in the entire program. In the void setup() function, we are declaring the Pin as INPUT by using a pinMode function and telling Arduino to establish serial communication with 9600 baud rate.
Next we have a void loop() function. This function is executed continuously. In the void loop() function, we have created an integer variable called sensorValue. In this variable, we are storing the data read by the Arduino from the sensor. We are storing the data from the digitalWrite function which reads the data from the sensor. It will be either HIGH or LOW.
Next, we are using an if-else statement. This if-else statement verifies whether the output is HIGH(1) or LOW(0). If the output of the sensor is HIGH then “no Object” will be printed on the serial monitor. Or if the output of the sensor is HIGH then “Object detected” will be printed on the serial monitor. And we have given a delay() function which reads the data every half-second from the sensor.
read more : Top 10 Robotic Projects for Beginners
proximity sensors have become an essential component in various industries for their ability to detect the presence or absence of objects without physical contact. From inductive sensors to capacitive sensors and ultrasonic sensors, the different types of proximity sensors provide a range of detection capabilities to meet diverse needs. By understanding the working principles of proximity sensors and how to interface them with Arduino, you can leverage their power and accuracy for your next project. So, Don't wait any longer, start exploring the world of proximity sensors today and unlock endless possibilities!
If you understand how to interfacing proximity sensor with arduino and appreciate our work don't forget to share this post and leave your opinion in the comment box.
Please do check out other blog posts about Arduino Interfacing ACS712 with Arduino , Arduino Interfacing with Ultrasonic Sensor , LED Interfacing with Arduino , Interfacing GSM Module with Arduino , Interfacing MAX30100 Pulse Oximeter with Arduino , IR Sensor Interfacing with Arduino , How to connect ZMPT101B to Arduino and How to use Buzzer with Arduino.
Make sure you check out our wide range of products and collections (we offer some exciting deals!)