Hi guys,
I am still a relatively new Arduino user and have did a lot with LED's and things but now I am working toward sensors and applications. I am having a weird problem/issue. I bought the IR emitter and detector from spark fun and I am not getting anything like I thought I would. I have them wired out correctly according to the forum on the sparkfun side. I have them probably about an inch apart facing right at each other. I block them to begin with and then i move the object to try and get a signal and print it to the serial monitor. I have tried analog inputs and pulsein and I am getting the same signal if they are blocked or not. Something seems to be floating but I can't figure out why. The same thing happens with the photoresistor.
Here is the IR test code. The emitter is always on and the receiver is plugged into pin 12.
int irpin = 12;
unsigned long irstatus;
void setup(){
pinMode(irpin, INPUT);
Serial.begin(9600);
}
void loop(){
irstatus = pulseIn(irpin, LOW);
if(irstatus != 0){
Serial.println(irstatus);
}
}
The output is usually close to 0 then close to max, like 5, 986.
Here is the code for the photoresistor (also bought from spark fun).
I have 5V going to the resistor and a 10k resistor to limit the current. Measuring where the resistor and photoresistor starts.
int resistorpin = 1;
int resistval;
void setup(){
pinMode(resistorpin, INPUT);
Serial.begin(9600);
}
void loop(){
resistval = analogRead(resistorpin);
Serial.println(resistval);
delay(50);
}
The serial output for usually goes 0, 0, 0, 234, 687, 1023 for the most part. This doesn't vary no matter what I do.
Any ides or suggestions to help me out?