I am trying to make a motion sensor with infrared emitter and detector from radioshack. Schematic attached. The thing is that i made a code to read the values of the sensor and it is reading crazy values. It is not doing nothing at all wen i aproach something to the sensor. I dont know if it is the code or the circuit. This is the code:
int sensor = 10;
int var = 0;
void setup(){
Serial.begin(9600);
pinMode(sensor,OUTPUT);
}
void loop(){
var = analogRead(sensor);
Serial.println(val);
delay(100);
}
Someone told me that i have to use the map statement, but every examples that i had seen are for calibration.
Hi Danielpag,
First off you should use the code tags (# button when writing message) around code as it makes it more readable and more likely people will respond.
Your using pin 10 for the sensor that I assume should be input pin but your defining it for output ALSO your trying to read this pin using analogRead but only pins A0-A5 are analogue input pins. You need to set sensor as INPUT and try using digitalRead instead of analogRead OR change code and wiring to use one of the analogue pins.
int sensor = 10;
int var = 0;
void setup(){
Serial.begin(9600);
pinMode(sensor,OUTPUT);
}
void loop(){
var = analogRead(sensor);
Serial.println(val);
delay(100);
}