Arduino startup behaviour


I’ve been trying to find out what Arduino digital pins do on startup, as soon as the device is turned on. I’m writing a sketch that will switching on or resetting a computer, and I want it to be safe if the arduino loses and regains power.

Is it well defined what the behaviour of pins are from startup until setup() runs? Is there a risk they will move between high and low states?


If anything flashes threw the digital pins on start up it will be so quick it won’t effect anything.

Your sentence there is a bit broken. I assume your wanting to use the arduino to power on or reset a PC? To do this you don’t want the power and reset to be directly wired to the Arduino. I suggest you have the PC connect to a pair of relays and have the Arduino actuate the relays. One that actuates on 5V. The you can digitalWrite HIGH to a pin that connects to the relay. The Relay will then actuate and turn on the PC. Here is a slightly modified version of the button example.

 // constants won't change. They're used here to 
 // set pin numbers:
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int ledPin =  12;      // the number of the relay pin

 // variables will change:
 int buttonState = 0;         // variable for reading the pushbutton status

 void setup() {
   // initialize the relay pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize the pushbutton pin as an input:
   pinMode(buttonPin, INPUT);     

 void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     
     // power on to relay:    
     digitalWrite(ledPin, HIGH);  
     delay(500); // allows power to the relay to stay on long enough 
                       // for the PC to power on. this number may need to 
                       // be adjusted
   else {
     // send no power to the relay
     digitalWrite(ledPin, LOW); 

Of course the button will be replaced with whatever means you plan to use to tell the board to actuate the relay.

I recommend pulling the pins either high or low with external resistors if you need to be sure.

All digitial pins become inputs on reset. That means “floating” from a electrical point of view; if their state is important they will need external pullup or pulldown resistors.

Thanks all. And yes sorry my sentence was poor. I meant to say the sketch will be powering on or resetting my pc.

It’ll be isolated from the PC - I’m using reed relays in parallel with the soft-on and reset switches, and I’ll be using an opto-isolator to see if it’s already powered on.

I guess with my load being a relay (rather than something that detects signal) the floating nature is less significant, but I’ll use 20K pull-down resistors - that way I hope the only possible way for the relays to fire would be from me setting pinmode to output and level to high.