I'm working on a project that use J5, so is using the standard firmata, this project is using an opto 4 channel relay, when the board is booting the pins state are set to low, so as soon as I power the board my relay goes to a close state and make my motor run... this is a wrong behaviour for my purpose. How can I avoid that? By googleing around I stumble acros this:

A possible solution

but I can't uderstand if this is what I'm looking for.. plus I need only the PIN 7 to be set high on boot, any help please?


4 Channel 5V Relay Module

enter image description here

  • What makes you believe it boots with all pins LOW? They should be high impedance. Could you share the schematic of how you connect the Arduino to the optocoupler, to the the relays and to the motors? Commented May 22, 2017 at 11:19
  • @EdgarBonet added schematics in the question ;)
    – FabioEnne
    Commented May 22, 2017 at 12:45
  • 3
    This is not a schematic. And it only shows how you are powering your relay module, not how you are driving it, nor how it works internally (reference please). Commented May 22, 2017 at 12:47
  • @EdgarBonet added the references link to the constructor wiki page
    – FabioEnne
    Commented May 22, 2017 at 12:51
  • @EdgarBonet I forgot in the schema above to connect the pin 7 to the ch1, sorry
    – FabioEnne
    Commented May 22, 2017 at 12:52

2 Answers 2


It would seem you are right. If I understood the source correctly, Firmata initializes all digital pins as OUTPUT LOW. Hard to believe, as this seems like a silly thing to do... My understanding is that:

  1. setup() calls systemResetCallback() in order to set the initial pin configuration (line 779)
  2. systemResetCallback() loops over all pins and calls setPinModeCallback(i, OUTPUT) for every pin i that is not an analog pin (line 732)
  3. setPinModeCallback() calls pinMode() to set the pin to OUTPUT (line 325).

If my understanding is correct, then the simplest solution would seem to patch systemResetCallback() and replace OUTPUT by INPUT on line 732.

  • yep, my same conclusion but I think that setting all the pins to INPUT will cause the same but opposite problem for other components.. best would be set the desired pin number
    – FabioEnne
    Commented May 22, 2017 at 18:26
  • 3
    Irrespective of how you patch Firmata, the pins will be set to INPUT when you power the Arduino, and during the time the bootloader runs. You should manage for you circuit to accommodate that initial state. A pullup or pulldown resistor may be suitable for the pins driving those other components. Commented May 22, 2017 at 18:48
  • how does it take to boot less than a second would be acceptable
    – FabioEnne
    Commented May 22, 2017 at 19:31

Just put digitalWrite(anyPin,HIGH) in void setup() this will make that specific pin HIGH to reset. It works for me.

void setup()

  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
  Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
  Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
  Firmata.attach(SET_PIN_MODE, setPinModeCallback);
  Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback);
  Firmata.attach(START_SYSEX, sysexCallback);
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  // to use a port other than Serial, such as Serial1 on an Arduino Leonardo or Mega,
  // Call begin(baud) on the alternate serial port and pass it to Firmata to begin like this:
  // Serial1.begin(57600);
  // Firmata.begin(Serial1);
  // However do not do this if you are using SERIAL_MESSAGE

  while (!Serial) {
    ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101

  systemResetCallback();  // reset to default config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.