🛠 Bouton poussoir et moniteur série sur la Duemilanove (avec ses 0,5 s de silence)

Arduino Duemilanove — Board Fiche · debutant · Schéma : IMG-duemilanove-debutant-2-bouton-poussoir-serial-ftdi.svg — bouton poussoir entre la broche 2 et GND sur une Arduino Duemilanove, résistance interne pull-up annotée 20–50 kΩ, moniteur série affichant ETAT=1 / ETAT=0, puce FTDI et LED TX clignotante.

Objectives

Read a push button and display its state on the serial monitor — the famous DigitalReadSerial — while discovering two documented specifics of the Duemilanove: the 20 to 50 kΩ internal pull-ups activatable by software, and the auto-reset via the FTDI DTR line: each time the port is opened, the board resets and the ATmegaBOOT bootloader swallows the first bytes for ~0.5 seconds. Your automation scripts must keep this in mind.

Hardware

Complete code

// Bouton sur broche 2 -> GND, pull-up interne active
const byte BOUTON = 2;      // les interruptions externes sont aussi sur 2 et 3

void setup {
  pinMode(BOUTON, INPUT_PULLUP);   // pull-up interne 20-50 kOhm
  Serial.begin(9600);              // USB via FTDI FT232RL
  delay(1000);                     // laisser passer le bootloader (~0,5 s)
  Serial.println("Duemilanove prete");
}

void loop {
  // rappel : avec pull-up, bouton enfonce = LOW
  byte etat = digitalRead(BOUTON);
  Serial.println(etat == LOW ? "ETAT=0 (appuye)" : "ETAT=1 (libere)");
  delay(100);
}

Expected verification

The serial monitor (9600 baud) continuously displays "ETAT=1 (libere)" [STATE=1 (released)]; holding the button down changes the lines to "ETAT=0 (appuye)" [STATE=0 (pressed)]. Each time the monitor is opened/closed, the board blinks (DTR reset) and the line "Duemilanove prete" [Duemilanove ready] reappears: this is the normal behavior of the auto-reset, not a bug.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials