bouton-poussoir.ino

Arduino UNO R4 WiFi · File : bouton-poussoir.ino · Language : Arduino · Use case : Allumer une LED sur appui bouton avec anti-rebond

The classic button/LED circuit, identical to historic Arduinos: the R4 core keeps the same primitives (INPUT_PULLUP, digitalRead). The base of any human interface on the board.

Hardware

An Arduino UNO R4 WiFi (Renesas RA4M1 @ 14 MHz + companion ESP32-S3 Wi-Fi/BLE, 12x8 LED matrix, RGB LED) powered by USB or 6-24 V. 1 push button + 1 LED + 330 Ω resistor.

Wiring

Button between D2 and GND (internal pull-up). LED + 330 Ω between D13 and GND. Pins are 5 V tolerant (5 V compatible logic).

How it works

The reading is validated after 30 ms of stability; the press (LOW with pull-up) lights the LED and prints to the serial monitor.

Running it

Arduino IDE 2.x with the « Arduino UNO R4 Boards » core, « Arduino UNO R4 WiFi » board, serial port then Upload. The ESP32-S3 coprocessor updates separately if the IDE asks.

Variants

Press counter shown on the matrix (R4 WiFi), or double-click with interval measurement between edges.

bouton-poussoir.ino

// Bouton sur D2 (vers GND) + LED sur D13, anti-rebond 30 ms.
const int BOUTON = 2;
const int LED = 13;

bool stable = HIGH, precedent = HIGH;
unsigned long dernierBord = 0;

void setup() {
  pinMode(BOUTON, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  bool lecture = digitalRead(BOUTON);
  unsigned long maintenant = millis();

  if (lecture != precedent) dernierBord = maintenant;
  if (maintenant - dernierBord >= 30 && lecture != stable) {
    stable = lecture;
    digitalWrite(LED, stable == LOW);   // appui -> LED
    Serial.println(stable == LOW ? F("appui") : F("relache"));
  }
  precedent = lecture;

  // Le RA4M1 est rapide (14 MHz) : le polling ne coute rien.
}

← Back to the board