Project : Simple Human Following Robot : Ultrasonic Configuration



In the previous post I've shared the overview of the robot. In this post, I will explain how to configure the ultrasonic sensors for this project.

SRF05 is a range sensor based on ultrasonic wave. It can measure from 3cm to 300cm. It allows us to work with 1 PIN connected to microcontroller or 2 PINs. I prefer to use 2 PINs. So, I need 4 cable to connect this sensor to the microcontroller :
1. 5V ( + )
2. ECHO
3. TRIGGER
4. GND ( - )


 http://www.robot-electronics.co.uk/images/srf05tma.gif
( image from www.robot-electronics.co.uk ) 

We can program this device following the timing diagram above.
1. Firstly, we have to send at least 10uS pulse high through PIN TRIGGER. 
2. The sensor will respond by transmitting ultrasonic burst.  
3. We just wait until the sensor receives the echo. 
4. While the sensor receiving the echo, PORT ECHO will high. The length of the high pulse from this PORT indicates the distance between sensor to the wall/human

Here I show you the program for my right sensor that I wrote in CodeVision AVR.
-ATMega128
-PORT C.6 as TRIGGER
-PIN C.7 as ECHO


unsigned int counter;
unsigned int us_right;
unsigned int limit;


 void us_right(unsigned char hold)  
 {  
    right=0;  
    limit=0;  
    counter=0;  
    DDRC.6=1;  //set C.6 as OUTPUT
    PORTC.6=1; //pulse High from PORTC.6 
    delay_us(20);  
    PORTC.6=0;  //Pulse LOW from PORTC.6
    DDRC.7=0;  //set PORTC.7 as input
    PORTC.7=1;  //activate the pull up
    while(PINC.7==0 && limit<=1000) {limit++;}; //echo not yet received  
    while (PINC.7==1) {counter++;}  //receiving echo
    right=counter;  
    delay_ms(hold);  
    if (right<=1) right=1;  
 }  


the distance equals to the number of "right" variable.
 While (1)  
 {  
 us_right();  
 delay_ms(3000);  
 }  
the number of variable "right" is not in centimeter or meter. You need to convert it by dividing the number by a divider. The divider will be different for each sensor.

Share on Facebook
Share on Twitter
Share on Google+

Related to Project : Simple Human Following Robot : Ultrasonic Configuration

0 comments:

Post a Comment

Silakan meninggalkan pesan disini...