Hi,
I bought some IR LED and receiver pairs from amazon.
I am planning on using these as basic RPM encoders.
To start with I have simply put 5V and GND across the LED and pointed it at a receiver. I have the output from the receiver connected to analogue pin 1 and am reading from the pin. I am receiving 1023 consistently (with the occasional fluctuation). I see no change if I place my finger in front of the LED or remove the LED.
Am I going about this the correct way? Any ideas?
Thanks Jack. (Arduino mega 2560)
const int sensorPin = A1; // select the input pin for the reciever
const int ledPin = 47; // select the pin for the LED
int sensorValue = 0;
float voltage = 0.0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
voltage = sensorValue*(5.0/1023.0);
Serial.println(voltage);
if (sensorValue > 500) //Random number - will fine tune later
{
digitalWrite(ledPin, HIGH); //Turn LED on when value high
}
else
{
digitalWrite(ledPin, LOW);
}
delay(100);
}