Social Distancing Device Using Ultrasonic sensor And Arduino
Introduction
In the wake of the COVID-19 pandemic, maintaining social distancing has become crucial to prevent the spread of the virus. To aid in this effort, innovative technologies are being developed, such as social distancing devices that use ultrasonic sensors, buzzers, and Arduino Nano microcontrollers. This article explores how these components work together to create an effective social distancing device.
Components Needed
- Arduino Nano
- Ultrasonic Sensor
- Buzzer
- LED
- Zero PCB
- Power Supply
Arduino Nano
- The Arduino Nano is powered by the ATmega328P microcontroller chip, which is the same microcontroller used in the Arduino Uno board. The ATmega328P operates at a clock speed of 16 MHz and has 32KB of flash memory, 2KB of SRAM, and 1KB of EEPROM.
- The Nano is significantly smaller compared to other Arduino boards, measuring approximately 45mm x 18mm. It is designed in a compact DIP (Dual Inline Package) format, making it suitable for projects with space constraints or when a smaller form factor is required.
- The Arduino Nano provides a total of 14 digital I/O pins, of which 6 can be used for PWM (Pulse Width Modulation) output. It also offers 8 analog input pins, each of which can provide a 10-bit resolution. These pins allow you to interface with various sensors, actuators, and other electronic components.
Ultrasonic Sensor
- The HC-SR04 is an ultrasonic sensor module commonly used in electronics projects to measure distance. It utilizes ultrasound waves to determine the distance between the sensor and an object in its vicinity. The sensor module consists of two primary components: a transmitter and a receiver.
- The transmitter emits high-frequency sound waves (ultrasound) that are inaudible to the human ear. These sound waves travel through the air and bounce off objects in their path. The receiver, positioned alongside the transmitter, picks up the reflected sound waves.
To measure distance, the HC-SR04 utilizes the time it takes for the sound waves to travel from the transmitter, hit an object, and return to the receiver. The module has four pins: VCC (power supply), Trig (trigger), Echo (echo signal), and GND (ground).
Buzzer
A buzzer is an electronic component that produces sound when an electric current passes through it. It consists of a coil and a diaphragm. When the electric current flows through the coil, it creates a magnetic field that pulls the diaphragm, causing it to vibrate and produce sound. Buzzers are commonly used in alarm systems and electronic devices to provide audible feedback.
LED
LED stands for Light-Emitting Diode. It is a semiconductor device that emits light when an electric current passes through it. LEDs have become extremely popular in recent years due to their energy efficiency, long lifespan, and versatility in various applications.
Zero PCB
Zero PCB refers to a type of printed circuit board (PCB) that is designed with a thickness of 0.0mm. It is also known as a “flexible PCB” because it is extremely thin and flexible compared to traditional rigid PCBs.
Algorithm
- Detection: The ultrasonic sensor continuously measures the distance between the device and nearby objects or individuals, providing real-time distance data.
- Distance Comparison: The Arduino Nano receives the distance data from the ultrasonic sensor and compares it to a predefined safe distance threshold. If the measured distance falls below this threshold, the Arduino Nano recognizes a breach in social distancing.
- Alert Activation: Upon detecting a breach, the Arduino Nano triggers the buzzer to emit an audible warning. The buzzer’s sound serves as an immediate alert to both the user of the device and the individual who breached the safe distance.
- Monitoring and Logging: Social distancing devices can be programmed to monitor instances of non-compliance, allowing for data logging and analysis. This data can provide insights into compliance patterns, identify high-risk areas, and contribute to the overall enforcement of social distancing guidelines.
Circuit Diagram
Ultrasonic Sensor Connections
-
- Connect the Trigger pin of the ultrasonic sensor to any digital pin of the Arduino Nano (10). This pin sends a signal to trigger the ultrasonic sensor to start measuring.
- Connect the Echo pin of the ultrasonic sensor to another digital pin of the Arduino Nano (9). This pin receives the signal indicating the time it takes for the ultrasonic waves to bounce back.
Buzzer Connection
-
- Connect one terminal of the buzzer to a digital pin of the Arduino Nano (11). This pin controls the buzzer’s activation.
- Connect the other terminal of the buzzer to GND.
Source 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 33 34 35 36 37 38 39 40 41 42 43 44 |
#define trigpin 10 #define echopin 9 int led_ring = 12; int buzzer = 11; float distance; void setup() { Serial.begin(9600); pinMode(trigpin, OUTPUT); pinMode(echopin, INPUT); pinMode(led_ring, OUTPUT); pinMode(buzzer, OUTPUT); digitalWrite(led_ring, LOW); digitalWrite(buzzer, LOW); delay(1000); } void loop() { int duration; digitalWrite(trigpin, HIGH); delayMicroseconds(1000); digitalWrite(trigpin, LOW); duration = pulseIn(echopin, HIGH); distance = (duration / 2) / 29.1; distance = distance / 12; Serial.println("Feet:"); Serial.println(distance); if ((distance < 0)) { distance = 0; } else if ((distance >= 0) && (distance <= 3)) { digitalWrite(led_ring, HIGH); digitalWrite(buzzer, HIGH); Serial.println("Not Safe"); } else if (distance > 3) { digitalWrite(led_ring, LOW); digitalWrite(buzzer, LOW); Serial.println("Safe"); } } |
Project Working Demo
- Detecting Nearby Objects: The ultrasonic sensor is positioned in a way that it can detect objects or people in close proximity. It continuously measures the distance between the device and the nearest object.
- Determining Social Distancing Compliance: The Arduino Nano receives the distance data from the ultrasonic sensor and compares it to a predefined threshold value, which represents the desired safe distance for social distancing. If the measured distance falls below this threshold, it indicates that social distancing is not being maintained.
- Activating the Buzzer: When the Arduino Nano determines that social distancing is not being followed, it triggers the buzzer to emit a sound. The sound serves as an audible warning to both the person carrying the device and the individual who breached the safe distance.
- Real-time Monitoring: The social distancing device can be programmed to monitor and record instances of non-compliance. This data can be logged for further analysis and used to identify patterns or areas where social distancing is frequently violated.
Video Tutorial
Conclusion
The use of ultrasonic sensors, buzzers, and Arduino Nano microcontrollers in social distancing devices offers a practical solution to promote and maintain safe distances during the COVID-19 pandemic. By combining distance detection, threshold comparison, and audible warnings, these devices serve as reminders to individuals to follow social distancing guidelines. As we continue to navigate public health challenges, such technological innovations contribute to a safer and healthier environment for all.
More Projects