I used "the same" sample code that the sellers page in.** **But It doesnt work what I want to.
here`s the sample code.(Including comment)
/*
plug infrared motion sensor on digital port 3. If signal is detected, digitalRead
will be high. Switch the resistor backward to adjust the sensitivity as you want.
*/
Janz:
There is no "if" statement in your software.
Why should there be?
All the code is doing is printing out the output of the sensor.
The fact is is outputting zeros and ones suggested the input is floating and that diagram looks like the input pin is connected to 5V.
Thanks for the link. There seems to be a bit of ambiguity about the diagrams with respect to the digital pin out. The photographs do not exactly match the drawings to my mind.
Sadly the English on the links show poor skills from the translator:-
Switch the resistor backward to adjust the sensitivity as you want.
I would ask what resistor, where and what does switching a resistor backwards mean. It would imply swap the two leads of the resistor but that is just stupid so don't try it.
It does say:-
Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room.
So are you doing this? It has a wide coverage so be sure to point it away from you when you "calibrate" it.
Finally check that the wire to pin 3 is making good contact.
I have a PIR sensor too. It outputs about 3,7 volts if motion is detected, otherwise zero volts. If you connect it with a digital pin it will read HIGH ( a "1") if it senses the 3,7 volts, otherwise it will read LOW ( a "0"). My PIR sensor has two little trimmers, one for the time that it outputs the signal, the other for sensitivity.
Turn it away from you and wait until it outputs zeros. Then move your hand in front of the sensor and you will notice it outputting "ones". The sensor is not sensitive in every direction, usually good from left to right and back and not so good from above to under and back.
You will need the "if" statement if you want switch something with it. I succesfully switched 220 volts (with a relay), leds, and even a mediaplayer by sending IR signals. Below is a simple program that switches a led. (don't forget the resistor)
Jan.
int ledPin = 10; // led is connected to pin 10
int pirPin = 2; // PIR is connected to pin 2
int val; // variable for reading the pin status
void setup() {
pinMode(pirPin, INPUT); // Set the pirPin as input
pinMode(ledPin, OUTPUT); // Set the ledPin as output
Serial.begin(9600); // Set up serial communication at 9600bps
}
void loop() {
val = digitalRead(pirPin); // read input value and store it in val