Switching PIR-Sensor On/Off with Transistor

Hey guys, I'm using a PIR-Sensor for my Project, but most of the day I don't need the sensor, so I wanted to switch it off when my Arduino goes into sleep mode.

#include <avr/sleep.h>
#include <avr/power.h>

int inputPin = 2;
int val = 0;
int switchPin2 = 8;


void setup() {
  pinMode(inputPin, INPUT);
  pinMode(switchPin2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(switchPin2, HIGH); //Here I want to switch the sensor on, to get the value of it.
  delay(100);
  val = digitalRead(inputPin); 

  if(val == HIGH){   //If the value is high, the arduino goes into sleep
    delay(900);
    pwrDown(10);
  }else{
    
  }
}

void pwrDown(int sekunden) {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   for(int i=0; i < sekunden; i++) {
    //power_all_disable (); 

    digitalWrite(switchPin2, LOW); //Here I switch it off before the arduino goes to sleep

    sleep_enable(); // sleep mode einschalten
    sleep_mode(); // in den sleep mode gehen
    sleep_disable(); // sleep mode ausschalten nach dem Erwachen
  }
}

I cut out parts of my code that can't be the problem

My problem is that the digitalRead of the PIR-Sensor's input pin is always HIGH, even though there isn't anything moving.

I'm using an BD911, it's wired up correctly.

Maybe anyone knows how to solve that problem ;D

Post a wiring diagram (not Fritzing, please).

I'm not quite sure if that's what you want :confused:

I connected the sensor as following:
VCC -> Collector
Signal -> Pin 2
GND -> GND

The attached picture shows the wiring diagram that I made

Not much better than a Fritzing, that diagram. Rather unreadable, especially which pins are used.

If I read it correctly: your transistor is the wrong way around, and on the wrong side of the PIR.

OPs diagram:

Yeah, it isn't the best ;D
But I have also a 433 MHz Transmitter hooked up with a BD911 Transistor, the same way, and it works perfect.

Edit: I tried connecting the Transistor the other way round and it still doesn't work, same "error"

Does the PIR go from low to high or high to low when it detects movement?

How much does the Yun use in sleep mode.

I doubt that the ~70uA idle current from a PIR sensor will make a lot of difference.

The 433Mhz transmitters I have use zero mA when not transmitting.
Useless to switch power to those, unless you have a 433Mhz tranceiver.
Leo..

INTP:
Does the PIR go from low to high or high to low when it detects movement?

The PIR pictured goes HIGH (3.3volt) when movement is detected.
But when connected to an input pin, there is no current flowing in either state.
Leo..

For further testing:

  • connect the PIR without transistor, make sure it works.
  • connect the transistor to an LED, see whether you can switch the LED. Then at least you know the transistor circuit is correct, and can replace the LED with the PIR later.

By the way, I recall PIR sensors need some time from switching on before they actually work, a few seconds at least. Maybe that's getting in the way? You'll have wait long enough from switching on to taking measurement.

PIR documentation I've seen says it needs 30-40 seconds to calibrate every time it gets power.

PIR modules intended for battery operation draw miniscule current (a few microamps) and do not need to be switched. Check the specifications on yours.

Thank you guys for your help, I checked my specs and saw that I really don't need to switch it off.