Adding a sharp infrared sensor

Hi,

I would like to add an analog sharp infrared sensor in front of the 3pi in order to detect obstacles. Would I have to use an extra microcontroler like the baby orangutan for it and thus make use of the extra board with cutouts as well? Is an A/D converter needed? If not were exactly should the 3 sensor cables be soldered?

Thanks very much!

Hello.

You can add a sharp distance sensor directly to the 3pi. The sensor outputs an analog voltage, so you will need an ADC to read it. Three of the mega168’s analog inputs (ADC6, ADC7, and PC5) are connected through jumpers to optional hardware on the 3pi, so you can use these for your own purposes if you remove the jumper. ADC6 is jumpered to 2/3 of the battery voltage, ADC7 is jumpered to the trimmer potentiometer, and PC5 is jumpered to a MOSFET that controls the reflectance sensors’ IR LEDs. When you remove the PC5 jumper, these LEDs are just on all the time, so while it might not be as power-efficient, you can still use the sensors.

You would solder the sensor output to one of the analog inputs that you’ve freed up by removing the associated jumper. You would connect the sensor’s power line to VCC (5 V) and its ground line to ground. You might also want to put a 10 uF capacitor or larger across VCC and ground somewhere near the sensor to prevent its periodic IR pulses from causing a dip in the regulated voltage. The Pololu AVR library has analog functions that will let you easily read the analog voltage from the sensor once you have it connected properly.

- Ben

Hello,

One thing about the jumpers that isn’t totally clear is which lead goes to the microcontroller.

For each of these descriptions have the LCD screen side towards you.
ADC6: right pin goes to microcontroller, left pin is at 2/3 battery voltage
ADC7: right pin goes to microcontroller, left pin reads the trimmer potentiometer
PC5: left pin goes to microcontroller, right pin reads the IR sensor array

It’s not recommended that you solder directly to the jumper pins. Instead use a 3pi expansion board or the expansion port and connect your distance sensor’s output line to ADC6, ADC7, or PC5 on the expansion kit (see pololu.com/catalog/product/979/

As for programming:
Read ADC6 with

int result = read_analog(6);

Read ADC7 with

int result = read_analog(7);

Reading PC5 is a bit more complicated. You initialize it once with

DDRC &= ~(1 << PC5);
PORTC &= ~(1 << PC5);

then read it with

int result = analog_read(5);

Ryan