How Proximity Sensor Works

In the evolving world of IoT, proximity sensors play a vital role in enabling us to create intelligent smart automation routines saving power and deliberate effort, overall increasing the efficiency of the entire system. 


But what exactly are proximity sensors?


In this blog post, we are going to discuss what proximity sensors are, how they work, the different types of proximity sensors available and their potential applications in different scenarios


What are Proximity Sensors?

The proximity sensor is a non-contact sensor that can detect an object/person (target) when the target enters the sensor’s field of range. Depending on the sensor used, the working principle of the proximity sensor can be based on infrared, ultrasonic, light, electric properties, etc.

There are many types of proximity sensors and each identifies a target in distinctive ways. 

What is Proximity Sensors

These sensors are extremely useful in applications where an object or target is to be detected in a certain space - to create alerts, or execute a chain of other automations like turning on the lights and fans when a person enters the room. 

Features of Proximity Sensors

Proximity sensors are relatively very simple sensors to operate. They will usually come with an onboard potentiometer to adjust the sensitivity of the sensor based on the user preference. 

 

If the Proximity sensor detects an object or target at less than the set threshold distance, the sensor will output a logic HIGH signal, indicating the presence of the object. If the object or target is away from the sensor greater than the threshold distance, the sensor output a logic LOW, indicating the presence of no object.

How does a Proximity Sensor Work?

Proximity sensors come in different varieties and forms, each more suitable than the rest in certain scenarios. Below are the list of commonly found proximity sensors one could use and their working principles.

Inductive Proximity Sensors Working

An inductive proximity sensor is used to detect metallic objects. This is because the sensor utilized the magnetic field to detect the presence of objects. When a metal object enters the field, the inductive properties between the sensor and the metal get altered thereby detecting the presence of the object. Depending on the type of metal and how inductive it can get, the sensor can either detect it from a greater distance or a shorter distance.


Inductive Proximity sensors are useful in situations where the object it is designed to detect is a known metallic object with a particular inductive properties 

Inductive Proximity Sensors

Capacitive Proximity Sensors Working

Capacitive Proximity sensors measure distance based on the changing capacitance between the sensor and the target. Therefore, the object it detects will not be limited to metallic targets and will work on any target capable of carrying an electrical charge. 

 

Capacitive type sensors are primarily used for liquid detection

Capacitive Proximity Sensors

IR-based Proximity Sensors Working

IR-based proximity sensors work by applying a voltage to an IR LED, which emits infrared light. The light then hits the target, bounced back and the photodiode will detect the intensity of the reflected light. Based on the threshold settings of the sensor, the proximity sensor can determine if a target is close to the sensor and accordingly give a signal.


IR-type proximity sensors are relatively inexpensive and are suitable for hobby-grade projects requiring simple target detection capability

IR-based Proximity Sensors

Ultrasonic Proximity Sensors Working

Ultrasonic proximity sensors work by emitting sound frequencies greater than the audible limit of human hearing. They are mainly used for measuring distance but can also be easily used as a proximity sensor. The basic principle of the ultrasonic IR proximity sensor is similar to that of IR. The ultrasonic proximity sensor emits an ultrasonic pulse and receives a pulse back. Based on the time difference between sending the pulse and receiving the pulse, the ultrasonic sensor can determine the distance between the sensor and the target object. Based on the set condition, the ultrasonic sensor can output logic high or low.


Because ultrasonic sensors are based on sound and not electricity or electromagnetic waves, they can be used in situations where the former types of sensors would have trouble, like reflective surfaces, clear plastics, etc.

Ultrasonic Proximity Sensors

How to connect a proximity sensor?

Due to its relatively simple design and operation, connecting a proximity sensor is extremely simple and easy to use. Moreover, it should be able to work with any microcontroller or board with onboard GPIO with very few lines of code


Since the sensor is just designed to give a Logic HIGH or logic LOW signal, it will have one wire indicating the same signal. In addition, the sensor will also require power, so there will also be a VCC and GND cable. Hence typical proximity sensor modules will come with 3 wires for interfacing

  • VCC
  • GND
  • OUT

VCC will be connected to the sensor's appropriate voltage supply from the interfacing device like 3.3V, 5V, or 12V (please check the sensor datasheet). 


GND should be connected GND terminal of the interfacing device


OUT should be connected to a digital input pin of the interfacing device. The device should then read the signal and this particular port in order to determine the sensor’s output


Code

The code will vary between different platforms and different programming languages. But since proximity sensors are relatively simple devices the general pseudo code to read the sensor is as simple as reading the digital pin the OUT wire is connected to

 

For example, in Arduino, if the sensor is connected to pin 7, the following 

 

int proximityPin = 7;

int reading;


void setup() {

  

  pinMode(proximityPin, OUTPUT);

  Serial.begin(9600);

}


void loop() {

  

  reading = digitalRead(proximityPin);

  if (reading == HIGH){

    Serial.println("Object Detected");

  } else {

    Serial.println("Object not detected");

  }

  delay(100);

}

For Raspberry Pi with Python, the following code can be used, if the sensor is connected to pin 7


import RPi.GPIO as GPIO

import time


proximity_pin = 7


GPIO.setmode(GPIO.BCM)

GPIO.setup(proximity_pin, GPIO.IN)


while True:

read = GPIO.input(proximity_pin)

if read == HIGH:

print("Object detected")

else:

print("Object not detected")

time.sleep(0.1)

Conclusion

In conclusion, proximity sensors are relatively simple, inexpensive, easy-to-use sensors capable of detecting an object or target using a non-contact method. These sensors play a vital role in the future of IoT and smart automation as proximity sensors are frequently used as triggers to carry out a smart function

Components and Supplies

You May Also Like To Read:

Leave a comment

Please note, comments must be approved before they are published