Archive - October, 2008

IR Sensor stuff

Guilherm asked to see a schematic for the IR sensors, so i’ve knocked a quick one up in Eagle for anyone else who’s interested. In the circuit, in its most basic form, the IR led is always on, connected to 5volts with a suitable resistor for the IR diode you are using in relation to the power supply.The IR sensor is connected in the same way, i found a 10k resistor worked in this case, but play arround with different values as it will affect is performance.

Both the IR led and sonsor should be connected to ground.

Between the resistor and the sensor, a jumper wire is connected to what ever you are using to read the sensor. This can be an analogue comparitor connected to an led circuit, or in my case in the videos below. an analogue input on the Arduino, either directly or via a demultiplexor.

ir-sensor.png

Simple arduino code to read sensor and send to serial/USB.

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(analogRead(5));
delay(20);
}

Simple Arduino code to read sensor and switch on an LED connected to Pin 8:

//works between 200 and 300 threshold with 5mm perspex.
//direct light triggers sensor and sensor only works with perspex when inverted, trigger = off.
int ledPin = 8;      // LED connected to digital pin 9
int analogPin = 5;   // potentiometer connected to analog pin 3
int threshold = 300;

void setup()
{
pinMode(ledPin, OUTPUT);   // sets the pin as output
Serial.begin(9600);
}

void loop()
{

if (analogRead(analogPin) < threshold) {
digitalWrite(ledPin, LOW);  // turn LED ON
} else {
digitalWrite(ledPin, HIGH);
Serial.println(analogRead(analogPin));
}

}

In this code, the led is switched on when the sensor value exceeds a certain reading, but could be adapted to dim an LED using PWM very easily. At the moment i have 16 sensors connected via two 4051 demultiplexor IC’s, connected to two analogue inputs on the arduino, and several digital pins to control which pins are read on the 4051. The Arduino then pumps the sensor readings out to a TI 5940 led controller as PWM signals to control the LED’s.

Hope this helps  Guilherm!