Arduino Automatic Shutoff

Hi,

I've purchased a "Pololu Pushbutton Power Switch LV" that has the ability to power off the arduino when a pin on it is brought high. In my current project I need to have the arduino automatically power off if the Paralax RFID reader connected to it does not detect a tag in 5 minutes. I'm a bit stumped on how to do this and I would be very grateful for any assistance available.

Thank you!

Connect the power of the RFID reader to an Arduino pin through a transistor (or relay). Your Sketch has complete control of the RFID reader's power.

Thanks, I have that working already as part of the tutorial posted on the playground, my question was more related to the syntax I would use to be able to set a particular pin to HIGH after 30 seconds of no tag being detected. The switch I have will cut off power to the whole device so that no power is wasted if a tag is not found after 30 seconds.

This is the code I have so far:

digitalWrite(txPin, LOW); // Activate the RFID reader on enable pin

if((val = RFID.read()) == 10) { // check for header

bytesread = 0;

while(bytesread<10) { // read 10 digit code
val = RFID.read();

if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}

code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}

if(bytesread == 10) { // If 10 digit read is complete
digitalWrite(txPin, HIGH); // deactivate RFID reader

Serial.print(“Checking tag…”); //Debug

if (checkTag(code) == true){
Serial.print(“Correct tag”);
blinkLED(2);
startIgnition();
ledpulse();
} else {
Serial.print(“Incorrect tag!!!”);
blinkLED(3);
}
}

bytesread = 0;
delay(2000); // wait for a second to read next tag
}

I need to surround this so that after 30 seconds of no tag being detected, It will exit the loop and set pin 10 to HIGH.

I hope this helps.

Thanks!

See the topic "simple countdown timer" and keep track of the time since an action happened in a similar manner.

I am also using a Pololu switch on my project. My project normally runs off a battery with the battery pack connected to the Pololu VIn connection and the Pololu's Vout connection is connected to the Arduino's Vin.

To power on the project I have a PB connected to the Pololu's PB connection closest to the edge of the Pololu circuit board and the other terminal of the pB is connected to Ground. This will make the PB only cause the project to power on. If you just use the small PB that comes with the Pololu, apparently it toggles between turning the project on and off.

To power down the project apply 5V to the OFF connection on the Pololu switch.

Note that what I described is when the Arduino is powered by the battery pack and not connected via USB to the PC. If you connect the Arduino to the PC via the USB cable it will start up and run and not shut down when you apply the 5V to the Pololu's OFF pin.

Be careful how you connect the wires. My first attempt trashed the microprocessor and I had to buy another. If you make the same mistakes as I did, make you you buy a processor with the bootloader already installed.

Hope this helps you.

Thanks you for the post.


Watch Tangled Online Free