Wireless distance measurement using ultrasonic sensor
Introduction:
The distance measurement project is a very useful project, which can be used in automobiles to avoid accidents, or in any distance monitoring system in industry, and can also be used in liquid level indicators such as fuel tanks. planes. This system consists of an ultrasonic sensor with a microcontroller and display. The sensor, display and circuit are connected with wires. Therefore, if we need to place the sensor and display at some distance (say 2-3 meters or more), we will have to make a long wire connection. But in some systems it is necessary to monitor/measure the distance from a remote location. Like the sensor is connected to a robotic vehicle wirelessly and we need to know the distance to any object around the vehicle at a remote location. In this case, it is necessary to transmit the sensor output and display it on the LCD at a remote location. This is possible with the help of RF technology.
The new and different approach in this project is to monitor the distance or liquid level of the fuel tank wirelessly from a remote location. The sensor is connected to the tank or any moving object, but the sensor value (distance) can be monitored at a remote location such as on our table. Wireless monitoring system is very useful in many cases.
Description:
The project uses two microcontrollers. One will measure the distance using the ultrasonic sensor module and transmit that value using the RF Tx module and another will receive that value using the RF Rx module and display it on the LCD. The ultrasonic sensor works based on the basic principle of radar. It generates continuous pulses and receives echo signals if any object is within range. The analog data from the sensor is converted to digital format using ADC in the microcontroller and this data is transmitted by the RF Tx module (434Mhz) connected to the serial port of the microcontroller. It is necessary to convert the sensor value into distance in centimeters. The formula to convert is
Test distance = (high level time×sound speed (340M/S)) / 2
And also consider the measurement angle.
So now let's start building the project and for this first step is to collect the necessary components and equipment:
Required components and equipment:
Sr. No. Component Name Required Quantity
1 RF Tx module (434 MHz) 1
2 RF Rx Module (434 MHz) 1
3 Ultrasonic sensor 1
4 LCD 1
5 1K Pot 1
6 10 K resistor 1
7 Arduino pro mini 2 development board
8 Battery – 9V 2
9 Breadboard 2
10 connecting wires
Circuit Diagram:
To build the circuit on the breadboard as per the above circuit diagram, follow the step by step procedure
Procedure:
Transmitter Section:
Step 1: connect the 2nd pin of the Tx module to the 12th pin of the Arduino board, the 1st pin to ground and the 3rd pin to Vcc.
Step 2: Connect pin 1 of the ultrasonic sensor module to Vcc and pin 4 to ground. Connect the trigger pin to Arduino pin 2 and the echo pin to Arduino pin 4.
Receiver Section:
Step 1: connect the 1st pin of the Rx module to ground and the 4th pin to Vcc
Step 2: Connect the second pin of the receiver module to the 11th pin of the Arduino
Step 3: Connect the second pin of Arduino to LCD Enpin (6), third pin to Rspin (4) and 4,5,6,7 pins to LCD D5, D6, D7, D8pins respectively.
Step 4: Connect the LCD's RW pin (5) to ground.
Step 5: connect LCD pins 1 and 16 to ground and 2 and 15 to Vcc. Connect the 1K potentiometer to the third pin as shown to vary the LCD brightness
Working:
1. In this project we are measuring distance using ultrasonic sensor module. The sensor value is in analog form. The sensor value is converted into digital using microcontroller
2. The digital value is applied to the 434 MHz Tx module to send as an ASK signal.
3. The LCD which is connected to the microcontroller which displays the value received by the 434MhzRx module.
4. In this project, data transmission is based on the serial ports of the microcontroller.
5. When an object in front of the ultrasonic module reflects sonic waves, these waves are called echo waves. The echo waves are received by the sonic receiver and produce analog output.
6. The sensor output is converted to cm scale to measure distance and transmitted to the receiver for display on the LCD
Photos:
Project source code
Project source code
constinttrigPin = 2;constintechoPin = 4; char Distance(4); void setup { Serial.begin(9600); vw_setup(2000); } void loop { int duration, inches, cm; pinMode(trigPin, OUTPUT);digitalWrite(trigPin, LOW);delayMicroseconds(2);digitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW); pinMode(echoPin, INPUT);duration = pulseIn(echoPin, HIGH); // convert the time into a distance //inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(inches);Serial.print("in, ");Serial.print(cm);Serial.print("cm");Serial.println ; delay(100); itoa(cm,Distance,10); digitalWrite(13, true); // Turn on a light to show transmittingvw_send((uint8_t *)Distance, strlen(Distance));vw_wait_tx ; // Wait until the entire message is gonedigitalWrite(13, false); // Turn off a light after transmissiondelay(200); } longmicrosecondsToCentimeters(long microseconds){ return microseconds / 29 / 2;} Receiver:#include
LiquidCrystallcd(2, 3, 4, 5, 6, 7); #include
// LED'sintledPin = 13; // Sensors int Data; // RF Transmission containerchar Distance(4); void setup {Serial.begin(9600); lcd.begin(16, 2);lcd.print("ENGINEERS GARAGE");lcd.setCursor(0, 1); // sets the digital pin as outputpinMode(ledPin, OUTPUT); pinMode(9, OUTPUT);pinMode(8, OUTPUT); // VirtualWire // Initialize the IO and ISR // Required for DR3100vw_set_ptt_inverted(true); // Bits per secvw_setup(2000); // Start the PLL receiver runningvw_rx_start; } // END void setup void loop {uint8_tbuf(VW_MAX_MESSAGE_LEN);uint8_tbuflen = VW_MAX_MESSAGE_LEN; // Non-blockingif (vw_get_message(buf, &buflen)) {inti; // Turn on a light to show received good message digitalWrite(13, true); // Message with a good checksum received, dump it. for (i = 0; i
{ // Fill Sensor1CharMsg Char array with corresponding // chars from buffer. Distance(i) = char(buf(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 "); }}
//Program to
###
Circuit diagrams
RF18 |
|
Questions related to this article?
Ask and discuss on the EDAboard.com and Electro-Tech-Online.com forums.
Tell us what you think!! Cancel reply
You need to be logged in to post a comment.