[vc_row][vc_column width=”1/1″][vc_column_text]Ultrasonic sensors (also known as transceivers when they both send and receive, but more generally called transducers) work on a principle similar to radar or sonar which evaluate attributes of a target by interpreting the echoes from radio or sound waves respectively. Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor. Sensors calculate the time interval between sending the signal and receiving the echo to determine the distance to an object.
This technology can be used for measuring wind speed and direction (anemometer), tank or channel level, and speed through air or water. For measuring speed or direction a device uses multiple detectors and calculates the speed from the relative distances to particulates in the air or water. To measure tank or channel level, the sensor measures the distance to the surface of the fluid. Further applications include: humidifiers, sonar, medical ultrasonography, burglar alarms and non-destructive testing.
Systems typically use a transducer which generates sound waves in the ultrasonic range, above 18,000 hertz, by turning electrical energy into sound, then upon receiving the echo turn the sound waves into electrical energy which can be measured and displayed.
In this post, we are going to look at measure the distance by using an ultrasonic sensor on pcDuino.
[/vc_column_text][vc_tour][vc_tab title=”BOM” tab_id=”1384365475-1-77″][vc_column_text]1. pcDuino experiment platform
2. Ultrasonic sensor breaktout
3. Jumper wires[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1384365475-2-34″][vc_column_text]Please wire the components according to the following rule:
- SR04 Trig —–> pcDuino D2
- SR04 Echo —-> pcDuino D3
- SR04 VCC —-> pcDuino 5V
- SR04 GND —-> pcDuino GND
[/vc_column_text][/vc_tab][vc_tab title=”Explain” tab_id=”1384365878952-2-6″][vc_column_text]When we run the code on pcDuino, the measured distance will be displayed on the screen of pcDuino.[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1384365925276-3-5″][vc_column_text]The following code is running under the Arduino IDE that comes with pcDuino.
#include <core.h>
const int trig = 2;
const int echo = 3;
long microsecondsToInches(long microseconds)
{
return (microseconds / 74 / 2);
}
long microsecondsToCentimeters(long microseconds)
{
return (microseconds / 29 / 2);
}
void setup()
{
pinMode(echo,INPUT);
pinMode(trig,OUTPUT);
digitalWrite(trig,LOW);
delay(20);
}
void loop()
{
long duration,inches,cm;
digitalWrite(trig,HIGH);
delayMicroseconds(20);
digitalWrite(trig,LOW);
duration = pulseIn(echo,HIGH,1000000);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
printf("%din, %dcm \n",inches,cm);
delay(80);
}
[/vc_column_text][/vc_tab][vc_tab title=”Run” tab_id=”1384365966730-4-7″][vc_column_text][/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.