PR23 - Analog Distance sensor

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR23 - Analog Distance sensor

Postby jonjon87 » Thu Mar 18, 2010 4:11 pm

HI
Regarding to your PR23 DIY Project, I want to ask some question about your analog distance sensor source code.

CODE: SELECT_ALL_CODE
void analog_sen(void)
{
   int distance;                                                // variable for distance measuring
   lcd_clr();                                                   // clear lcd
   send_string("Distance");                                       // display string

   while(1)
   {
      lcd_goto(20);                                          // lcd goto 2nd line
      read_adc(CHANNEL1);                                       // read adc channel 1 ( analog distance sensor input)
      distance = result;                                       // assign distance as the result oft he reading
      dis_num(result);                                       // display the value   

      if (distance< 200)                                       // check if distance less than 200
      {
         backward();                                          // backward with full speed
         SPEEDL = 255;
         SPEEDR = 255;
         buzzer = 0;
      }
      else if (distance< 250)                                    // check if distance less than 250
      {
         backward();                                          // backward with medium speed
         SPEEDL = 230;
         SPEEDR = 230;
         buzzer = 0;
      }
      else if( distance < 300)                                 // check if distance less than 300
      {
         stop();                                             // stop
         buzzer = 0;
      }
      else                                                 // else, distance more than 300
      {
         forward();                                          //forward with medium speed and on buzzer
         SPEEDL = 230;
         SPEEDR = 230;
         buzzer = 1;
      }
   }
}

Q1: What is 200,250,300?I know its the distance measured by sensor, but in waht unit do them stand?

Q2: Does the sensor always measuring distance while the robot is moving?
jonjon87
Greenhorn
 
Posts: 2
Joined: Thu Mar 18, 2010 4:04 pm

Re: PR23 - Analog Distance sensor

Postby ober » Thu Mar 18, 2010 4:22 pm

Please share your code properly, else it will be deleted.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: PR23 - Analog Distance sensor

Postby jonjon87 » Thu Mar 18, 2010 11:01 pm

sorry
my code is actually from your Multi Function Robot-DIY project(PR23).
I get confused about the analog sensor subroutine.
I have tried it,but my robot did not work as expected.
So, my question here, what is 200,250 and 300?and does the sharp analog sensor calculate distance continously?
thanks!
:)
jonjon87
Greenhorn
 
Posts: 2
Joined: Thu Mar 18, 2010 4:04 pm

Re: PR23 - Analog Distance sensor

Postby ober » Sat Mar 20, 2010 1:57 pm

What we request is to use the proper function in forum to share information, like I shown in your post. If you want to share code, use the [Code] function when you post it.

You need to refer to data sheet of IR distance sensor to get the information. You must get the data first in order to translate the data into voltage, as PIC read voltage only, it does not know what is the voltage represent. The program translate the voltage back to useful information.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 16 guests

cron