Why should we use resistor with push button with Arduino? 1/2

Project Video
Project Details

This is Arduino Sketch for Tutorial video explaining why resistor is needed to be used with push button
with Arduino.

We are using resistor with push button either from Arduino pin to the ground as shown in this picture.

See Why should we use resistor with push button with Arduino? 1/2

Or using resistor from Arduino pin to VCC (5V) as shown in this picture.

Project Code


/*
 * This is Arduino Sketch for Tutorial video 
 * explaining why resistor is needed to be used with push button
 * with Arduino.
 * 
 * Written by Ahmad Shamshiri on July 17, 2018 at 23:11 in Ajax, Ontario, Canada
 * For Robojax.com
 * Watch instruction video for this code: https://youtu.be/TTqoKcpIWkQ
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
 */

void setup() {
  // Robojax.com push button tutorial
  pinMode(3,INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Robojax Push button Tutorial");
  

}

void loop() {
  // Robojax.com push button tutorial
  int pushButton = digitalRead(3);
  if(pushButton == LOW)
  {
    Serial.println("Pin 3 LOW");
  }else{
    Serial.println("Pin 3 HIGH");
  }

delay(500);
}

If you found this Arduino course helpful, please support me so I can continue creating content like this. support me via PayPal