Monday, November 30, 2026

Arduino Button Reads Randomly? Fix It with INPUT_PULLUP in 4 Steps

Arduino Button Wiring with INPUT_PULLUP – MY CREATIVE ENGINEERING

Does your Arduino button seem to read randomly, switching between pressed and released even when nobody is touching it? The cause is usually a floating input pin. The fix is simple: use the Arduino's built-in pull-up resistor, so no extra resistor is needed. Follow the 4 steps below.

What Is a Floating Input?

When a button is wired to a digital pin and nothing defines the pin's level while the button is released, the pin "floats". It picks up electrical noise and returns random readings. A pull-up resistor holds the pin at HIGH until the button connects it to GND.

Step 1: Wire It

Connect one leg of the push button to a digital pin (this example uses Pin 2) and connect the opposite leg to GND.

Step 2: Enable the Internal Pull-Up

In setup(), set the pin mode with pinMode(2, INPUT_PULLUP);. This enables the internal pull-up resistor, so no external resistor is needed for this wiring.

Step 3: Read the Pin

Read the pin with digitalRead(2). With INPUT_PULLUP the logic is inverted: the pin reads LOW when the button is pressed and HIGH when it is released.

Step 4: Debounce the Button

Mechanical contacts bounce, which can cause several readings from a single press. Add a short delay or filter the reading in your code.

Wire It the Right Way

  • Correct: button between the pin and GND, with INPUT_PULLUP set in pinMode().
  • Wrong: plain INPUT with nothing attached. The pin floats and gives random readings.

Quick Reference

ItemValue
Button leg 1Digital pin 2
Button leg 2GND
ModeINPUT_PULLUP
PressedLOW
ReleasedHIGH
BounceAdd a short delay

Safety Precautions

  • Disconnect power before wiring.
  • Never connect a button directly between 5 V and GND.
  • Use only a small push button.
  • Check the pin number in your code.
  • Keep wires tidy and short.
  • Do not exceed the pin ratings.

Remember

Wire the button to GND, use INPUT_PULLUP, and read LOW as pressed. Code smart, wire safe!

Follow MY CREATIVE ENGINEERING for more practical electronics and engineering tips.

Ohm's Law Made Easy – How to Find V, I or R in 4 Steps

Ohm's Law Made Easy – MY CREATIVE ENGINEERING

Struggling with Ohm's Law? Whether you are wiring an LED, sizing a resistor or checking a power supply, Ohm's Law is the first tool every electronics and electrical technician reaches for. It links three values: voltage (V), current (I) and resistance (R). Know any two and you can always find the third. Here is the simple 4-step method used on the MY CREATIVE ENGINEERING workbench.

What is Ohm's Law?

Ohm's Law states that the voltage across a conductor equals the current through it multiplied by its resistance: V = I × R. Voltage is measured in volts (V), current in amperes (A) and resistance in ohms (Ω).

Step 1: Know two values

Write down the two values you already know: voltage (V), current (I) or resistance (R). Identify the one value you need to find.

Step 2: Pick the formula

  • To find voltage: V = I × R
  • To find current: I = V ÷ R
  • To find resistance: R = V ÷ I

A handy memory aid is the Ohm's Law triangle: place V at the top and I and R at the bottom. Cover the value you want and the triangle shows the formula.

Step 3: Calculate

Put your numbers into the formula. Example: a 12 V supply across a 4 Ω load gives I = 12 V ÷ 4 Ω = 3 A.

Step 4: Check units

Convert milliamps (mA) to amps and kilo-ohms (kΩ) to ohms before you calculate. Example: 5 V across a 1 kΩ resistor (1000 Ω) gives I = 5 V ÷ 1000 Ω = 0.005 A = 5 mA.

Calculate It Right

  • Correct: convert mA and kΩ first, and use V, A and Ω together.
  • Wrong: mixing kΩ with amperes gives an answer that is wrong by 1000×.

Quick Reference

VoltageV = I × R
CurrentI = V ÷ R
ResistanceR = V ÷ I
PowerP = V × I

Safety Precautions

  • Switch off power before wiring.
  • Check the power rating of every resistor (P = V × I) so it does not overheat.
  • Stay within the voltage rating of your components.
  • Double-check the maths before powering up.

Remember: know any two of V, I and R and you can find the third. Calculate smart, work safe!

Follow MY CREATIVE ENGINEERING for more practical electronics and engineering tips, from Kuala Terengganu, Malaysia.