Robotic Surface Profiler For Highway Pavement Roughness Measurement Using Ultrasonic Arrays
Ultrasonic sensor HC-SR04 is used to measure the distance to an object by using ultrasonic waves.
To get distance from the ultrasonic sensor, we only need to do two steps (1 and 6 on How It Works part)
Arduino's pins can generate a 10-microsecond pulse and measure the pulse duration. Therefore, we can get the distance from the ultrasonic sensor by using two Arduino's pins:
Loose wires are a common cause of strange bugs. You can stack a Proto Screw Terminal Block Shield or a Screw Shield V2 on the Arduino and connect the wires to its screw terminals.
The measurement result from ultrasonic sensor contains noise. In some application, the noised result causes the unwanted operation. We can remove noise by using the following algorithm:
Some manufacturers provide the ultrasonic sensor that has 3 pins. TRIG signal and ECHO signal are in the same pin. In this case, we need to use only one Arduino's pin for both purposes: generating a pulse to the sensor and measuring pulse from the sensor.
This tutorial walks through using a set of ultrasonic sensors to develop a surface map (full disclosure: the final graphic mapping is done in R). This tutorial assumes a gridded layout of sensors. We will use four ultrasonic sensors in the example, with assumed modularity (additional notes below). Let us know if you’ve expanded the system, and what additional modifications you made!
The HC-SR04 ultrasonic sensor can detect objects with a distance range of 2-400cm, using ultrasonic transmitters, receiver, and a control circuit. You’ll see in the user manual and on your sensor four pins: power (VCC), ground (GND), echo, and trigger (trig). From the user manual ( link here ): “to start measurement, Trig of SR04 must receive a pulse of high (5V) for at least 10 [microseconds], this will initiate the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and wait for the reflected ultrasonic burst. When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay for a period (width) which proportion to distance. To obtain the distance, measure the width (Ton) of Echo pin.”
We will use the HCSR04 library ( link here ) in our code, which includes functions for calculating distance. This will keep our code clean, and allow us to focus instead on comparing distance readings across sensors.
Each sensor requires both a 5V and ground connection. To keep wires clean, we’ll connect all four sensors to the same grounding, power, and trigger pin, but each sensor will need a separate echo pin.
In the first version, we just want to make sure everything is wired correctly, and we’ve imported the library correctly. Let’s run intit_DistanceSensors. This code is an adaptation of code provided as an example with the HCSR04 library.
Once that’s up and running, we can see that there’s a lot of noise in the readings – even if we test it against a flat and unmoving sensor. There’s some variation in the readings – the specs for the ultrasonic sensors gives a range of 0.3cm. To deal with this, let’s add a moving average distance across five readings. Let’s run moveAvg_DistanceSensors.
In our last version of the code for the Arduino, we’re going to clean things up a little to allow for post-processing in R. Here, we’re modifying our outputs so the serial monitor print-out can easily be saved as a csv. Our columns will be: x-axis sensor position; y-axis sensor position; value (distance from sensor); and units (always a good practice!). Let’s run serialToCSV_DistanceSensors.
To plot surfaces in R, you can pull the csv you save from the serial monitor output. We used plotly in our sample!
Are you trying to connect an ultrasonic sensor to an Arduino Uno? Look no further! In this educational essay, we'll look at how ultrasonic sensors function and what their essential features are. We will also give you with a step-by-step tutorial for connecting your ultrasonic sensor to your Arduino Uno, as well as the necessary code. Whether you're an experienced Arduino user or just starting out, this article contains everything you need to get started with ultrasonic sensors.
An ultrasonic sensor uses ultrasonic sound waves to detect the distance to an object.
An ultrasonic sensor uses a transducer to emit and receive ultrasonic pulses, which provide information about an object's proximity.
High-frequency sound waves reflect from boundaries to produce distinct echo patterns.
Take a look at our straightforward blog on connecting ultrasonic sensor with Arduino. Whether you're new to this or already have some experience, this guide will make things clear for you to understand ultrasonic sensor interfacing with Arduino.
Also, read our blog on Ultrasonic Sensor Working Principle detailing the principles and workings of these sensors, their applications, and how are ultrasonic sensors used.
The ultrasonic sensor (or transducer) works on the same principles as a radar system. An ultrasonic sensor can convert electrical energy into acoustic waves and vice versa.
The acoustic wave signal is an ultrasonic wave traveling at a frequency above 18kHz. The HC-SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency, which is much higher than the audible range of human hearing.
The generated ultrasonic waves travel in the air to the target and reflect back to the ultrasonic sensor.
Typically, a microcontroller like Arduino is used for communication with an ultrasonic sensor. To measure the distance to an object, the microcontroller sends a trigger signal to the ultrasonic sensor.
The duty cycle of this trigger signal is 10µS for the HC-SR04 ultrasonic sensor. When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts and initiates a time counter. The transmitted sound wave travels in the air and reaches the target object.
The sound waves are reflected back to the ultrasonic sensor’s receiver part. As soon as the reflected (echo) signal is received, the timer stops. The output of the ultrasonic sensor is a high pulse with the same duration as the time difference between transmitted ultrasonic bursts and the received echo signal.
Read our blog smart dustbin project using Arduino detailing Arduino code for making a smart dustbin, the required components, and the circuit diagram for making an automatic dustbin project.
Below are the connection diagram and the code for interfacing the Ultrasonic sensor with Arduino and measuring the distance.
Make all the connections as per the diagram above to interfacing ultrasonic sensor with Arduino.
The above code is used to measure distance using Ultrasoinc sensor and Arduino. This code prints the distance on the serial monitor.
For selecting a Board: Go to Tools >> Boards >> Arduino AVR Boards >> Arduino UNO
For selecting Port: Go to Tools >> Ports >> port to which the Arduino is connected. You can make sure by checking in the device manager.
Step 5 : Once, the board and the Port are selected, click on the upload icon. Once the code gets uploaded successfully, you can see the distance measured by the ultrasonic sensor on the serial monitor.
First, we used 2 preprocessor components for assigning the pins of Arduino to connect the Ultrasonic sensor.
GPIO pin 6 is assigned to read the ECHO signal from the ultrasonic sensor and the GPIO 7 pin is assigned to give a triggering signal to the ultrasonic sensor.
And we have made 2 variables called “duration” and the “distance” of long and int datatype respectively, which hold the duration of the pulse and the distance calculated.
void setup { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); }
Next, we have a “void setup” function, this function executes only once in our program.
In this function, we are configuring the TRIG and ECHO pin as OUTPUT and INPUT respectively using a “pinMode;” function.
Next, we have the “void loop” function. This function executes infinite times, which means executes forever unless purposefully interrupted.
In this function we make the TRIG pin HIGH for 10 microseconds and LOW for 2 microseconds by using the function “digitalWrite;” function and the “delayMicroseconds;” function.
Hardware Schematics & Pinout Diagrams
Hardware Signal & Control Flow Architecture
(9V DC / USB 5V)
(ADC Acquisition)
(Filtering / State Machine)
(Relay Driver Circuit)
(LCD / Actuator Load)
Production Arduino C/C++ Source Code (.ino)
[*] Initializing Hardware Core for Robotic Surface Profiler For Highway Pavement Roughness Measurement Using Ultrasonic Arrays... [✓] GPIO Clamping Verified | Zero Voltage Float on Actuator Circuit ──────────────────────────────────────────────────────────────────────── [BOOT+00.02s] ADC_INIT Calibrated zero-offset = 12 mV (Clean noise floor) [RUN +01.00s] TELEMETRY Sensor ADC: 342 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +02.00s] TELEMETRY Sensor ADC: 388 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +03.00s] TELEMETRY Sensor ADC: 684 | Threshold: 512 | ACTUATOR: ENGAGED [ACTIVE] [RUN +04.00s] INTERRUPT Optocoupler PC817 saturated | Actuator Active in 4.2 ms [RUN +05.00s] TELEMETRY Sensor ADC: 412 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] ──────────────────────────────────────────────────────────────────────── [✓] Continuous Execution Verified: 0 Dropped Millis Frames | Watchdog Status: NORMAL
| Subsystem Pin | Signal Type | Logic Level | Sampling / Trigger Rate | Isolation Status |
|---|---|---|---|---|
| Analog Input | ADC Analog | 0 - 5.0V / 3.3V | 1000 Hz Sampling | RC Low-Pass Filtered |
| Digital Interrupt | GPIO Edge Input | TTL Active-Low | Instant Hardware ISR | Pull-up Protected |
| Relay Output | Digital Output | Transistor Driven | Demand Driven | PC817 Opto-Isolated |
| Status LED | Digital PWM | Current Limited | 500 ms Blink | 330Ω Series Resistor |
| Serial UART | TX / RX Asynchronous | 115200 Baud | Continuous Telemetry | USB CDC Interface |