I was thinking that using analogRead you would get more information, than using digitalRead. Digital only tells you "1" when voltage above 2.7V and "0" when it below 2.2V.
First I was using analogRead and I was getting values around 20 and 1020 after trying this I decided to use the digitalRead just to have a simpler output.
Where is this 5V coming from?
The 5V came from the arduino 5V pin.
What voltage did you supply to the arduino when you used the VIN to drive the PIR?
I had the arduino plugged to the USB of my Mac. And in the tests I did the only difference was that the V+ of the sensor was either connected to the arduino 5V pin or the arduino Vin pin.
I re-read the arduino power specs http://arduino.cc/en/Main/ArduinoBoardUno/
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.
and I realized that the main difference between VIN and 5V pins is that 5V comes from the regulator and VIN connects directly to the power supply. So I need to get a multimeter and check the values that the PIR is getting in both cases. But in the case that in both cases it gets 5V is there any difference if the 5volts come from the regulator or not?
I read the forum in sparkfun about this product and it seems that more people is having similar problems. The sensor has its own regulator and it requires more than 5V to work properly. Some people suggest to pass the sensor internal regulator and with this the sensor can work even with 3.3V. So it seems that the sensor is not as straight forward to use as I initially thought. I am planning to run my project using USB and I am not too happy with the idea of getting power for the sensor using the VIN, also using a different power supply for the sensor is not an option. If I would understand what is the main difference of the power coming from VIN and 5V pins when the arduino is powered using USB I would be happier.