DIY Infrared Proximity Sensor

I’m trying to make a low-cost robot kit, and part of this should really be a low cost Infrared Proximity sensor. Here’s the schematics. Ignore the photo-sensors on the right. They are for if you don’t want an IR sensor and you just want to sense the difference between light/dark on two sides of the bot.

It works, but not for very long distances. I’m using it for sensing for example 10 cm, which is fine for a robot.

The part list:

I’ve made a board for it, which is documented here. It’s a sub-board that’s part of the motor driver card.

For the MSP430, connect pin 1 to ground, pin 2 to vcc (3.5V), pin 3 to P2.5 and pin 4 to P1.6

Here’s some test code using Energia (if you haven’t tested Energia, you should. It’s an Arduino-port for MSP430 and is very simple to use). I’ll add a picture later.

[code lang=”c”]

const int analogInPin = A6; // Analog input pin that the potentiometer is attached to
const int analogOutPin = P1_0; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(P2_5, OUTPUT);
pinMode(P1_0, OUTPUT);

}

void loop() {
// read the analog in value:
digitalWrite(P2_5, HIGH);
delay(10);
int on = analogRead(analogInPin);
digitalWrite(P2_5, LOW);
delay(10);
int off = analogRead(analogInPin);
int diff = on – off;

// print the results to the serial monitor:
Serial.print("on = " );
Serial.print(on);
Serial.print("\t off = ");
Serial.print(off);
Serial.print("\t diff = ");
Serial.println(diff);

if (diff > 30) {
digitalWrite(P1_0, HIGH);
}
else {
digitalWrite(P1_0, LOW);
}

delay(100);
}

[/code]

2 thoughts on “DIY Infrared Proximity Sensor”

Leave a Reply

Your email address will not be published. Required fields are marked *