📘 Lesson F8 – Digital vs Analog Pins
🎯 Learning Objectives
After completing this lesson, students will be able to:
✅ Understand what Digital Signals are
✅ Understand what Analog Signals are
✅ Differentiate between Digital and Analog Pins
✅ Use Digital Pins correctly
✅ Use Analog Pins correctly
✅ Understand ADC (Analog-to-Digital Converter)
✅ Understand how Arduino reads sensor data
✅ Select the correct pin for different components
1. Introduction
When working with Arduino, one of the most important concepts is understanding:
Digital Signals
and
Analog Signals
Almost every sensor, module, button, motor, and device connected to Arduino uses either digital signals or analog signals.
Before building projects, students must clearly understand the difference between them.
2. What is a Signal?
A signal is simply information transmitted from one device to another.
Examples:
- Button Press
- Temperature Reading
- Light Intensity
- Gas Concentration
- Motor Control Signal
Arduino receives these signals through its pins.
3. What is a Digital Signal?
A digital signal has only two possible states.
LOW
or
HIGH
Nothing exists between them.
Digital Logic
LOW
Represents:
- OFF
- FALSE
- 0 Volt
- Binary 0
HIGH
Represents:
- ON
- TRUE
- 5 Volt
- Binary 1
Example of Digital Signal
Imagine a room light switch.
The switch has only two states:
OFF
or
ON
This is exactly how digital signals work.
Real-Life Examples of Digital Devices
Push Button
Pressed or Not Pressed
IR Obstacle Sensor
Obstacle Detected or Not Detected
Relay Module
ON or OFF
LED
ON or OFF
Digital Signals in Arduino
Arduino Uno uses:
Digital Pins D0 to D13
These pins can:
- Read digital inputs
- Generate digital outputs
4. What is an Analog Signal?
Analog signals can have many values instead of only two states.
They vary continuously.
Example
Consider room temperature.
Temperature can be:
25°C
25.1°C
25.2°C
25.3°C
25.4°C
and so on.
It changes continuously.
This is an analog signal.
Real-Life Analog Examples
Temperature
Continuously changes
Light Intensity
Continuously changes
Sound Level
Continuously changes
Gas Concentration
Continuously changes
Water Level
Continuously changes
Why Analog Signals are Important
The real world is mostly analog.
Examples:
- Temperature
- Pressure
- Light
- Humidity
- Sound
All these change continuously.
Therefore Arduino must be able to measure analog values.
5. Analog Pins on Arduino UNO
Arduino Uno contains:
A0
A1
A2
A3
A4
A5
These are analog input pins.
Used for:
- LDR
- Potentiometer
- MQ Gas Sensor
- Soil Moisture Sensor
- Temperature Sensors
6. Problem: Arduino Understands Only Digital Data
The ATmega328P microcontroller works digitally.
It understands:
0
or
1
Only.
But sensors generate analog values.
How can Arduino understand analog signals?
The answer is:
ADC
7. What is ADC?
ADC stands for:
Analog to Digital Converter
It converts analog voltage into digital numbers.
Example
Suppose an LDR generates:
2.5V
Arduino cannot directly understand 2.5V as a value.
ADC converts:
2.5V
↓
512
Now Arduino can process the value.
8. ADC Resolution in Arduino UNO
Arduino Uno contains:
10-bit ADC
A 10-bit ADC provides:
1024 Levels
Range:
0 to 1023
ADC Conversion Table
| Voltage | ADC Value |
|---|---|
| 0V | 0 |
| 1V | 204 |
| 2V | 409 |
| 2.5V | 512 |
| 3V | 614 |
| 4V | 818 |
| 5V | 1023 |
9. Reading Analog Signals
Arduino uses:
analogRead()
Function.
Example:
int sensorValue;
sensorValue = analogRead(A0);
Arduino reads the voltage and converts it into a value between:
0 and 1023
10. Reading Digital Signals
Arduino uses:
digitalRead()
Function.
Example:
int buttonState;
buttonState = digitalRead(2);
Possible output:
0
or
1
Only.
11. Generating Digital Output
Arduino uses:
digitalWrite()
Function.
Example:
digitalWrite(13,HIGH);
LED ON
digitalWrite(13,LOW);
LED OFF
12. Analog Output in Arduino
Many beginners ask:
Does Arduino UNO have Analog Output Pins?
Technically:
No
Arduino Uno does not generate true analog voltage.
Instead it uses:
PWM
(Pulse Width Modulation)
to simulate analog output.
13. What is PWM?
PWM stands for:
Pulse Width Modulation
PWM rapidly switches a pin ON and OFF.
By changing ON time and OFF time, it creates an effect similar to analog output.
PWM Pins on Arduino UNO
D3
D5
D6
D9
D10
D11
These pins support PWM.
Applications of PWM
LED Brightness Control
Motor Speed Control
Fan Speed Control
Servo Control
14. Digital Pins vs Analog Pins
| Feature | Digital Pins | Analog Pins |
|---|---|---|
| Pin Numbers | D0-D13 | A0-A5 |
| Values | HIGH / LOW | 0-1023 |
| Signal Type | Digital | Analog |
| Reading Function | digitalRead() | analogRead() |
| Output Function | digitalWrite() | Analog Input Only |
| Applications | Buttons, Relays, LEDs | Sensors |
15. Which Devices Use Digital Pins?
Examples:
Push Button
Relay Module
Buzzer
IR Sensor
LED
Motor Driver Inputs
These devices only require ON/OFF signals.
16. Which Devices Use Analog Pins?
Examples:
LDR Sensor
Soil Moisture Sensor
Gas Sensor
Potentiometer
Temperature Sensors
These devices produce continuously changing values.
17. Practical Example
Push Button
Button Released
↓
LOW
Button Pressed
↓
HIGH
Digital Signal
LDR Sensor
Dark
↓
150
Medium Light
↓
500
Bright Light
↓
900
Analog Signal
18. Common Beginner Mistakes
Mistake 1
Connecting analog sensor to digital pin.
Result:
Incorrect readings.
Mistake 2
Expecting analog values from digitalRead().
Impossible.
Digital pins only return:
0 or 1
Mistake 3
Using digitalWrite() on analog sensors.
Wrong usage.
Mistake 4
Confusing PWM with true analog output.
PWM is not real analog voltage.
19. How Arduino Uses Digital and Analog Together
Example:
Automatic Street Light
Input
LDR Sensor
(Analog)
↓
Arduino Processes Data
↓
Output
LED
(Digital)
This is how most automation projects work.
20. Real World Applications
Smart Irrigation System
Soil Moisture Sensor → Analog
Pump Relay → Digital
Gas Leakage Detector
MQ Sensor → Analog
Buzzer → Digital
Line Follower Robot
IR Sensors → Digital
Motors → PWM
Automatic Water Dispenser
IR Sensor → Digital
Relay → Digital
📊 Summary
In this lesson, we learned:
✅ What digital signals are
✅ What analog signals are
✅ Digital pins and analog pins
✅ ADC working
✅ analogRead()
✅ digitalRead()
✅ digitalWrite()
✅ PWM basics
✅ Applications of digital and analog signals
Understanding digital and analog signals is one of the most important foundations of Arduino programming because almost every sensor and device depends on these concepts.
📖 Key Terms
Digital Signal
Signal with only two states: HIGH or LOW.
Analog Signal
Signal that varies continuously.
ADC
Analog-to-Digital Converter.
PWM
Pulse Width Modulation.
HIGH
Logic 1 or 5V.
LOW
Logic 0 or 0V.
analogRead()
Function used to read analog values.
digitalRead()
Function used to read digital values.
digitalWrite()
Function used to generate digital outputs.
🎯 Quiz
1. How many analog pins are available on Arduino UNO?
A. 4
B. 5
C. 6 ✅
D. 8
2. What is the ADC resolution of Arduino UNO?
A. 8-bit
B. 10-bit ✅
C. 12-bit
D. 16-bit
3. Which function reads analog values?
A. digitalRead()
B. digitalWrite()
C. analogRead() ✅
D. analogWrite()
4. What values can digitalRead() return?
A. 0-1023
B. HIGH or LOW ✅
C. 0-255
D. Any value
5. Which of the following is an analog sensor?
A. Push Button
B. Relay
C. LDR Sensor ✅
D. LED
🏠 Assignment
Task 1
Create a table comparing Digital Signals and Analog Signals.
Task 2
List five devices that use digital pins.
Task 3
List five devices that use analog pins.
Task 4
Draw a block diagram showing how ADC converts analog signals into digital values.
Task 5
Research PWM and write three applications where PWM is used in real-world electronics.