Author Topic: Problems with Sharp IR Range Finder  (Read 2207 times)

0 Members and 1 Guest are viewing this topic.

Offline brianTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Problems with Sharp IR Range Finder
« on: March 12, 2008, 06:08:16 PM »
Hello, so today I was experimenting with the sharp IR range finder and I have some problems. Right now I have it set so that when the sensor reading is not 0 it turns on an LED. The problem is that the LED stays off all the time, however if I spend a minute or two positioning it in front of a mirror I can get the LED to turn on.

Any ideas?

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: Problems with Sharp IR Range Finder
« Reply #1 on: March 12, 2008, 10:32:16 PM »
Which Sharp IR sensor? Which micro controller and which pins are you using? Can you show us the code?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,665
  • Helpful? 169
    • Society of Robots
Re: Problems with Sharp IR Range Finder
« Reply #2 on: March 13, 2008, 07:30:20 AM »
Output the data to hyperterminal.

Also, try having the LED turn on if it receives values from say 0 to 5 and see if it then works.

Offline brianTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Problems with Sharp IR Range Finder
« Reply #3 on: March 13, 2008, 08:32:36 AM »
The Sharp IR I am using is this one http://www.sparkfun.com/commerce/product_info.php?products_id=242

Microcontroller is an Atmega8 and I am using pin PC5... then here is my code.

Code: [Select]
#include "a2d.h"
#include <avr/interrupt.h>    // Defines pins, ports, etc to make programs easier to read
#define F_CPU 1000000       // Sets up the default speed for delay.h
#include <util/delay.h>
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)

int main(){
DDRC = 0x00;  //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF;  //configure all D ports for output
DDRB = 0xC7;  //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//int tim=0;
//int loc=1;

int IRSensor=0;
int IRSensorThresh=0;
IRSensorThresh=a2dConvert8bit(5);

_delay_ms(2000);
while(1){
IRSensor = a2dConvert8bit(5);
if(IRSensor <= 5 && IRSensor >=0){
PORT_ON(PORTD, 4);
}else{
PORT_OFF(PORTD, 4);
}
}
return(0);
}

This code is currently taking into account Admins advice, but unfortunately now the LED stays on no matter what. I would output the data to hyperterminal but I still have to make the modifications to my board (which I guess I should do).

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,665
  • Helpful? 169
    • Society of Robots
Re: Problems with Sharp IR Range Finder
« Reply #4 on: March 13, 2008, 09:28:39 AM »
Use a multimeter to measure the signal wire. See if the voltage changes as expected. I just want to rule out electrical issues.

And . . . I've been known to make this same dumb mistake myself but . . . are you sure its plugged into the right port?

Offline brianTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Problems with Sharp IR Range Finder
« Reply #5 on: March 13, 2008, 10:31:03 AM »
Ok, so I checked the readings with a multimeter, it seems to work... if I change the distance of the object its pointing at I get a votage change. So it looks like either my code, or my atmega8.

EDIT: Solved the problem. The issue was with my code, in global.h the F_CPU was defined for a 3.6mhrtz processor then I later redefined it as 1mhrtz.
« Last Edit: March 13, 2008, 04:15:33 PM by brian »

 


Get Your Ad Here

data_list