Distance measurement has important applications in automotive and industrial applications. The distance measurement through sensors is useful in detecting obstacles and measuring the fluid levels in automotive tanks and containers. It is the distance measurement feature that allowed to imagine about self-driving cars and robots. Without a technology that may have allowed to measure distance from an object or obstacle, self-driving concept would have never been thought of. The distance measurement application is also used in industries to check fuel levels in aircrafts and commercial transport vehicles. The application is used in robotics to equip autonomous robots detect obstacles and find an accessible path. This project is also a distance measurement application using ultrasonic sensors.
Any distance measurement application has a sensor circuit and an actuator or display circuit (to perform path change according to the obstacle detection or display the distance reading respectively). Often these circuits are connected through a wire line for transmission of data between the two. This project has utilized a 434 RF module to transmit distance reading instead of using a wired bus. This way the project can be easily deployed to any industrial environment where installing the cable between the sensor circuit and the actuator/display circuit may be risky or costlier. An RF module has typical operational range of 50-60 metre and can be extended to 300-350 metre using an antenna and increased transmission power. This way the wireless distance measuring system can be deployed to any place and have supervision or control operations activated from a remote location.
The project uses an ultrasonic sensor to measure distance (and sensor used can measure distance from 2 to 400 cm) and is built on Arduino Pro Mini. A 16X2 LCD is used at the display circuit to show measured readings. A 434 RF transmitter and receiver form the wireless bridge between the sensor circuit and display circuit.
|Sr. No.||Components Required||Quantity Required|
|1||RF Rx Module(434Mhz)||1|
|2||RF Tx Module(434Mhz)||1|
|5||1 k Pot||1|
|6||10 k resistor||1|
|7||Arduino pro mini devlopment board||2|
|10||Connecting wires|| |
There are two circuits in the project - Sensor circuit and Display Circuit. The sensor circuit is built on an Arduino Pro Mini. The ultrasonic sensor is connected to pins 2 and 4 of Arduino. The ultrasonic sensor has four pins - Ground (Pin 1), Echo (Pin 2), Trigger (Pin 3) and Trigger. The VCC and ground pins are connected to VCC and Ground respectively. The Echo pin is connected to pin 4 of the Arduino board while Trigger pin is connected to pin 2 of Arduino board. An RF transmitter is directly connected to the Arduino Pro Mini with pin 2 connected to pin 12 of the board for serial data out and has an antenna attached to pin 4 of the module.
The other circuit is display circuit. It has an RF receiver connected to Arduino Pro Mini with pin 2 connected to pin 11 of the board for serial data in. An antenna is connected at pin 8 of the RF receiver. An LCD is interfaced to the Arduino board for showing the distance reading. The 16X2 LCD display is connected to the Arduino board by connecting its data pins to pins 7 to 4 of the Arduino board. The RS and RW pin of LCD is connected to pins 3 and 2 of the Arduino Pro Mini respectively. The E pin of the LCD is grounded.
The standard code library for interfacing Arduino UNO and Arduino Pro Mini are used in the project to program LCD with the board.
How the circuit works
The ultrasonic sensor works on the principle of echo of sound waves. When a HIGH pulse of 10usec is passed to the trigger pin of the sensor, it transmits eight 40KHz waves of HIGH Sonic Pulse shots back to back. A High pulse signal is out from the echo pin as the ultrasonic wave is transmitted. This wave when collides with an obstacle, it is reflected back and detected by the sensor. On detecting the wave again, the High pulse signal from the echo pin of the sensor is terminated. The signal received from the echo pin is analog in nature. The distance from the obstacle can be measured by measuring the high time of the echo pin. This is the time between the transmission and reflection back of the sonic wave. The distance is given by the formulae -:
Test distance = (high level time × velocity of sound (340M/S)) / 2
The time multiplied by velocity is divided by 2 as the time taken is for sonic wave to reach obstacle and return back. Therefore the distance measurement in cm can be given by the formulae - :
Test distance = (high level time × velocity of sound (340M/S)) / 2
= (high level time(microsecond) × velocity of sound (340M/S)) / 2
= high level time x 340/2000000 m
= high level time x 34000/2000000 cm
= high level time x 34000/2000000 cm
The ultrasonic sensor outputs the high pulse from pin 2 which is detected at the pin 12 of the Arduino Board. The program code measures the pulse duration and digitize it to a distance value using the formulae stated above. The distance measurement is serially transmitted using the RF transmitter in the form decimal characters.
At the display circuit, the decimal characters corresponding to distance measurement are received by the RF receiver and serially passed to the pin 11 of receiver-side Arduino Pro Mini. The receiver side Arduino has the embedded program to store the serially received characters into a memory buffer and pass the buffered characters to 16X2 LCD in a presentable format. Check out the transmitter side Arduino program code to learn how pulse width from ultrasonic sensor is measured and measurement is converted to decimal characters for presentation. Then, check out the transmitter side program code to learn how received characters are taken into buffer and displayed on the LCD.
At the transmitter side Arduino, first the standard libraries are imported. The VirtualWire library is imported to access the analog input from Ultrasonic Sensor.
There are two constants defined "trigpin" mapped to pin 2 where trigger pin of ultrasonic sensor is connected and "echopin" where echo pin of ultrasonic sensor is connected.
A "Distance" array of character type is created to store characters corresponding to the value of distance measured.
A setup() function is called where the baud rate of the Arduino board is set to 9600 bits per second using the Serial.begin() function.
The vw_setup() function is used to set the data rate for serial transmission to 2000 bits per second.
A loop() function is called, where "duration" variable to store pulse width duration, "distance" variable to store distance value in metre and "cm" variable to store value of distnace in cm are declared.
The 10uS pulse shot is generated at the trigger pin by setting the "trigpin" variable to output using pinMode() function. A LOW is passed to trigpin as beginning of the pulse shot for two microseconds followed by 10 microseconds HIGH pulse, then the trigpin is set to LOW to terminate the pulse shot.
The echopin is set to input using pinMode() function. The HIGH pulse duration at the echo pin is measured using the pulseIn() function and stored to the variable "duration".
The pulse width measurement is converted to distance measurement using the time-velocity formulae. The measurement is in metre which is converted to centimetre by multiplying with 100.
The distance measurement in cm is stored in the microcontroller buffer using the Serial.print() function along with the "cm" string. The distance measurement in cm is converted to character value and stored in Distance array using itoa() integer to character conversion function.
The LED connected at pin 13 is switched ON to indicate data transmission in progress. The Distance value is serially send to the RF transmitter using vw_send() function where the characters are converted to unsigned characters as parameter. vw_wait_tx() fiunction is used for microcontroller to prompt push to talk until all characters are serially transmitted. The LED is switched OFF to indicate that the distance reading has been successfully transmitted.
This terminates the loop() function and so the transmitter side program code.
At the receiver side Arduino board, standard libraries are imported. The Liquidcrystal.h is imported to perform lcd interfacing and content display. An array "lcd" is created with pins interfaced to LCD mapped to LiquidCrystal object. The VirtualWire library is imported to read serial data from the RF receiver.
Additional global variables are declared - "ledpin" mapped to pin 13 where reception indicator LED is connected, "Data" to store integer value of distance reading and Distance array to read one to one character of received character buffer.
A setup() function is created to run the initialization code. Inside the function, baud rate of the Arduino is set to 9600 bits per second using the Serial.begin() function. The lcd is configured to 16X2 mode using lcd.begin() function. Initial messages are flashed and cursor is set to first line of the display. The pinMode function is used to set LCD connected pins output.
The RF transmitter and receiver module does not have Push To Talk pin. They go inactive when no data is present to transmit or receive respectively. Therefore vw_set_ptt_inverted(true) is used to configure push to talk polarity and prompt the receiver to continue receiving data after fetching the first character. The baud rate for serial input is set to 2000 bits per second using vw_setup() function. The reception of the data is initiated using vw_rx_start().
A loop() function is called where "buff" array of unsigned character type is created to retrieve buffer characters and "buflen" variable is created to keep check on the length of the character buffer.
The character buffer is detected using the vw_get_message() function, if it is present, a counter "i" is initialized and LED
connected pin 13 is switched on by sending a HIGH at pin 13 to indicate successful detection of
character buffer. The character buffer is stored in the Distance array using the for loop with the initialized counter.
The null character is detected in the buffer stream so that no garbage value goes to the LCD display. The characters received from the buffer are converted to integer value and stored in "Data" variable.
The variable value along with relevant strings enclosed is passed to the microcontroller's buffer and passed to the LCD for display in a presentable format.
This ends the loop() function and so the receiver side program code.