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

WellPCB PCB Manufacturing
urPCB PCB Manufacturing
PCBGOGO PCB service

Gearbest Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black
Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black only $$162.89

AFFILATE

Gearbest Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black
Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black only $$352.94

Gearbest Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black
Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black only $$153.84

Gearbest Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black
Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black only $$253.39