Go Down

Topic: IR motion sensor (Read 435 times) previous topic - next topic

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.

Any response will be appreciated.

Riva

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.

Code: [Select]
int sensor = 10;
int var = 0;
void setup(){
  Serial.begin(9600);
  pinMode(sensor,OUTPUT);
}

void loop(){
var = analogRead(sensor);
Serial.println(val);
delay(100);
}
I might seem like an idiot but remember it takes one to know one.
Forum user generally fall into three categories (the good, the bad & the a**hole) what category do you fit in?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy