Hey, I'm currently working on a project to make a Sharp IR 2Y0A02 sensor to work as a keyboard button in a game. http://www.acroname.com/robotics/parts/R144-GP2Y0A02YK.html
To do this I first wanted to test it with a led and see if I could turn on the led by activating my IR sensor.
I've been looking at these homepages:
http://www.e-gadget.com.au/category/63-arduino-duemilanove-and-infrared-sensor-tutorial.aspx
http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/
So far I've thought of doing it like this. I haven't tested it yet, because I'm not sure that it is correct.
int IRpin = 1; // analog pin for reading the IR sensor
int ledPin = 10; // Setup LedPin on Digital Pin 10
void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output:
Serial.begin(9600); // start the serial port
void loop()
{
if (sensors[0] < 750)
{
// Turn on the LED if we get a High Reflectance.
digitalWrite(ledPin, HIGH);
}
// Turn off the LED if we have a Low Reflectance.
else digitalWrite(ledPin, LOW);
}
What do you think of this?
At the moment, I'm not sure what I should name the sensors[0] or what distance it should be set at.
Also, do I need to program it to show me the distance time?
Hope you will be able to help me