Using touch sensor with Baby Orangutan

Hello.

I have a pair of cheap touch sensors. They are simply on/of-switches with no electronics in them.

I would like to use them in my obstacle avoiding robot, but I am not sure how. I guess it would be the same as connecting a pushbutton. Should I connect them in the way they recommend connecting pushbuttons with LCD in the BabyO manual? They use VCC, PB3, GND and two resistors.

And would the ADC be the best way to check if they are pushed?

You are absolutely correct in thinking you should copy the pushbutton part of the manual, since that’s essentially what your tactile sensors are, but you should read them as digital inputs rather than using the analog to digital converter. Your switches are essentially digital (two-state) sensors, so you won’t get any extra information out of them by treating them as analog devices, and setting up the ADC is a tad more complicated, especially when polling multiple inputs.

To do this you can connect your switches to any of the PB, PC, or PD pins, but you might want to give which pins some thought. PD2 and PD3 might be good choices, as they are also dedicated interrupt pins, although you can use any input pin as an interrupt. PD0 and PD1 are probably bad choices, since they are also the dedicated UART input and output pins (which you can use to control other devices like a serial motor controller), not to mention PD1 controls your built in indicator LED.

There are a couple of different ways to do the resistor/sensor configurations, but the one in the Baby-O manual is totally fine, and you already have a schematic diagram of it. When the pushbutton isn’t pressed, the input pin is tied to ground and registers low. When the pushbutton is pressed, current flows from VCC to Ground, with the voltage dropping proportionally across the resistors. The input pin sees 10/11*VCC, which is plenty to trigger it and not much current is wasted through the relatively high net resistance of 11Kohm. If your touch sensors are the kind with three contacts, make sure you use the two that are normally open, and close the circuit when the sensor makes contact with something.

To read the sensors in your program, you would do something like this in C:

#include <avr/io.h>//Input Output library

void main(){
	DDRD&=~(1<<PD2);//Sets PD2 direction to input (already set by default)
	DDRD|=(1<<PD1);//Sets LED pin to output
	while(1){
		if(PIND&(1<<PB3)){//If input of PD3 is high, sensor is pressed
			PORTD|=(1<<PD1);//Turn on LED
		}else{
			PORTD&=~(1<<PD1);//Turn off LED
		}
	}
}

Good luck with your robot!

-Adam

Thank you. That worked perfectly.