Arduino Introduction
🔹 What is a Microcontroller?
- A microcontroller is a compact integrated circuit with a CPU, memory, and I/O pins.
- It controls specific tasks in devices like remotes, cars, microwaves, etc.
🔹 Arduino Uno
- The Arduino Uno is a popular microcontroller board based on the ATmega328P microcontroller
chip.
- It’s like a small computer that can be programmed to
control electronics.
🔹 Why Arduino?
- Easy to use and beginner-friendly
- Open-source with a large community
- Affordable for students and hobbyists
- Can connect to sensors, motors, LEDs
- Supported on simulation tools like Tinkercad
P in Diagram of Arduino Uno & Signal
Types
1. Digital I/O Pins (Pins 0 to 13)
hese pins can be used as either input or output. They are used to connect devices like LEDs,
T
buzzers, and switches. You can control whether they send or receive signals using code.
1
2. PWM Pins (Pins 3, 5, 6, 9, 10, 11)
hese are special digital pins that
T
support Pulse Width Modulation
(PWM). They can simulate analog
output, which is useful for dimming
LEDs or controlling motor speed.
. Analog Input Pins
3
(A0 to A5)
hese pins are used to read analog
T
signals from sensors. They can
detect varying voltage levels, such
as those from light sensors,
temperature sensors, or
potentiometers.
. Power Pins (5V, 3.3V,
4
GND)
hese pins are used to supply power
T
to other components.
V and 3.3V provide voltage to
5
sensors and modules.
GND (Ground) completes the circuit.
5. Reset Pin (RESET)
his pin is used to restart the Arduino. Pressing the reset button or triggering it through a wire
T
connected to this pin will restart the code running on the board.
2
Digital,Analog, andPWMsignals
1. Digital Signals
digital signal has only two values: ON or OFF (also called HIGH or LOW, or 1 and 0).
A
For example, an LED connected to a digital pin can either be fully ON or fully OFF—no
in-between.
Think of it like a switch: it’s either ON or OFF.
2. Analog Signals
n analog signal can have many values between 0
A
and 100%.
It changes smoothly and continuously, like the
volume knob on a speaker or brightness of light.
hink of it like a fan regulator: you can increase or
T
decrease speed gradually.
3. PWM (Pulse Width Modulation)
WM stands for Pulse Width Modulation. It is a way
P
to create an analog-like effect using digital signals.
Instead of sending a smooth signal, it turns the
digital pin ON and OFF very quickly.
By changing how long the pin stays ON versus OFF, it controls things like motor speed or LED
brightness.
hink of it like blinking the light very fast—so fast that it looks dim or bright based on how long it
T
stays ON.
3
Writing Arduino Code in Tinkercad
🔹 Getting Started:
- Go to tinkercad.com > Sign in > Circuits > Create
New Circuit
- Drag Arduino, Breadboard, LED, and Resistor
🔹 Writing Code:
- Click “Code” > Switch to Text Mode (C++)
- Write your Arduino sketch
🔹 Example: Blink LED on Pin 13
- Thesetup()function runs once when the Arduino
starts.
- pinMode(13, OUTPUT);tells the Arduino thatPin 13
will be used tosend signals, liketurning an LED on
or off.
- If we wanted to receive signals (like from a button),
we would writepinMode(pin, INPUT);.
-Theloop()function runs again and again.
- digitalWrite(13, HIGH);sends 5V to Pin 13 – turning
the LEDON.
- digitalWrite(13, LOW);sends 0V to Pin 13 – turning
the LEDOFF.
- delay(1000);pauses the code for 1 second, so the
LED blinks at regular intervals.
4
L ED Sequence Using Arduino on
Tinkercad
🔹 Objective:
onnect three LEDs (Red, Yellow, Green) to pins
C
3, 4, and 5 of the Arduino and make them blink one
after another in a sequence.
🔹 Circuit Description:
- Connect the Red LED to Pin 3,
-Yellow LED to Pin 4,
-Green LED to Pin 5.
-Use a resistor in series with each LED to protect it
from high current.
-Connect the other leg of each LED (short leg) to
GND on the Arduino.
🔹
Working: When the program
runs:
- Red LED lights up, then turns off.
-Yellow LED lights up, then turns off.
-Green LED lights up, then turns off.
This sequence keeps repeating to create a
blinking pattern.
5
Using a Push Button with LED – Digital Input
🔹 Objective:Turn the LED ON when the button is pressed.
🔹 Circuit:
- The long leg (anode) of the LED goes to pin 8, and the short
leg (cathode) of the LED is connected to GND through a
220-ohm resistor.
- A push button is connected to digital pin 2. One side of the
push button is connected to pin 2, and the other side is
connected to 5V on the Arduino. Additionally, a 10k-ohm
resistor is connected between pin 2 and GND. This resistor
acts as a pull-down resistor to ensure that the input pin reads
LOW (0) when the button is not pressed.
Explanation:
- pinMode(2, INPUT); sets pin 2 as an input to read the button void setup() {
state. pinMode(2, INPUT);
pinMode(8, OUTPUT);
-pinMode(8, OUTPUT); sets pin 8 as an output to control the LED. }
- The program continuously checks the state of the button using oid loop() {
v
digitalRead(2). int buttonState = digitalRead(2);
if(buttonState == HIGH) {
- If the button is pressed and the input reads HIGH, the LED digitalWrite(8, HIGH); // LED ON
connected to pin 8 turns ON. }
else {
-If the button is not pressed, the LED stays OFF. digitalWrite(8, LOW); // LED OFF
}
}
🔹 How it Works:
-When the button is not pressed, Pin 2 reads LOW (0), and LED remains OFF.
-When the button is pressed, Pin 2 reads HIGH (1), and LED turns ON
6
Analog Input: Potentiometer with LED
Objective
Adjust LED brightness using a potentiometer.
🔹 Circuit Connections
● Potentiometer
○ One side →5V
○ Other side →GND
○ Middle pin (wiper) →A0on Arduino
● LED
○ Anode (long leg)→Pin 9(PWM)
○ Cathode (short leg)→GND(through a
resistor)
🔹 Explanation
● T hepotentiometerworks like a volume knob.
void setup() {
As you rotate it, it sends a different voltage to
pinA0, which the Arduino reads. pinMode(9, OUTPUT);
● analogRead(A0)gets a value between0
and 1023. }
● map(...)converts that to a value between0
and 255(the PWM range). void loop() {
● analogWrite(9, value)sends a PWM
int potValue = analogRead(A0);
signal to pin 9, making theLED brighter or
dimmerbased on the value. nt ledBrightness = map(potValue, 0,
i
● delay(10)adds a small pause so the LED 1023, 0, 255);
adjusts smoothly.
analogWrite(9, ledBrightness);
delay(10);
}
7
Exercise 1 – Multiple Choice Questions
1. What does a microcontroller have inside it?
Q
a) Only memory b) Only lights c) CPU, memory, and pins to connect things d) Only wires
2. The Arduino Uno is a type of:
Q
a) Motor b) Microcontroller board c) Light bulb d) Wire
3. A digital signal can be:
Q
a) Many smooth values b) Always above 10 volts c) Only ON or OFF d) Always noisy
4. Pins A0 to A5 on Arduino are used for:
Q
a) Ground pins b) Reading analog signals c) Storing programs d) Making sounds
5. The chip used in Arduino Uno is called:
Q
a) Core i5 b) ATmega328P c) Arduino Light d) Power Chip
Answers:
Q1.c) CPU, memory, and pins to connect things
Q2.b) Microcontroller board
Q3.c) Only ON or OFF
Q4.b) Reading analog signals
Q5.b) ATmega328P
Exercise 2 – Fill in the Blanks
6. The ______ function in Arduino runs one time at the start.
7. A digital pin can be either ______ or ______.
8. The _______ command is used to set a pin as input or output in Arduino.
9. Analog signals change ______ and can have many values.
digitalWrite(8, LOW);turns ______ the thing connected to pin 8.
10.The command
8
Answers:
. setup()
6
7. ON; OFF
8. pinMode
9. smoothly
10. OFF
Theory Questions
1. Define microcontroller.
2. What are the benefits of using Arduino Uno?
3. Write the difference between analog and digital signals.
4. What is a PWM signal in Arduino?
5. W
rite an Arduino program to turn an LED ON for 2 seconds and then OFF for 1
second, repeating this again and again.
Find the answers:
9