Back to Arduino Step By Step Course

Lesson 09: Using Switch and Push Buttons with Arduino

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

We learn how a switch turns ON and OFF a bulb. We learn how to use push button or switch with resistor and without resistor with Arduino. Using INPUT_PULLUP has been explaiend.

 * S01-09 Push Button 
 * Written by Ahmad Shamshiri
 Please watch video instruction here
 This code is available at
 with over 100 lectures Free On  YouTube Watch it here
Get the code for the course: 
 * Written by Ahmad Shamshiri for Robojax,
 * on Dec 24, 2018 in Ajax, Ontario, Canada

void setup() {
  pinMode(2, INPUT);// define pin 2 as input
  Serial.begin(9600);// initialize the serial monitor
                     // with 9600 baud
  Serial.println("Push button Test");
  pinMode(8, OUTPUT);


void loop() {
		//Robojax Step By Step Arduino Course
 int pushButtonValue = digitalRead(2);
 if(pushButtonValue == LOW)
  Serial.println("Button pushed");
  digitalWrite(8,HIGH);// turn ON the LED
  //Serial.println("Button NOT pushed");
  digitalWrite(8, LOW);// turn OFF the LED


The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

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

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.