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.
Fig. 1: Prototype of Arduino based Wireless Distance Meter
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.
Components Required
Sr. No. | Components Required | Quantity Required |
---|---|---|
1 | RF Rx Module(434Mhz) | 1 |
2 | RF Tx Module(434Mhz) | 1 |
3 | Ultrasonic sensor | 1 |
4 | LCD | 1 |
5 | 1 k Pot | 1 |
6 | 10 k resistor | 1 |
7 | Arduino pro mini devlopment board | 2 |
8 | Battery- 9V | 2 |
9 | Breadboard | 2 |
10 | Connecting wires |
BLOCK DIAGRAM
Circuit Connections
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.
Fig. 2: Image showing working of Arduino based Wireless Distance Meter
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 E pin of LCD is connected to pins 3 and 2 of the Arduino Pro Mini respectively. The RW pin of the LCD is grounded.
LCD | ARDUINO UNO |
---|---|
RS | 3 |
RW | GRND |
E | 2 |
D7,D6,D5,D4 | 7,6,5,4 Respectively |
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.
Fig. 3: Circuit Diagram of Arduino based Wireless Distance Meter
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.
Programming Guide
At the transmitter side Arduino, first the standard libraries are imported. The VirtualWire library is imported to access the analog input from Ultrasonic Sensor.
#include <VirtualWire.h>
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().
You may also like:
Project Source Code
###
#includeconst int trigPin = 2; const int echoPin = 4; char Distance[4]; void setup() { Serial.begin(9600); vw_setup(2000); } void loop() { int duration, distance, cm; pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); distance=duration*34/200000; //Convert metre to cm cm = distance*100 Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); //Convert integer value to character value itoa(cm,Distance,10); digitalWrite(13, true); // Turn on a light to show transmitting vw_send((uint8_t *)Distance, strlen(Distance)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, false); // Turn off a light after transmission delay(200); } #include#include LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // LED's int ledPin = 13; // Sensors int Data; // RF Transmission container char Distance[4]; void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.print("ENGINEERS GARAGE"); lcd.setCursor(0, 1); // sets the digital pin as output pinMode(ledPin, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT);// VirtualWire // Initialise the IO and ISR // Required for DR3100 vw_set_ptt_inverted(true); // Bits per sec vw_setup(2000); // Start the receiver PLL running vw_rx_start(); } // END void setup void loop(){ uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; // Non-blocking if (vw_get_message(buf, &buflen)){ int i; // Turn on a light to show received good message digitalWrite(13, true); // Message with a good checksum received, dump it. for (i = 0; i Distance[buflen] = ''; // Convert Sensor1CharMsg Char array to integer Data = atoi(Distance); // DEBUG Serial.print("distance = "); Serial.print(Data); Serial.println(" cm "); lcd.setCursor(0, 2); lcd.print("Distance = "); lcd.print(Data); // change the analog out value: lcd.print("cm "); }}###
Circuit Diagrams
Project Video
Filed Under: Tutorials
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.