3-Hour Workshop · Hands-On Learning

Arduino Uno
Beginner Workshop

From your first LED blink to a sensor-controlled servo gate — 7 sketches with fully commented code, step-by-step circuit builds, and progressive challenges.

7
Code Sketches
3h
Workshop Duration
6
Sessions
Things to Build
Workshop Overview

This workshop takes you from zero Arduino experience to building a real sensor-controlled mechanical system. Each session builds on the last, introducing new concepts through hands-on circuit construction.

# Start Session Duration Key Concepts
00:00Introduction & Setup15 minIDE, board anatomy, first upload
10:15Basic LED Blink20 minpinMode, digitalWrite, delay
20:35LED Pulse & Multi-Blink25 minPWM, analogWrite, millis()
31:00Single Traffic Light30 minSequencing, helper functions
41:30Two-Way Traffic Lights45 minCoordination, safety logic
52:15Ultrasonic Sensor + Servo Gate45 minSensors, Servo lib, map(), constrain()
3:00Wrap-Up & ChallengesopenExtensions & Q&A
Equipment Required (Per Student / Pair)
ComponentSpecQtyPurpose
Arduino UnoRev 3 or compatible clone1Microcontroller brain
USB CableType-A to Type-B1Programming & power
BreadboardFull or half size (830/400 tie)1Prototype circuits without soldering
Jumper WiresMale-to-Male mixed colours20+All circuit connections
LEDsRed × 2, Amber × 2, Green × 26Traffic light outputs
LEDsAny colour (status/alert)2Sensor & gate indicators
Resistors220Ω (Red-Red-Brown)8Current limiting for LEDs
HC-SR04 SensorUltrasonic distance module1Session 5 — distance input
Servo MotorSG90 or MG90S (5V hobby)1Session 5 — mechanical output
Laptop + Arduino IDEv1.8+ or v2.x1Code editor & uploader
📥 Download the Arduino IDE from arduino.cc/en/software and install it before the workshop. Once installed, connect your Arduino Uno, then go to Tools → Board → Arduino Uno and select your COM port under Tools → Port.
Session
0
Introduction & Arduino Setup
Board anatomy, IDE tour, and uploading your first sketch
15 min
What is Arduino?

Arduino is an open-source electronics platform that combines a simple microcontroller board with easy-to-use software. The Arduino Uno uses an ATmega328P processor running at 16 MHz with 32KB of flash memory.

Key Parts of the Arduino Uno
PartDescription
USB PortConnects to laptop for programming and provides 5V power
Digital Pins 0–13Can be INPUT or OUTPUT; pins marked ~ support PWM
Analogue Pins A0–A5Read voltages from 0V to 5V as numbers 0–1023
5V & 3.3V PinsRegulated power output for sensors and components
GND PinsGround (negative/return) — connect all component GNDs here
RESET ButtonRestarts your sketch from the beginning
PWM Pins (~)Pins 3, 5, 6, 9, 10, 11 — support analogWrite()
Structure of Every Arduino Sketch

Every Arduino program (called a sketch) must have exactly these two functions:

structure.ino
Uploading Your First Sketch
1

Connect Arduino to your laptop via USB cable

2

Open Arduino IDE → Tools → Board → Arduino Uno

3

Select your port: Tools → Port → COM3 (Windows) or /dev/ttyUSB0 (Linux/Mac)

4

Click the ✓ Verify button to compile your code — fix any errors shown

5

Click the → Upload arrow — the TX/RX LEDs will flash as code transfers

6

"Done uploading" = success! Your sketch is now running on the board

Session
1
Basic LED Blink
The "Hello World" of electronics
20 min
Circuit Build
ComponentValueQtyPurpose
LEDAny colour1Our output — lights up!
Resistor220Ω (Red-Red-Brown)1Limits current to protect LED & pin
Jumper wiresMale-to-Male2Pin 13 to circuit; GND to circuit
  • Arduino Pin 13 → 220Ω resistor (one leg)
  • Resistor (other leg) → LED long leg (anode +)
  • LED short leg (cathode −) → Arduino GND pin
LEDs are polarised — they only work in one direction. The longer leg is the positive anode (+). If your LED doesn't light up, try flipping it around. The 220Ω resistor is essential — without it, the LED and pin can be damaged by excess current (Ohm's Law: I = (5V − 2V) / 220Ω ≈ 14mA).
Sketch 1 — Basic LED Blink
pinMode() digitalWrite() delay() OUTPUT HIGH / LOW
sketch1_blink.ino
What to Expect
  • The LED on Pin 13 blinks once per second (on 1s, off 1s)
  • The built-in 'L' LED on the board also blinks — it shares Pin 13
  • Open Tools → Serial Monitor (Ctrl+Shift+M) to see LED ON / LED OFF messages
Try These Modifications
1

Change delay(1000) to delay(500) — twice as fast

2

Try delay(100) — it starts to look like a flicker, not a blink. Why?

3

Make the ON time and OFF time different (e.g. 200ms on, 800ms off)

4

Add a second LED on Pin 12 with its own resistor — make it blink at a different rate

Session
2
LED Pulse & Multi-Blink
PWM fading and non-blocking timing with millis()
25 min
What is PWM?

Most Arduino pins are strictly digital — fully ON (5V) or fully OFF (0V). Pulse Width Modulation (PWM) creates the illusion of in-between brightness levels by rapidly switching the pin on and off. Your eye blurs the fast switching into a perceived brightness.

PWM Brightness Levels
analogWrite(9, 0) — 0%LED OFF
analogWrite(9, 64) — 25%Dim
analogWrite(9, 127) — 50%Half bright
analogWrite(9, 191) — 75%Fairly bright
analogWrite(9, 255) — 100%Full brightness
📌 PWM pins on Arduino Uno are marked with ~: pins 3, 5, 6, 9, 10, and 11 only. Calling analogWrite() on a non-PWM pin won't work as expected.
Sketch 2a — LED Pulse (Breathing Effect)
analogWrite() for loop PWM ~ pins 0–255 range
sketch2a_pulse.ino
Sketch 2b — Multiple LEDs, Non-Blocking Timing

This introduces millis() — the professional way to handle multiple simultaneous timings without freezing the Arduino.

💡 Key insight: delay() freezes everything — the Arduino can't read sensors, check buttons, or do anything else while it waits. millis() asks "has enough time passed?" without stopping. This is how real-world Arduino projects handle multiple concurrent tasks.
sketch2b_multi_blink.ino
Session
3
Single Traffic Light
Sequencing multiple LEDs with functions
30 min
Circuit
ComponentValueQtyPin
Red LED5mm Red1Pin 4
Amber LED5mm Yellow1Pin 5
Green LED5mm Green1Pin 6
Resistors220Ω each3One per LED
⚠️ All three LED cathodes (short legs) connect to the same GND rail on the breadboard. Connect that rail to any Arduino GND pin with one wire.
UK Traffic Light Sequence
Phase
Red
Amber
Green
RED (5s)
ON
off
off
RED + AMBER (2s)
ON
ON
off
GREEN (5s)
off
off
ON
AMBER (2s)
off
ON
off
Sketch 3 — Single Traffic Light
custom functions const int sequencing UK sequence
sketch3_traffic_light.ino
Session
4
Two-Way Traffic Light System
Coordinating two junctions with safety logic
45 min

Two independent sets of traffic lights that coordinate — when Road A is green, Road B is red. They are never both green simultaneously.

Pin Assignments
RoadColourArduino PinResistor
Road A RedPin 2220Ω
Road A AmberPin 3220Ω
Road A GreenPin 4220Ω
Road B RedPin 7220Ω
Road B AmberPin 8220Ω
Road B GreenPin 9220Ω
🚨 Safety rule: The sketch includes a brief all-red period (500ms) between every green phase change. Both roads are on RED during this gap, ensuring it is physically impossible for both to be green simultaneously. This models how real traffic signal controllers work.
Sketch 4 — Two-Way Traffic Lights
coordinated outputs helper functions safety gap all-red phase
sketch4_two_way_traffic.ino
💡 Extension challenge: Add a pedestrian button on Pin 10 (with INPUT_PULLUP). When pressed, complete the current green phase, then insert a special phase: both vehicle sets go RED, and a pedestrian green LED (Pin 11) lights for 5 seconds. This is exactly how real pelican crossings work.
Session
5
Ultrasonic Sensor + Servo Gate
The grand finale — sensors meet mechanical control
45 min
Part A: HC-SR04 Ultrasonic Sensor

The HC-SR04 measures distance using the same principle as a bat's echolocation. It fires an inaudible 40kHz ultrasound burst and times how long the echo takes to return. Distance = (pulse duration × speed of sound) ÷ 2.

HC-SR04 PinConnect toDirection
VCCArduino 5V pinPower in
GNDArduino GND pinGround
TRIGArduino Pin 11OUT — we send pulses
ECHOArduino Pin 12IN — we listen for echo
Sketch 5 — Ultrasonic Distance Sensor
pulseIn() delayMicroseconds() sensor reading distance formula
sketch5_ultrasonic.ino
Part B: Servo Motor

A servo contains a DC motor, gearbox, and position sensor — all in one small package. You control the exact angle (0°–180°) with a simple command. The Arduino Servo library handles all the PWM timing automatically.

  • Brown or Black wire → Arduino GND
  • Red wire → Arduino 5V
  • Orange or Yellow (signal) wire → Arduino Pin 9
⚠️ Servos under load can draw 200–500mA. If your Arduino resets when the servo moves, power the servo from an external 5V supply, sharing GND with the Arduino. The SG90 micro servo is fine powered directly from the Uno for this workshop.
Sketch 6 — Servo Sweep
Servo library servo.attach() servo.write() #include
sketch6_servo_sweep.ino
Sketch 7 — Grand Finale: Sensor-Controlled Gate

This combines everything. The HC-SR04 measures distance and the servo opens a gate proportionally — more open the closer the object gets. Two LEDs show gate status.

Full Wiring
  • HC-SR04: VCC→5V, GND→GND, TRIG→Pin 11, ECHO→Pin 12
  • Servo: Red→5V, Brown/Black→GND, Signal→Pin 9
  • Red LED: Pin 5 → 220Ω → Red LED → GND (gate closed indicator)
  • Green LED: Pin 6 → 220Ω → Green LED → GND (gate open indicator)
map() constrain() proportional control sensor + actuator state tracking
sketch7_ultrasonic_gate.ino
Challenge Exercises & Extensions

Finished early? These challenges deepen your understanding, roughly ordered by difficulty.

Beginner

SOS Blinker

Blink an SOS pattern using short (200ms) and long (600ms) flashes: · · · — — — · · ·

Beginner

Speed Control Button

Make the traffic lights change timing with a button — short press = fast mode, long press = normal

Beginner

Amber Buzzer

Add a passive buzzer on Pin 7 that beeps during the AMBER phase of the traffic light sequence

Beginner

Distance Bar

Display ultrasonic distance as 5 LEDs that light up as an object gets progressively closer

Intermediate

Pedestrian Crossing

Add a button to the two-way lights for a pedestrian crossing mode — vehicles stop, pedestrian green LED lights for 5 seconds

Intermediate

Servo Speedometer

Map a potentiometer (0–1023) to servo angle (0°–180°) to create an analogue gauge needle

Intermediate

Smart Traffic Lights

Use the ultrasonic sensor to detect waiting vehicles and automatically extend the green phase

Intermediate

Parking Sensor

Build a parking sensor: Green = far, Amber = medium, Red = close, with a buzzer that beeps faster as you approach

Advanced

State Machine Traffic Lights

Implement the traffic light as a proper state machine using enum and switch/case — no delay-based sequencing

Advanced

Object Counter

Mount two HC-SR04 sensors facing each other to count objects that pass between them

Advanced

LCD Distance Display

Connect an I2C 16×2 LCD display to show live distance reading and gate status from Sketch 7

Advanced

Servo Smoothing

Modify Sketch 7 to use a running average of the last 5 distance readings to eliminate servo jitter

Key Concepts Reference
Function / Concept What it Does Used in
pinMode(pin, mode)Sets a pin as INPUT or OUTPUTAll
digitalWrite(pin, val)Sends HIGH (5V) or LOW (0V) to a digital pin1,3,4,5,7
delay(ms)Pauses everything for N milliseconds1,2a,3,4
analogWrite(pin, 0-255)Sends a PWM signal — creates brightness levels2a
millis()Returns milliseconds since power-on — non-blocking timer2b
Serial.begin(baud)Starts Serial communication at given baud rateAll
Serial.println()Sends text + newline to the Serial MonitorAll
Custom functionsReusable named blocks of code (void myFunc())3,4,5,7
pulseIn(pin, HIGH)Measures how long a pin stays HIGH — used for echo timing5,7
delayMicroseconds(µs)Pauses for N microseconds — finer than delay()5,7
Servo.attach(pin)Links Servo object to a physical PWM pin6,7
servo.write(angle)Moves servo to exact angle 0°–180°6,7
map(val,fL,fH,tL,tH)Scales a value from one range to another7
constrain(val,min,max)Clamps a value within min/max — prevents overflows7
for (init;cond;incr)Repeating loop with counter — used for fades and sweeps2a,6
unsigned longLarge integer type for millis() timestamps (0 to ~50 days)2b
booltrue / false variable — tracks binary state2b,7
#include <Servo.h>Loads the built-in Servo library — no installation needed6,7
📚 Further Learning: arduino.cc/reference has documentation for every Arduino function. Tinkercad Circuits lets you simulate Arduino circuits in your browser. Falstad Circuit Simulator is excellent for visualising PWM and timing circuits.