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
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