Monday, January 26, 2009

Connecting the [im]duino to an IR kit



Here are clearer pictures of my Arduino, (I call it A.L.I.C.E.) and an IR proximity sensor kit from e-gizmo [more info here] 300 Php per unit.

Note for fellow novices, the IR kit shown above already outputs digital signal, also it is made and sold in the Philippines, so if you need to order one from outside Philippines, ask them (site link above).
Ill probably post a how to make an IR sensor next time

If in case you have the same kit, take note that the kit outputs a "low" when an object is in its detection range (usually 25cm), testing it with an arduino platform is a walk in the park.

Here's what you do:
1. Connect your Arduino to your PC (USB/Serial/etc.)
2. Run the Arduino software
3. Click File>Sketchbook>Example>Digital>Button
4. This opens the Button sketch for the program that allows the Arduino to interact with button.
5. Replace parts of the code inside the void loop() function with what you see here, leave the rest as is.

void loop(){
val = digitalRead(inputPin); // read input value
if (val == LOW) { // check if the input is LOW
digitalWrite(ledPin, HIGH); // turn LED ON
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
}
}

6. The kit shown uses 5V, connect the wires with respect to proper polarity, in this case pink to +5V, and gray to ground, and most important is the output (White wire). Connect the IR kit's output wire to pin 2, remember this is where the switch was connected to if you performed the beginner experiments. Then connect a LED (any color) positive lead into Pin 13, negative lead to ground, this will serve as your output to check if the setup (hardware connections and program) is working.

7. The changes made in the program basically changes how the Arduino behaves to input. A "low" input will cause the LED connected to Pin 13 to light up instead(remember, the IR kit outputs a "low" when an object is detected). So when the IR sensor kit is connected, whenever an object gets in the detection range, the LED in pin 13 will turn on.


And there you have it, connecting an IR kit to an Arduino. If you have a different type of IR sensor kit , youll have to identify what its output is (when an object is detected), if your kit outputs a "high" then youll have to change the condition inside the if statement to HIGH.

If your IR sensor has an analog output, you will have to set up a circuit for it, or learn how to program your arduino to accept analog sensor input. Im not yet at that level however... However Ill probably make a post on how to make one's own digital output IR sensor. Till then, Goodnight

0 comments:

Post a Comment