Arduino Uno limit switch Interfacing and Programming

(Last Updated On: February 13, 2020)

limit switch


Arduino Uno limit switch Interfacing and Programming- This is a very detailed tutorial on how to use a limit switch with Arduino or Mega. This Tutorial explains everything from interfacing to the final testing. For the complete circuit explanation and programming watch video tutorial “Click Here”.

Components and tools used in this project can be purchased from Amazon, the components purchase links are given below:

Arduino Uno:
Mega 2560:
limit switch:  Best deal “pack”:
lm7805 Voltage Regulator:
330-ohm resistors pack:
female DC power jack socket:
470uf capacitors:
5×7 cm Vero board:
female headers:
connection wires:
Super Starter kit for Beginners:
Jumper Wires:
Bread Board:
12v Adaptor:
PCB plate:
Variable Supply:
Digital Multimeter:
Vero Board / Stripboard:
Soldering iron kit: “best” You guys should definitely purchase this:
Solder wire:
Wire Stripper:
PCB small portable drill machine:

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

limit switch

Limit switches are one of the most commonly used electronic components, the limit_switches are used in a situation where we need to define the limits. Like for example, the movement of the Pneumatic cylinder can be controlled using the limit switch as demonstrated in the video. Limit switches are most commonly used in industries. If you look at the construction of the limit switch you will find that it’s just like the ordinary push button but with a different design.

In the market, we have different types of switches like roller type limit switches, no matter which limit switch you use, the basic working principle is exactly the same. This limit switch can also be used with Mega, tinny, 8051 microcontrollers, pic microcontroller, plc, raspberry pi, etc.  for the limit switch interfacing watch this Video Tutorial “Click Here


Limit Switch Wiring with Arduino Uno:

Limit Switch
Limit Switch Wiring with Arduino

As you can see in the circuit diagram the limit switch wiring with the Arduino Uno or Mega is really simple. A Limit Switch is connected in series with a 10K ohm resistor. This is a Pull-Up resistor. In the normal condition, 5 Volt is connected with the Arduino, but when the limit switch is pressed the ground is connected with the Arduino’s pin number 2. In the same way, you can connect multiple limit switches.

Limit Switch Arduino Programming:

Watch Video Tutorial:

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

1 Comment

  1. Hi Fahad,

    What a great presentation! Thank you for the video. You make it seem so simple in writing the codes. Like flow of water.

    I’m Tomi from Thailand and is always fascinated with motors control. Recently, I decided to indulge in wetting my feet in the Arduino lake.

    Actually, I was on the verge of giving up as my code comprehension is so discouraging until I stumbled upon your site. Eureka…! I found a Guru.

    I took up a challenge to build a simple mechanism to further improve the productivity at my workplace. Since the, I have been hunting for appropriate sketches for more than 2 weeks but not very fruitful.

    Highly appreciate if you could shine some light into my undertaking.

    Please allow me to explain my intends.

    1) Press Button A , a carriage (mounted on a linear actuator) travels forward for 180mm (about 4250 steps) at a speed of 2-2.5sec/100mm (delayMicroseconds(800)). As a contingency, in case of over travelled, there will be an installation of a limit switch-Y just after the stop position.

    2) The carriage will only travel back to homing position one second after Button-B is being triggered.

    3) Returning or Homing speed is controlled by a potentiometer. Between delayMicroseconds (400 to 1500)

    4) Home position is determined by steps and a backup limit switch-Z.

    5) LOOP back to (1)


    NEMA 17 bipolar Stepper motor + Linear motion lead screw slide actuator
    Arduino UNO R3
    A4988 Driver,Hi Fahad,
    Momentary button switch ….2 pcs
    Limit switch …………………….2 pcs
    12V DC 5A power supply unit
    10K Potentiometer

    I shall be keeping my fingers crossed and hoping for your favourable reply.

    Thanking you in advance and looking forward to hearing from you soon

    I may be contacted at;-
    b) Whatsapp: +66 9913 15151

    Shukraan jazilaan lak

    Warmest Regards

    Tomi GOH

Leave a Reply