Table of Contents
Social Distancing Project, Description:
Social Distancing Project using Arduino, Ultrasonic Sensor, and LEDs- As per the World Health Organization “WHO” the safe distance is at least maintain 1 meter or 3 feet, while some people suggests that this distance should be around 6 feet.
I this tutorial, you will learn how to make a Social Distancing Project based on the Arduino Nano and HC-SR04 Ultrasonic Sensor. When the distance is less than or equal to 3 feet the LED module is automatically turned ON, and when the distance is greater than 3 feet than the LED module is turned OFF. You can increase the distance as per your requirement by simply changing the preset value.
A few months back I uploaded an article about, How to make Automatic Hand Sanitizer or Hand Wash system to stop Coronavirus Spreading. This project really got popular, and this is the reason, this time I am making this Social Distancing Project.
Recently I got this 6th-anniversary badge from the PCBWay Company. This is basically an RGB LED module and can be easily powered up using 3 to 3.3 Volts. Due to its cool design, I decided to use it in a social distancing project against the Covid-19 Corona Virus.
About the Sponsor of this project, PCBWay:
The PCB board used in this project is sponsored by the PCBWay Company. PCBWay is quite professional in the field of PCB manufacturing; you can try their services at extremely low prices, Only 5 dollars for 10 PCBs and 30 dollars in total for 20 PCBs assembly, besides this the new members also get a 5 Dollars bonus.
PCBWay is currently Celebrating 6th Anniversary offering Mid-Year Big Sale. I am really thankful to the PCBWay for continuously supporting my work by sending me such High-quality PCBs.
Without any further delay, let’s get started!!!
Amazon Purchase Links:
Other Tools and Components:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Why Social Distance Project?
Social distancing also called “physical distancing,” means keeping a safe space between yourself and other people who are not from your household. To practice social or physical distancing, stay at least 3 to 6 feet (about 2 arms’ length) from other people who are not from your household in both indoor and outdoor spaces.
You can reduce your chances of being infected or spreading COVID-19 by taking some simple precautions:
- Regularly and thoroughly clean your hands with an alcohol-based hand rub or wash them with soap and water. Why? Washing your hands with soap and water or using alcohol-based hand rub kills viruses that may be on your hands.
- Maintain at least 1 meter (3 feet) distance between yourself and others. Why? When someone coughs, sneezes, or speaks they spray small liquid droplets from their nose or mouth which may contain virus. If you are too close, you can breathe in the droplets, including the COVID-19 virus if the person has the disease.
- Avoid going to crowded places. Why? Where people come together in crowds, you are more likely to come into close contact with someone that has COVID-19 and it is more difficult to maintain a physical distance of 1 meter (3 feet).
- Avoid touching eyes, nose, and mouth. Why? Hands touch many surfaces and can pick up viruses. Once contaminated, hands can transfer the virus to your eyes, nose or mouth. From there, the virus can enter your body and infect you.
- Make sure you, and the people around you, follow good respiratory hygiene. This means covering your mouth and nose with your bent elbow or tissue when you cough or sneeze. Then dispose of the used tissue immediately and wash your hands. Why? Droplets spread virus. By following good respiratory hygiene, you protect the people around you from viruses such as cold, flu and COVID-19.
- Stay home and self-isolate even with minor symptoms such as cough, headache, mild fever, until you recover. Have someone bring you supplies. If you need to leave your house, wear a mask to avoid infecting others. Why? Avoiding contact with others will protect them from possible COVID-19 and other viruses.
- If you have a fever, cough and difficulty breathing, seek medical attention, but call by telephone in advance if possible and follow the directions of your local health authority. Why? National and local authorities will have the most up to date information on the situation in your area. Calling in advance will allow your health care provider to quickly direct you to the right health facility. This will also protect you and help prevent the spread of viruses and other infections.
- Keep up to date on the latest information from trusted sources, such as WHO or your local and national health authorities. Why? Local and national authorities are best placed to advise on what people in your area should be doing to protect themselves.
I highly recommend reading my article on “How to make the Automatic Hand sanitizer System”. The reason I am making this Social Distancing project is, it’s impossible to manually measure the distance each time you meet someone. With the help of my proposed Social distancing project, you don’t have to be worried about the distance. Whenever someone gets near to you the lights will automatically turn ON, this way you can increase your distance from the next person. This is an easy to built DIY project based on a few electronic components which you can easily found in your local electronics shops.
3V to 3.3V LED Ring Module:
This is the RGB LED module from the PCBWay Company which can be powered up using the 3v cell and can also be powered up using 3.3 Volts from the Arduino board. As I will power up this LED module using the Arduino’s 3.3V, so I will not use the 3V cell. The metal part is the + which connects with the 3V side of the cell, while the other point is on the PCB and is the ground point. I am going to desolder this metal part.
As you can see I removed the metal part, these two are the + points “3V to 3.3V” while the middle one is the ground. Next, I drilled two holes for soldering the voltage and ground wires
This way I can enter the wires from the backside. So the wires will remain hidden.
The brown wire is connected with one of the two positive points while the white wire is connected with the ground of the LED module.
HC-SR04 Ultrasonic Sensor:
This is the HC-SR04 Ultrasonic Sensor, for the easy interfacing I soldered wires with the female headers. Red wire is the VCC, Green wire is the Trigger, White wire is the Echo, and the black wire is the ground. The recommend voltage for this Ultrasonic Module is 5 Volts.
We are done with the LED module and the Ultrasonic Sensor, Now let’s have a look at the complete circuit diagram and see how this LED module and HC-SR04 Ultrasonic Sensor are connected with the Arduino Nano.
Social Distancing Project Circuit Diagram:
The Circuit Diagram of the Social Distancing Project based on the Arduino Nano and an Ultrasonic Sensor is very simple. The whole project can be powered up using different voltage sources. You can use a 9V or 12V battery. As the LM7805 Voltage Regulator accepts a wide range of input voltages from 7 to 25 Volts, so the whole project can also be powered up using a small solar panel. You can also use the 5V Lipo Battery pack.
J1 is the DC Female Power Jack and this where we connect our external power supply. The voltage and GND legs of the DC female power jack are connected with the input and ground legs of the LM7805 Voltage regulator. Two 470uF electrolytic decoupling capacitors are connected at the input and output sides of the voltage regulator. The output leg of the voltage regulator is connected with the VIN pin of the Arduino Nano and the ground of the 5V regulated power supply is connected with the GND pin of the Arduino Nano.
The LED module 3.3V supply pin is connected with the Arduino’s 3.3V. The ground pin of the LED ring module is connected with the collector of the 2n2222 NPN transistor. The emitter of the transistor is connected with the ground, while the base is connected with the Arduino’s pin number 9 through a 10K resistor. The transistor and 10k resistor together makes the driver circuit that controls the LED module.
The HC-SR04 Ultrasonic Sensor VCC and GND pins are connected with the Arduino’s 5 Volts and GND, while the Trigger and ECHO pins of the Ultrasonic Sensor are connected with the Arduino’s pins 4 and 3 respectively. So, that’s all about the circuit diagram.
Social Distancing Project PCB board:
Next, I designed a PCB for the Arduino Nano, which I will use as the Development board. I added female headers for the 3.3V, 12V, 5V, and ground. The right side area can be used as the Vero Board for soldering other electronic components. I also added female headers on the left and right sides of the Arduino Nano for connecting the jumper wires. I double-checked all the connections. And finally, generated the Gerber files and placed an online order on the PCBWay official website.
Social Distancing Project components Interfacing:
These are the PCB boards I received from the PCBWay Company. As you can see the Quality is really great. The silkscreen is quite clear and the solder mask looks amazing. Next, I started off by placing the components and completed the soldering job.
This is how the final circuit looks. Finally, I connected the Ultrasonic Sensor and the LED module with the Arduino Nano as per the circuit diagram already explained. This is how everything looks after soldering.
The 10K ohm resistor is connected with the digital pin 9 and base of the 2n2222 NPN transistor. The voltage wire from the LED module is connected with the 3.3V of the Arduino Nano. The emitter of the transistor is connected with the GND. The ground of the LED module is connected with the collector of the transistor. So, by turning ON and turning off the transistor we can turn ON and turn OFF the LED module using the Arduino’s Nano digital pin 9, my hardware is ready and now it’s time to have a look at the Arduino programming.
Social Distancing Project Arduino Programming:
* Social Distancing Project for the Covid-19 Corona Virus based on the Arduino Nano, Ultrasonic Sensor, and LED Module.
#define trigpin 4 // digital pin 4
#define echopin 3 // digital pin 3
int led_ring = 9;
duration = pulseIn(echopin,HIGH);
distance = ( duration / 2) / 29.1; // distance in inches
distance = distance / 12; // distance in feet
if( (distance < 0) )
distance = 0;
if( (distance >= 0) && (distance <= 3) )
if( distance > 3 )
Social Distancing Project Code explanation:
No, libraries are used in this project. The trigger and ECHO pins of the Ultrasonic Sensor are connected with the Arduino’s pins 4 and 3. Next, I defined a pin for controlling the LED module using the 2n2222 NPN transistor. Finally, a variable “distance” of the type float. This variable will be used for storing distance information.
Inside the void setup() function, I activated the Serial Communication using the Serial.begin() function and selected 9600 as the baud rate. This is only used for debugging purposes. I set the trigger pin as the OUTPUT, ECHO pin as the INPUT, and the LED module as the OUTPUT. Finally, I turned OFF the LED module and added a delay of 1 second.
Then stars the void loop function, which consists of the actual code. This is the same exact code that I used in my previous Ultrasonic Sensor based projects. This time I made a few changes which are, I converted inches into feet and added some conditions to check if the distance is less than 3 feet, or the distance is greater than 3 feet. So, that’s all about the programming.
After uploading the coding, I powered up the circuit. I successfully controlled the LED module depending on the distance.
In the picture above you can see there is nothing in front of the Ultrasonic Sensor so the distance is obviously greater than 3 feet and that’s why the LED module remains OFF.
But when I placed my hand in front of the Ultrasonic Sensor, the distance is less than 3 feet, the LED module was automatically turned ON. I checked this project several times and it worked perfectly without any errors.
For the practical demonstration and step by step explanation, watch the video tutorial given below.
Now, you can design a plastic enclosure and add some straps to use it as the final product. You can further reduce the circuit. If you plan to use the Lipo Battery pack then there is no need to add the DC female power jack and the LM7805 voltage regulator. Apart from the Social Distancing, you can also use this project in so many other cool projects, like for example, in accident avoiding system, etc.