MASINDE MULIRO UNIVERSITY OF
SCIENCE AND TECHNOLOGY
Department of Electrical & Communication Engineering
INTRODUCTION TO ARDUINO PROGRAMMING USING
ARDUINO SIMULATOR
Programme: Bachelor of Science in Electrical & Electronics Engineering
Level: Second Year
Training Mode: Hands-on Practical Using Arduino Simulator (Android or PC)
Duration: One Day dWorkshop (6 Hours)
Fundamentals – What is Arduino
and How to Start
Learning Objectives (by the end of this module, you will be able to):
1. Explain what a microcontroller is and what Arduino does.
2. Identify the main parts of an Arduino Uno board.
3. Install the Arduino IDE and connect the board to a computer.
4. Write, compile, and upload your first program (blink an LED).
5. Use pinMode, digitalWrite, and delay correctly.
1.1 What is a Microcontroller? (Very Simple
Explanation)
Think of a microcontroller as a tiny, very simple computer on a single
chip. It has:
A processor (to think)
Memory (to remember instructions)
Input/output pins (to connect lights, buttons, sensors)
Arduino is a friendly kit that wraps this microcontroller with:
A board that makes it easy to connect wires.
Free software (IDE) to write code on your computer.
A huge library of example programs.
Key point: The microcontroller cannot do anything until you tell it exactly
what to do – step by step.
1.2 The Arduino Uno Board – Anatomy (Look
at your board)
Label on board Name Purpose
(Big black chip) ATmega328P The microcontroller – the brain.
Connects to computer for code
USB socket USB port
and power.
(Small chip near Translates between USB and serial
USB-to-Serial
USB) signals.
Input or output: only HIGH (5V) or LOW
D0–D13 Digital pins
(0V).
Analog input Read voltages from 0 to 5V (0–1023 in
A0–A5
pins code).
Can simulate analog output (dimming,
~3,5,6,9,10,11 PWM pins
speed).
5V 5V output Supplies 5V to external components.
GND Ground (0V) Completes the circuit – always connect.
Vin Voltage input For external power (7–12V).
ON LED Power indicator Lights when board is powered.
Connected to digital pin 13 (useful for
L LED Built-in LED
testing).
Exercise 1.1 (Observation): Hold your board. Locate each of these parts.
Do not skip – this will save you from confusion later.
1.3 Installing the Arduino IDE (Step-by-Step)
1. Open a browser and go to: [Link]
2. Download the version for your operating system:
o Windows: Click “Windows Win 10 and newer” → run the .exe file.
o Mac: Click “macOS” → open the .dmg and drag Arduino to Applications.
o Linux: Follow the instructions for your distribution.
3. After installation, open the Arduino IDE. You should see a white coding
window.
1.4 Connecting and Configuring the Board
1. Plug the Arduino Uno into your computer using a USB-B cable (square end).
2. Wait a few seconds. The green “ON” LED should light up.
3. In the Arduino IDE, go to:
o Tools → Board → Arduino AVR Boards → Arduino Uno
4. Then go to:
o Tools → Port → select the COM port (Windows) or /dev/[Link] (Mac)
or /dev/ttyACM0 (Linux).
o If you see no port: Try a different USB cable (some are charge-only) or
restart the IDE.
Check: The bottom right corner of the IDE should show “Arduino Uno on
COMx” (or similar).
Arduino is an open-source microcontroller platform used to develop
electronic control systems. It enables engineers to interface sensors,
actuators, displays, communication modules, and other electronic devices
using simple programming techniques.
Applications of Arduino include:
Industrial automation
Smart home systems
Robotics
Internet of Things (IoT)
Renewable energy monitoring
Security systems
Instrumentation and control
This workshop introduces students to Arduino programming using simulators
before working with actual hardware.
2. LEARNING OBJECTIVES
At the end of this practical session, students should be able to:
Create and save Arduino programs (sketches)
Compile and execute Arduino code
Understand Arduino program structure
Control LEDs using digital outputs
Read digital and analog inputs
Develop simple automation programs
Simulate Arduino projects using Android phones or PCs
3. GETTING STARTED WITH
ARDUINODROID
Step 1: Install ArduinoDroid
Download and install:
ArduinoDroid Android Application
Step 2: Open ArduinoDroid
1. Launch ArduinoDroid.
2. Select New Sketch.
3. Delete any existing code.
4. Save the project using an appropriate name.
Example:
LED_Blink
4. UNDERSTANDING AN ARDUINO
PROGRAM
Every Arduino program consists of two compulsory sections:
setup()
This section runs only once when the board is powered or reset.
Used for:
Pin configuration
Initialisation
Serial communication setup
loop()
This section runs repeatedly and continuously.
Used for:
Reading inputs
Making decisions
Controlling outputs
PROGRAM STRUCTURE
void setup()
{
void loop()
{
}
PRACTICAL EXAMPLE 1
Blinking One LED Connected to
Pin 2
Objective
Write a program that switches an LED connected to Pin 2 ON and OFF
repeatedly with a delay of 1000 milliseconds.
Circuit Connections
Arduino Componen
Pin t
LED Anode
Pin 2
(+)
LED 220 Ω
Cathode (-) Resistor
Resistor GND
Connection Procedure
Step 1
Connect the long leg (anode) of the LED to Arduino Pin 2.
Step 2
Connect the short leg (cathode) of the LED to a 220 Ω resistor.
Step 3
Connect the other side of the resistor to GND.
Program
void setup()
{
pinMode(2, OUTPUT);
}
void loop()
{
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
}
Program Explanation
pinMode(2, OUTPUT);
Configures Pin 2 as an output pin.
digitalWrite(2, HIGH);
Turns the LED ON.
delay(1000);
Waits for 1000 milliseconds (1 second).
digitalWrite(2, LOW);
Turns the LED OFF.
delay(1000);
Waits another second before repeating.
Expected Output
The LED should:
Turn ON for 1 second
Turn OFF for 1 second
Continue repeating indefinitely
Exercise 1
Modify the delay from:
delay(1000);
to:
delay(500);
Question:
How does the blinking speed change?
PRACTICAL EXAMPLE 2
Controlling Three Blinking LEDs
Objective
Control three LEDs connected to Pins 2, 3, and 4 so that they blink one after
another.
Circuit Connections
Arduino Compo
Pin nent
Pin 2 Red LED
Yellow
Pin 3
LED
Green
Pin 4
LED
Each LED must have:
One 220 Ω resistor
Connection to GND
Connection Procedure
LED 1 (Red)
Long leg → Pin 2
Short leg → 220 Ω resistor
Resistor → GND
LED 2 (Yellow)
Long leg → Pin 3
Short leg → 220 Ω resistor
Resistor → GND
LED 3 (Green)
Long leg → Pin 4
Short leg → 220 Ω resistor
Resistor → GND
Wiring Diagram Representation
Pin 2 ---- LED1 ---- 220Ω ---- GND
Pin 3 ---- LED2 ---- 220Ω ---- GND
Pin 4 ---- LED3 ---- 220Ω ---- GND
Program
void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(1000);
}
Program Explanation
Stage 1
digitalWrite(2, HIGH);
LED 1 turns ON.
LED 2 and LED 3 remain OFF.
Stage 2
digitalWrite(3, HIGH);
LED 2 turns ON.
LED 1 and LED 3 remain OFF.
Stage 3
digitalWrite(4, HIGH);
LED 3 turns ON.
LED 1 and LED 2 remain OFF.
Expected Output
The LEDs blink sequentially:
LED 1 → LED 2 → LED 3 → LED 1 → LED 2 → LED 3
repeated continuously.
Exercise 2
Modify the program so that:
1. All LEDs turn ON simultaneously for 2 seconds.
2. All LEDs turn OFF simultaneously for 2 seconds.
Hint:
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
Exercise 3
Create a traffic-light sequence using:
Red LED on Pin 2
Yellow LED on Pin 3
Green LED on Pin 4
Timing:
Green = 5 seconds
Yellow = 2 seconds
Red = 5 seconds
Key Programming Functions
Learned
Function Purpose
Configure pin as input or
pinMode()
output
digitalWrite
Set output HIGH or LOW
()
delay() Pause program execution
setup() Runs once
loop() Runs continuously
Summary
In this lesson, you have learned how to:
✓ Configure Arduino output pins
✓ Blink a single LED using Pin 2
✓ Control three LEDs sequentially
✓ Use delays for timing control
✓ Understand the structure of an Arduino program
These concepts form the foundation for more advanced Arduino applications
involving sensors, motors, displays, communication systems, and IoT
projects