Author Topic: IR sensor problem  (Read 1742 times)

0 Members and 1 Guest are viewing this topic.

Offline alex2988Topic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
IR sensor problem
« on: May 23, 2010, 04:44:21 PM »
I'm trying to read a values from my sharp ir sensor but i'm having a problem. I have sent the values to my lcd and when i hold my hand in front of the ir sensor it stays at a certain value depending on the distance.
But after it detect an obstacle or two....when there is nothing in front of the sensor the value that it indicates keeps on rising
sometring like 130...131....131....132...and so on and it dosn t stop.

It's something wrong with my IR senzor or with my code?

unsigned int temp_res;
int i=0;

unsigned int ADC_senzor(){
                         ADCON0 = 0b10011001;
                        delay_us(10);
                        ADCON0.GO_DONE=1;
                        adc_wait:
                        if(ADCON0.GO_DONE==1) goto adc_wait;
                      // Get 10-bit results of AD conversion
                        //PIR1=0b00000000;
  return ADC_read(3);
}

void main(){

  TRISB = 0 ;
  TRISA  = 0x08;
    ////////////////////////////////////////////////////
  ADCON0 = 0b10011001;
  ADCON1 = 0b10000100;
  delay_ms(10);
 PIR1=0b00000000;
 PIE1=0b01000000;
 INTCON=0b11000000;
  delay_ms(10);
  /////////////////////////////////////////////////////////////////
  //a=0b1100100;

  do{
  temp_res=ADC_senzor();a
....
}
}

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: IR sensor problem
« Reply #1 on: May 24, 2010, 07:53:40 AM »
What processor and compiler?
I can tell its a PIC but which one.

Or is there something wrong with the display code?

How is the Sharp IR sensor powered? These do draw a huge amount of current when it pulses the LED.
Do you have an additional cap on the Sharp sensor?
Also you can try power the Sharp from a separate power supply, battery or regulator.

Offline alex2988Topic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Re: IR sensor problem
« Reply #2 on: May 24, 2010, 02:08:52 PM »
I am using a PIC 16f877 ....actually it's a tutor board based on a 16f877.I really dont think that is a hardware problem.the porblem apears after 1 minute.and i don't understand why

Offline Pratheek

  • Contest Winner
  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 3
    • Probots
Re: IR sensor problem
« Reply #3 on: May 25, 2010, 06:30:45 AM »
Take a multimeter and measure the voltage at the output pin of your sharp sensor when there is no object in front of it. If the voltage at the output remains constant, then your sensor is perfectly fine and the problem is with your microcontroller. If the output voltage of the sharp sensor keeps rising even when there is no object in front, then the problem is with your sensor.

As suggested by waltr, do put filtering capacitors across your sharp sensor.

And finally, I guess you will have already taken this into consideration while writing the code - sharp sensors have a response time of around 40 ms, which means after you get a particular sensor reading, you will have to wait for another 40ms before you get the next reading.

 


data_list