Skip to main content
5 of 5
comment regarding EDIT section removed as not relevant anymore
Remi
  • 159
  • 1
  • 10

How to reset an arduino while being able to know which button has been pressed?

Context

I keep the board in sleep mode and want to wake it with different buttons. I need to know which button has been pushed on boot.

In the following schematic, SW-R is actually used to reset the board.

If I hold SW-D5 or SW-D6 while pushing SW-R, the code can detect which button I pushed.

Problem

I don't want to have to push 2 buttons at the same time and, being new to electronic, I don't know how to wires things up so it reset and set a pin to HIGH simultaneously.

Question

How can I reset the board and trigger a HIGH on an IO corresponding to a button while it boot?

Considering the HIGH only need to be hold for less than a second, can it be simply achieved with capacitors and/or transistors? If so, how? Or any other suggestion?

schematic

simulate this circuit – Schematic created using CircuitLab

The actual code example only contain 1 button but I'll have many.

#include <Spi.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>

int buttonPin = D5;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(BUILTIN_LED, OUTPUT);

  int buttonValueAtBoot = digitalRead(buttonPin);
  Serial.begin(115200);
  Serial.println();

  if (buttonValueAtBoot == HIGH) {
    // I want to trigger this code pushing only 1 button
    // should also work with many buttons
    Serial.println("button was pressed");
  }

  digitalWrite(BUILTIN_LED, HIGH);
}

void loop() {
  delay(5000);
  ESP.deepSleep(0);
}
Remi
  • 159
  • 1
  • 10