Connecting the Devantech SRF04 UltraSonic Sensor To The SV203 powered PPRK
Connecting the Devantech SRF04 Ultrasonic Sensor to the SV203 board powered PPRK is fairly simple and needs only basic knowledge of electronic device operation timing. We have to consider the requirements for this popular sensor. Most sensors, like IR sensors, need only one I/O connection, but the SRF04 needs one for setting the trigger and another to receive the echo. The sensor is shown below :
In order to have
the sensor working, the input line should be held low (logic 0) and then brought
high for a minimum of 10m
sec to
initiate the sonic pulse ( the trigger). For our work, we connect the input pin
of the sensor to an unused servo port pin (Port B). The power of 5v is supplied
to the SRF04 directly from the 5v output of the SV203 board. The output pin of
the sensor is connected to the A/D port (Port A) on the SV203.
Since we need an
initial pulse for a minimum of 10m
sec, we send
a servo command of position 1 to the port where the input of the sensor is
connected and read the output with the read voltage command on the A/D
port.
The following is
the set of commands required for the SRF04
PIN 4 of PORT B
is connected to the input pin of the sensor.
SV4 M1
<enter>
SV5 M1
<enter>
The function Trigger carries two variables; the two port numbers.
The first variable is the input port number and the second variable is the output port number.
int
Trigger(int number1, int number) { // send request for
analog value to SV203 board Err
error; char
buf[10]; char incoming[]="
"; int
value=0; int len,
c=0; int l; // loop
variable DisplayTxt("entered"); StrPrintF(buf, " SV%d
M1 \r", number1); DisplayTxt("triggered"); len =
StrLen(buf); SerSendWait(portRef,
-1); // wait for port to clear SerSend(portRef, buf,
len, &error); // send buffer DisplayTxt("sent"); StrPrintF(buf, "
AD%d \r",
number); DisplayTxt("reading"); len =
StrLen(buf); SerSendWait(portRef,
-1); // wait for port to clear SerSend(portRef, buf,
len, &error); // send buffer // receive from
portRef into incoming buffer using 5 bytes and 3ms
timeout SerReceive(portRef,
incoming, 4, 10, &error); // buffer correction
-- replace all ASCII non-numbers with spaces for (n=0; nl<=5;
n++) if ( incoming[n] == 10
) incoming[n]='
'; incoming[3] =
'\0'; if (incoming[0] !=
'1') // two digit
number cut-off incoming[2] =
'\0'; SerReceiveFlush(portRef,
5); // flush buffers SerSendFlush(portRef); value =
StrAToI(incoming); DisplayTxt("done"); return
value; } |
Some of the fascinating pictures of the PPRK controlled by SRF04 Ultrasonic sensor.
Developed by Mayukh Dass. For further contact mail : dass@uga.edu or visit at http://www.arches.uga.edu/~dass