PIR motion sensor to activate relay shield to turn on electronics on robot

Hello,
Been working on my wheelchair robot and became interested in a relay type setup to power on the electronic system on my robot... some code below.
A bit of info on my bot:
I have an Arduino Uno controlling the motor driver for the main motors. Arduino Mega2560 for all the sensors (PING, PIR, etc...). And a Mini ITX PC motherboard as a go-between the 2 Arduinos, as well as for voice recognition (which I have somewhat setup).

I have two motorcycle style 12VDC, 32Ah batteries in series (24VDC, 32Ah) solely for driving the main motors. For all the electronics, I have a 12VDC, 12Ah battery.

I recently bought the relay module from Seeed Studios:

And decided to play around a bit with it.
I have a 3rd Arduino (Uno) that I was thinking of running on a 9V battery along with the relay shield and one PIR motion sensor.
So, setting it up for motion (excluding false highs on the PIR) the relay would turn on the robots electrical system and then turn on the PC motherboard. Maybe do a greeting from the VR on the PC.
Also, if after 15min. (900,000mS) of no activity/motion, it will shut down the PC, the robots electrical system and then wait again for motion.
I know the power switch header pins on an ATX style M/B act like a momentary switch (or shorting of the two pins).

I hope I made some sense :confused:

One dilemma I have is how exactly, or the better way to short the two power switch pins on the PC M/B (with the Arduino?) I know it's like a momentary switch but just want to make sure.

Here's some code I put together:

// Turning on electrical systems on my robot via motion PIR sensor and Seeed relay module.
// Give a greeting, hello, etc.. (speech), which I have setup already on my mini ITX PC M/B.
// Then, if there is no motion detected after a certain time (15 minutes),
// shut down PC M/B followed by the robots electrical system.
// The arduino in this setup will be powered by a 9V battery.

// Some of the code used (PIR), I believe was from Kristian Gohlke
// and the Seeed relay demo code.


const int relayPin = 4;
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 900000;  // 15min. pause or wait  

boolean lockLow = true;
boolean takeLowTime;  

const int pirPin = 9;    //the digital pin connected to the PIR sensor's output


void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(pirPin, LOW);

}

void loop(){

  if(digitalRead(pirPin) == HIGH){
    if(lockLow){  
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow = false;            
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec"); 
      delay(50);
    }      
    if(lockLow){  
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow = false;            
    }         
    takeLowTime = true;

    digitalWrite(relayPin,HIGH);  // Turn on power to electrical system with relay.
    // Wondering here how to turn on PC M/B (momentary sw.)...using Arduino?
  }



  if(digitalRead(pirPin) == LOW){       

    if(takeLowTime){
      lowIn = millis();          //save the time of the transition from high to LOW
      takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
    //if the sensor is low for more than the given pause, 
    //we assume that no more motion is going to happen
    if(!lockLow && millis() - lowIn > pause){  
      //makes sure this block of code is only executed again after 
      //a new motion sequence has been detected
      lockLow = true;                        
      Serial.print("motion ended at ");      //output
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);
    }

    // Here turn PC OFF first... 

    // then turn electrical system OFF with relay.
    digitalWrite(relayPin,LOW);
  }
}

t

One dilemma I have is how exactly, or the better way to short the two power switch pins on the PC M/B (with the Arduino?) I know it's like a momentary switch but just want to make sure.

Hi, to get the ATX supply to turn on you need to connect that green wire to one of the black ground wires. You could do with this with a relay since you have that, or probably a MOSFET would do the same trick. That seems pretty straightforward, and unlike the paperclip hacks you don't need to hold that relay after it's triggered - the ATX supply will keep running without that power line being grounded, though some will need a load to keep going.

In your case it's not clear, but were you intending to signal the OS running on the PC board to get it to shut down ? I don't believe triggering the same power switch will reverse the process, at least on the one I have here for a benchtop supply pressing that ON switch when it's on just keeps it on (ie it's ignored). Any OS will know how to shut itself down, and that's probably a neater way since it will clean up processes and return to a safe state before removing the power.

Cheers ! Geoff

Just did a little probing with my multimeter on the 2 power switch pins on the motherboard header.

One pin is 0V (GND).
The other pin is 3.40VDC (these values are when computer is OFF or ON).
The actual power switch is a momentary switch. When you press this switch (momentarily) it grounds out the pin with the 3.40VDC (and turns ON or OFF).

Was wondering if I could use 2 digital pins on the Arduino set to OUTPUT. Then to turn the PC ON or OFF, set both pins to LOW.
I was wondering (the digital pins will always be output) how the header pin on the MB with 3.40VDC would affect the Arduino.
I'm guessing I could put a current limiting resistor of about 470 Ohms or 1K Ohms on that line (or a diode to prevent the voltage from getting to the Arduino).?

t

strykeroz:

One dilemma I have is how exactly, or the better way to short the two power switch pins on the PC M/B (with the Arduino?) I know it's like a momentary switch but just want to make sure.

Hi, to get the ATX supply to turn on you need to connect that green wire to one of the black ground wires. You could do with this with a relay since you have that, or probably a MOSFET would do the same trick. That seems pretty straightforward, and unlike the paperclip hacks you don't need to hold that relay after it's triggered - the ATX supply will keep running without that power line being grounded, though some will need a load to keep going.

In your case it's not clear, but were you intending to signal the OS running on the PC board to get it to shut down ? I don't believe triggering the same power switch will reverse the process, at least on the one I have here for a benchtop supply pressing that ON switch when it's on just keeps it on (ie it's ignored). Any OS will know how to shut itself down, and that's probably a neater way since it will clean up processes and return to a safe state before removing the power.

Cheers ! Geoff

Hey Geoff,
thanks for the reply...I added to the post at the same time hehe.
In my case, with the computer OFF and you press the power button, computer turns ON.
With the computer ON and you momentarily press the power button it powers OFF (like going to start/shutdown, etc..) Think it's called a soft OFF (can be configured in the BIOS).

t

Hi,

If the method you're proposing were workable, you'd only need one pin, with that wired to the green of the ATX. Setting that pin LOW will be the same as connecting your green wire to GND, as you'll have the GND of the Arduino and the ATX connected to each other.

However, while you have your Uno pin HIGH, and it will be high all the time the PC is running or off, it will be pushing 5V out to that ATX 3V pin. I don't know enough to suggest if that's entirely a good idea or not, but the relay idea (since you have the relay shield already) would keep everything electrically isolated - just connect one side to green and one to black so the relay can join the two momentarily when you need.

Geoff

strykeroz:
Hi,

If the method you're proposing were workable, you'd only need one pin, with that wired to the green of the ATX. Setting that pin LOW will be the same as connecting your green wire to GND, as you'll have the GND of the Arduino and the ATX connected to each other.

However, while you have your Uno pin HIGH, and it will be high all the time the PC is running or off, it will be pushing 5V out to that ATX 3V pin. I don't know enough to suggest if that's entirely a good idea or not, but the relay idea (since you have the relay shield already) would keep everything electrically isolated - just connect one side to green and one to black so the relay can join the two momentarily when you need.

Geoff

Yeah, I though about using one pin... I understand what you're saying about when it's HIGH.
No problem, I'll use the relay shield (I have 4 available relays on the shield), so I'll just use a second relay to turn the computer ON/OFF.

Thanks a lot Geoff! :slight_smile:

t