stats online

Comment Faire Fonctionner Un Bouton Poussoir Arduino


Comment Faire Fonctionner Un Bouton Poussoir Arduino

Okay, imagine this. You're trying to build your ultimate robot assistant (who isn't these days, am I right?), and you need a simple way to tell it, "Hey, pay attention now!" A voice command system? Too complicated for now. Flailing your arms wildly? Fun, but not exactly reliable. The solution? The humble, reliable, utterly iconic pushbutton.

Yeah, I know, it sounds basic. But trust me, mastering the pushbutton with Arduino is like learning to ride a bike. Once you get it, you can build all sorts of amazing things. Think blinking lights, simple games, maybe even a slightly less-flailing-arms robot control system. Let's dive in!

Le Matériel Nécessaire (The Stuff You'll Need)

First, gather your gear. You'll need:

  • An Arduino board (Uno, Nano, Mega – whatever tickles your fancy).
  • A pushbutton (the smaller, the cuter, in my opinion... but any will do).
  • A resistor (usually 10k ohms – don't worry too much about the exact value, something around there will work).
  • Jumper wires (male-to-male, unless you have a female Arduino… which, come to think of it, would be a very advanced project).
  • A breadboard (because stabbing wires directly into your Arduino is generally frowned upon).

Easy peasy, right? If you don't have a breadboard, you can make it work, but I highly recommend one. They make life so much easier. Trust me on this.

Le Schéma de Câblage (The Wiring Diagram)

Alright, let's get connected. This is where things can get a little intimidating, but don't worry, we'll break it down. Essentially, we're creating a simple circuit. Think of it like a tiny electric river that's either flowing or blocked.

[TUTO] Arduino bouton poussoir, comment utiliser + code, câblage
[TUTO] Arduino bouton poussoir, comment utiliser + code, câblage
  1. Connect one leg of the pushbutton to a digital pin on your Arduino (let's use pin 2 for this example).
  2. Connect the other leg of the pushbutton to the 5V pin on your Arduino. Hold on! Before you freak out, read on...
  3. Now, here's the resistor part. Connect one end of the resistor to the same leg of the pushbutton connected to the digital pin (pin 2).
  4. Connect the other end of the resistor to GND (ground) on your Arduino.

Why the resistor, you ask? Great question! It's a pull-down resistor. It ensures that when the button isn't pressed, the digital pin is definitely LOW (0V). Without it, the pin could "float" and give you unpredictable readings. Think of it as a little helper, keeping things stable. Nobody likes a flaky pushbutton, am I right?

Le Code Arduino (The Code!)

Now for the fun part: the code! This is where we tell the Arduino what to do when the button is pressed.

Arduino - Bouton
Arduino - Bouton

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin (often built-in)

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);  // initialize the pushbutton pin as an input
  pinMode(ledPin, OUTPUT);      // initialize the LED pin as an output
  Serial.begin(9600);             //Start serial communication for debugging.
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) { //With INPUT_PULLUP, LOW means pressed.
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    Serial.println("Button Pressed!"); //Send message via serial for debugging
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    Serial.println("Button Not Pressed"); //Send message via serial for debugging
  }
  delay(10); //Debounce delay. Helps prevent false triggers.
}

Copy and paste that code into your Arduino IDE. Make sure the buttonPin and ledPin values match the pins you used on your board. If you didn't use the built-in LED, change the `ledPin` to another digital pin and connect an LED to that pin (with a resistor, of course!).

Important! Notice the `INPUT_PULLUP` in the `setup()` function. This activates the Arduino's internal pull-up resistor. We could use a separate pull-up resistor instead of a pull-down resistor, and then `HIGH` would mean "pressed", but this method is cleaner and saves you a component.

Utiliser un bouton poussoir avec l'Arduino - Idehack
Utiliser un bouton poussoir avec l'Arduino - Idehack

Téléchargez et Testez (Upload and Test)

Now, upload the code to your Arduino. Open the Serial Monitor (Tools -> Serial Monitor) to see what's happening. When you press the button, you should see "Button Pressed!" in the Serial Monitor, and the LED should light up. When you release the button, the LED should turn off, and you should see "Button Not Pressed". If it doesn't work, double-check your wiring and code!

Et voilà! You've successfully made a pushbutton work with your Arduino. From here, the possibilities are endless. You can use the button to control anything you can dream up. Go forth and create! And remember, if you get stuck, there are tons of resources online. Happy tinkering!

Utiliser un bouton poussoir avec Arduino facilement - YouTube Le bouton poussoir | arduino-passion Bouton poussoir: comment utiliser cet élément simple avec Arduino Formation Arduino #3 Les boutons poussoirs - YouTube Bouton arduino Comment utiliser Bouton poussoir avec Arduino - Moussasoft Explications du schéma électrique du bouton poussoir Arduino pour le [TUTO] Arduino bouton poussoir, comment utiliser + code, câblage TUTO ARDUINO #2 : FAIRE FONCTIONNER UN BOUTON / INTERRUPTEUR ! - YouTube Cablage Bouton Poussoir Arduino ARDUINO BOUTON POUSSOIR TUTORIEL [Résolu] [Arduino] Bouton poussoir - Je n'arrive pas à le faire

You might also like →