Skip to content
← Back to Electronics
⚡ electronics July 1, 2026 by Nitvi 📖 5 min read

Why Code is Important — Same Circuit, 5 Different Behaviours!

Same Arduino, same LED, same button, same breadboard — change only the code and watch the circuit behave completely differently. Full wiring guide + all 5 code examples to copy.

In my last video, I built a push button + LED circuit on Arduino. It worked perfectly! But then I started wondering…

🤔 Can the same circuit do completely different things… without changing a single wire?

The answer is YES — and the secret is code.

🦾
Components
LED, button, wires
= the body
🧠
Arduino
The board
= the brain
📝
Code
The program
= the instructions

Change the instructions → same body does different things. That's the power of programming!

🔌 What You Need

🔹
Arduino UNO
×1
📋
Breadboard
×1
💡
LED
×1
220Ω Resistor
×1
🔘
Push Button
×1
🧵
Jumper Wires
×5-6
🔌
USB Cable
×1
Same for ALL demos
No changes!

🧩 Wiring Guide

Connect everything once. Same wiring for all 5 demos.

1
LED → Resistor → Pin 13
LED long leg (+) → 220Ω resistor → Pin 13 on Arduino
LED short leg (−) → GND rail on breadboard
2
Push Button → Pin 2
Button left legPin 2 on Arduino
Button right legGND rail on breadboard
⚠️ INPUT_PULLUP = no external resistor needed
3
GND → Breadboard GND rail
Arduino GND pinGND rail (blue/black line) on breadboard
⚠️
Button tip: Push buttons have 4 legs. Legs on the same side are connected inside. Use legs on opposite sides (diagonally across) for your connections.
1

Basic Push Button

Behavior: LED glows only while button is pressed.
🎥 Nitvi says:

"This is the code from my last video."

Arduino Code
const int buttonPin = 2;
const int ledPin = 13;

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); }

void loop() { if (digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }

2

Toggle Switch

Behavior: Press once → LED ON. Press again → LED OFF.
🎥 Nitvi says:

"Same button... but now it works like a light switch!"

Arduino Code
const int buttonPin = 2;
const int ledPin = 13;

bool ledState = LOW; bool lastButton = HIGH;

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); }

void loop() { bool button = digitalRead(buttonPin);

if (button == LOW && lastButton == HIGH) { ledState = !ledState; digitalWrite(ledPin, ledState); delay(200); }

lastButton = button; }

3

Blink While Pressing

Behavior: Hold button → LED blinks. Release → OFF.
🎥 Nitvi says:

"Now it blinks instead!"

Arduino Code
const int buttonPin = 2;
const int ledPin = 13;

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); }

void loop() { if (digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); } else { digitalWrite(ledPin, LOW); } }

4

SOS Signal

Behavior: Press button → LED flashes SOS in Morse code (... ――― ――― ...)
🎥 Nitvi says:

"Wow! It can even send an SOS message!"

Arduino Code
const int buttonPin = 2;
const int ledPin = 13;

void dot() { digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); }

void dash() { digitalWrite(ledPin, HIGH); delay(600); digitalWrite(ledPin, LOW); delay(200); }

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); }

void loop() { if (digitalRead(buttonPin) == LOW) { dot(); dot(); dot(); dash(); dash(); dash(); dot(); dot(); dot(); delay(1000); } }

5

Random Blink Speed

Behavior: Every button press changes the blink speed randomly!
🎥 Nitvi says:

"Every press gives me a new blink speed!"

Arduino Code
const int buttonPin = 2;
const int ledPin = 13;

int speed = 200; bool lastButton = HIGH;

void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); randomSeed(analogRead(A0)); }

void loop() { bool button = digitalRead(buttonPin);

if (button == LOW && lastButton == HIGH) { speed = random(100, 700); delay(200); }

lastButton = button;

digitalWrite(ledPin, HIGH); delay(speed);

digitalWrite(ledPin, LOW); delay(speed); }

</ div>

🔍 What Changed Across All 5 Demos?

Feature Demo 1 Demo 2 Demo 3 Demo 4 Demo 5
Circuit Same Same Same Same Same
LED behavior On while pressed Toggle on/off Blink while held SOS signal Random blink
What's new in code? + ledState
+ lastButton
+ delay(200)
inside if
+ dot()
+ dash()
+ random()
+ analogRead

The only thing that changed: CODE. 🎯

✅ Key Takeaways

🦾
Electronics = Hardware
The physical parts — LED, button, wires, Arduino board
🧠
Arduino = Brain
It reads inputs and controls outputs
📝
Code = Instructions
Tells the Arduino brain what to do
Same Hardware + Different Code = Different Behaviour
5 demos, 5 behaviours, 0 wire changes!

🚀 What's Next?

Today I learned that changing the code can completely change how a circuit behaves. But now I have another question…

🤔 How does Arduino actually understand the code we write?

How does my program turn into actions like blinking an LED? Let's discover that in the next video!

If you're learning Arduino, electronics, coding, or STEM just like me, join me on this exciting journey. 👍 Like, 💬 Comment, 🔔 Subscribe on Nitvi Talks!

Share this post: 𝕏 Share f Share