Pages: [1]   Go Down
Author Topic: IR motion sensor  (Read 375 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* IR_proximity_sensor.jpg (93.25 KB, 1381x771 - viewed 18 times.)
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2565
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int sensor = 10;
int var = 0;
void setup(){
  Serial.begin(9600);
  pinMode(sensor,OUTPUT);
}

void loop(){
 var = analogRead(sensor);
 Serial.println(val);
 delay(100);
}
Logged


Pages: [1]   Go Up
Jump to: