Here is an Arduino based social distancing alarm cap meant for Covid-19 pandemic or similar disease outbreak. Maintaining the right gap for social or physical distancing is not always feasible. When we are outside, we forget to maintain the distance as soon as we get involved in our daily work.
This novel circuit alerts you if you come too close to someone either from the front, back, right, or left direction. A cap fitted with four ultrasonic distance sensors connected to Arduino Uno senses the minimum safe distance and alerts you through a buzzer. The author’s prototype is shown in Fig. 1.
Circuit and working
The circuit diagram of the social distancing alarm cap is shown in Fig. 2. It is built around Arduino Uno, four HC-SR04 ultrasonic sensors, and a few other components.
HC-SR04 ultrasonic sensor utilises sonar to determine distance from an object (or humans as in this case). It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. Its range is from 2cm to 400cm with an accuracy of 5mm. The module consists of an ultrasonic transmitter, receiver, and control circuit. HC-SR04 ultrasonic sensor is shown in Fig. 3. It has the following four pins, namely:
- VCC: +5V DC
- Trig: Trigger (input)
- Echo: Output
- GND: Ground
It can be easily interfaced with Arduino Uno.
The working of HC-SR04 is simple. When the sensor is triggered (a short 10µs pulse to the trigger input pin 2 from Arduino Uno board), the transmitter sends a high-frequency sound signal at 40kHz. The transmitted signal reflects back from the nearby object and is picked up by the receiver.
The output of HC-SR04 (echo-pin 3) is a pulse where the width of the pulse is proportional to the distance of the object. The width of the pulse can be calculated by the pulseIn( ) function in the code. Arduino program calculates the distance of the objects in all its four directions.
Here, four ultrasonic sensors are placed in four directions and connected to Arduino Uno. Each sensor collects the distance of the object in all four directions and compares it with the distance safety value defined in the program. When the user comes too close to another person in any of the directions, an alarm sound is produced.
Pin connections of Arduino with components are shown in the Table.
The circuit operation is performed through the software program loaded into the internal memory of Arduino Uno. The program is simple and easy to understand. Comments are given at the end of each command line.
The code starts with defining the pin numbers. Trigger and echo pins are needed for each sensor. So, a total of eight pins are needed to connect to the Arduino board. The buzzer is used, so you need to define the buzzer pin in the code. Here, two variables are needed for each sensor: the duration received from the sensor and the distance to be calculated from the pulse duration.
Set the input and output pins of the four sensors and the buzzer. Also set the serial communication for monitoring the working of the four HC-SR04 sensors. Now in the loop, start initialising the trigger pin of the sensor to the high state for ten microseconds, and then using PulseIn( ) function read the output from the sensor and calculate the distance in centimetres. The initialisation is similar for all four HC-SR04 sensors.
There are four variables: distance1, distance2, distance3, and distance4 to mark the distance from all four directions. Perform logical ‘or’ operation. Next, use an ‘if’ statement to compare with the safe distance and turn on the buzzer if the distance crosses the threshold limit.
Construction and testing
Before assembling the circuit, make sure the source code (social_distancing.ino) is uploaded to the Arduino board using Arduino IDE.
As shown in the prototype (Fig. 1), all the four HC-SR04 sensors along with Arduino are placed on the cap in all four directions. To power the circuit, a 9V PP3 battery is connected to the Arduino through its DC jack.
For testing purposes, a safe distance of 30cm is used in the program. It can be changed as per the norms. The serial monitor utility in Arduino IDE can be used to check the distance from all four sensors. You can remove the cable after verifying the working of each sensor on the serial monitor.
In order to reduce the bulkiness of the circuit, you can use smaller ultrasonic sensor modules and replace the Arduino Uno with an Arduino Nano board.
K. Murali Krishna is currently working as a junior engineer (telecom), BSNL, Rajahmundry, Andhra Pradesh. He is an electronics enthusiast, circuit designer and technical articles writer