Covid Distancing Device: Ultrasonic Sensor HC - SR04

by csd28 in Circuits > Arduino

247 Views, 0 Favorites, 0 Comments

Covid Distancing Device: Ultrasonic Sensor HC - SR04

Screen Shot 2021-04-12 at 10.38.38 PM.png

The HC - SR04 is an ultrasonic ranging module that can detect distance up to 13 feet, with the accuracy of 3mm.

This module provides a guide on how to utilize the HC - SR04 sensor and LED lights to create a covid-safety distancing device, which will alert the vicinity of an object to the sensor.

Materials Needed

Screen Shot 2021-04-12 at 9.56.12 PM.png

- Arduino UNO

- Jumper Wires

- Ultrasonic Sensor - HC SR04

- LED (1 red, 2 yellow or orange, 4 green)

- Breadboard

Overview

Untitled Sketch_bb.jpg

The photo above shows the setup of the project. Connect the jumper wires as follows:

Connect a jumper wire from the GND pin of the Arduino to the NEGATIVE channel of the breadboard. Connect another jumper from the 5v pin of the Arduino to the POSITIVE channel of the breadboard.

(On Ultrasonic Sensor)

Connect Echo -> pin 13
Connect Trig -> pin 12

(In Order from left to right)

LED1 -> A0
LED2 -> A1
LED3 -> A2
LED4 -> A3
LED5 -> A4
LED6 -> A5
LED7 -> 2

Sensor and LEDs

Screen Shot 2021-04-12 at 9.56.58 PM.png

First off, we will assemble the HC - S404 Ultrasonic Sensor and LED’s onto the breadboard.

Place the sensor on the far right of your breadboard. By placing it on the far right, you can avoid cluster when we connect the LED lights.

Next, assemble the LED lights accordingly, starting from the first hole on the far left. The color order will begin with 4 green, 2 yellow, and end with 1 red.
- Make sure NEGATIVE leg (shorter) will be fixed into the GND rail of the breadboard.
- The POSITIVE leg will fixed into the circuit area.
- Skip 3 holes before fixing another LED light into the breadboard.

Sensor Wires

Screen Shot 2021-04-12 at 9.57.22 PM.png

Now we will assemble the jumper wires onto the breadboard for the sensor.

Connect the legs of the LEDs by placing a wire in the GND rail next to the leg of the red LED. Connect the other end of this wire to the GND pin of the sensor into the breadboard.

Connect another wire to the next to the one just placed, and leave the other end as is for now. We will assemble it later into the GND pin of the Arduino.

We will then connect the remaining holes in the breadboard for the HC - S4040 Ultrasonic Sensor. Connect a POSITIVE wire into the VCC pin to the sensor into the breadboard. Next connect a wire for the trig and echo holes of the sensor into the breadboard.

There should be 4 wires in the breadboard that have not been fully connected yet. We will assemble these after we connect the LEDs.

LED Wires

Screen Shot 2021-04-12 at 9.57.33 PM.png

Now we will connect the jumper wires to the POSITIVE pins of the LEDs, with LED1 being on the very left. Leave other end of the wires unattached as we will connect them to the Arduino later.

Ensure that each wire is aligned in same columns as the LEDs.

Connect the Wires

Screen Shot 2021-04-12 at 9.57.49 PM.png
Screen Shot 2021-04-12 at 9.58.00 PM.png

Finally, we will connect the remaining wires into the Arduino.

Start off by connecting the NEGATIVE wire to the GND pin of the Arduino.

Connect the POSITIVE wire of the sensor to the 5v pin of the Arduino.

Connect the trig wire of the sensor to pin 12 and the echo wire to pin 13 of the Arduino.

Connect the following LED’s to their assigned pin of the Arduino:

LED1 -> A0
LED2 -> A1
LED3 -> A2
LED4 -> A3
LED5-> A4
LED6 -> A5
LED7 -> 2

Upload Arduino Code

1280px-Arduino_Logo.svg.png

const int trigPin = 12;
const int echoPin = 13;

const int LED1 = A0;
const int LED2 = A1;
const int LED3 = A2;
const int LED4 = A3;
const int LED5 = A4;
const int LED6 = A5;
const int LED7 = 2;

int duration = 0;
int distance = 0;

void setup()
{
pinMode(trigPin , OUTPUT);
pinMode(echoPin , INPUT);

pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);
pinMode(LED4 , OUTPUT);
pinMode(LED5 , OUTPUT);
pinMode(LED6 , OUTPUT);
pinMode(LED7 , OUTPUT);

Serial.begin(9600);

}

void loop()
{ digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;

if ( distance <= 183 )
{
digitalWrite(LED1, HIGH);
}
else
{
digitalWrite(LED1, LOW);
}
if ( distance <= 190 )
{
digitalWrite(LED2, HIGH);
}
else
{
digitalWrite(LED2, LOW);
}
if ( distance <= 197 )
{
digitalWrite(LED3, HIGH);
}
else
{
digitalWrite(LED3, LOW);
}
if ( distance <= 205 )
{
digitalWrite(LED4, HIGH);
}
else
{
digitalWrite(LED4, LOW);
}
if ( distance <= 212 )
{
digitalWrite(LED5, HIGH);
}
else
{
digitalWrite(LED5, LOW);
}
if ( distance <= 219 )
{
digitalWrite(LED6, HIGH);
}
else
{
digitalWrite(LED6, LOW);
}
if ( distance <= 226 )
{
digitalWrite(LED7, HIGH);
}
else
{
digitalWrite(LED7, LOW);
}
delay(100);
}

Connect Power Cable

Screen Shot 2021-04-12 at 9.59.19 PM.png

Connect the power cable into the Arduino and test your new Covid-Distancing Device!