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. The circuit diagram below shows the connections:

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 sensor.

PIN 4 of PORT B is connected to the input pin of the sensor. PIN 4 of PORT A is connected to the output pin of the sensor.

The board command required is :

SV4 M1 <enter> AD4<enter>

For the connection of the second Devantech SRF04 sensor, we will take the help of one of the free power output of the Port - B. In this case, we will take the help of a voltage regulator with an output of 5v to power our SRF04 sensor. In the above diagram, we have used Pin 5 from Port - B to power our second Ultrasonic sensor. We could have used the 5v output of the SV203 from J4 pin to power the two sensors simultaneously, but that may draw more current from the SV203 board and eventually damage it. For the second sensor, we have used Pin 5 of the Port -A for receiving the echo and the Pin 5 of Port -B for triggering.

The board command required is :

SV5 M1 <enter> AD5<enter>

Sample code for PPRK in Metrowerks Codewarrior:

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