yt_link
insta_link
fb_link
twitter_link

Homemade sensor
page 2/2


Homemade ultrasonic distance sensor

Help me by sharing this post


PART 5 - Test the module

After I've uploaded the code to my module I've made the enxt connections between the homemade module and another Arduino UNO. I’ve connected an LCD to the Arduino UNO and connect D3 and D4 to the trigger and echo pins of my homemade module. Now I upload this next code to the second Arduino and place an object in front of the sensor. This code will only apply a trigger pulse and measure the delay between the sent and received echo and then print the distance on the LCD.


Download LCD test code:

Download i2c lyquid crystal library:

circuit sr04 ultrasonic

Make the connections above and uplaod next code to the Arduino uno. This code will measure the width of the echo pulse and divide that by 2. Next we multiply taht by 34000cm/s and we het the distance in cm and print it on the LCD. REMEMBER! you have to isntall i2c liquid crystal librery in order to work with the i2c LCD.


// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.setCursor(11,0);
lcd.print(distance);


Download LCD test code:










Go back ←

Help me by sharing this post








ADVERTISERS
PCBWAY PCB Manufacturing

PCBWAY Christas PCB Manufacturing

Advanced PCB Manufacturing
Advanced PCB Manufacturing

AFFILATE

Gearbest SG - 700 Satellite Navigation Foldable RC Drone Quadcopter - WHITE 720P WIFI FPV CAMERA
SG - 700 Satellite Navigation Foldable RC Drone Quadcopter - WHITE 720P WIFI FPV CAMERA only $46.99

Gearbest Xiaomi AMAZFIT Heart Rate Smartwatch - BLACK INTERNATIONAL VERSION
Xiaomi AMAZFIT Heart Rate Smartwatch - BLACK INTERNATIONAL VERSION only $89.99

Gearbest FeiLun FT011 2.4GHz Brushless RC Racing Boat - BLACK AND WHITE AND RED
FeiLun FT011 2.4GHz Brushless RC Racing Boat - BLACK AND WHITE AND RED only $96.99