Immediately set all pins to low when plugged in?

I have a project with a water pump attached and when plugging in the device, the pin usually goes high and the pump runs for a few seconds before the firmware kicks in with a low call in the setup. Is there a way to have the pins all low when plugging in either programmatically or via hardware?


By default, all pins are INPUT once user firmware runs. In some cases, you will need to add an external pull-down if your external device is a logic gate or MOSFET transistor that does not like having the floating input.

It also depends on which device and which pin. For example, on the Photon, pins D3, D5, and D7 will be pulled high with a pull-up at boot because these pins are also used for SWD/JTAG. Once Device OS boots, the pins go back to INPUT mode. See pinMode for more information.

I just tried this:

// define communication pins
const int8_t H_PIN = D2;                    // pin D2 will be used to toggle the humidifier on and off based on the humidity reading with a relay
const int8_t WH_PIN = D3;                   // pin D3 used to toggle the water heater on and off based on the water temperature with a relay
const int8_t AH_PIN = D4;                   // pin D4 will be used to toggle the air heater on and off based on the air temperature with a relay
const int8_t GL_PIN = D5;                   // use pin D5 for the grow light
const int8_t P_PIN = D7;                    // pin D7 will be used to toggle the h20 pump on and off based on the soil moisture reading with a TIP120 transistor

// Function to set all pins LOW
void setPinsLow() {
  int8_t pins[] = {H_PIN, WH_PIN, AH_PIN, GL_PIN, P_PIN};
  int8_t numPins = sizeof(pins) / sizeof(pins[0]);

  for (int8_t i = 0; i < numPins; i++) {
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], LOW);
// Set all pins low right away
// Retained memory is a type of non-volatile memory that can retain its value even when the device loses power, such as during a reset or power cycle.

This is for an Argon at present. This MOSTLY works. I am using a TIP120 to control the pump. When plugging in it comes on for a split second and then stops, instead of on for 3-10 seconds like previously.

I'm going to add a 10K pull down resistor to the to the D7 pump pin and see if that removes the plug in jitter completely.

I tried adding a 10K pull down resistor that connects D7 to GND on the 3.3V side of a logic level controller. This doesn't seem to fix the problem. Am I missing something?