I'm using the following script with spark fun Lite-On LED emitters and detectors with no luck?
Am I using the wrong resistors? Wrong code? All I get is "0"
// This example shows one way of creating an optoswitch
// using an IR LED as emiter and an IR LED receiver as
// light sensor.
// On this case it acts as a tachometer to count the
// revolutions per second of an aeromodelism plane's
// propeller.
//
// + GROUND +GROUND
// | |
// < <
// > 220 ohm resistor > 220 omh resistor
// < <
// | |
// | |
// ----- -----
// / \ >>IR LED emiter >>>>>>>>>>>>>>>> / \ IR LED receiver
// ----- -----
// | |
// | |
// + +5VCD + ANALOG INPUT 0
//
int val;
int count = 0;
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop()
{
val=analogRead(0);
Serial.print(val); Serial.print(" ");
if (count % 40 == 0 ){
Serial.println();
digitalWrite(13,1);
delay (250);
}digitalWrite(13,0); delay (250);
count ++;
}