Course Content
Hands-On ESP32 Robotics: Build Smart Robots Step by Step

📊 Analog Input and Output

🎯 Lesson Objective

In this lesson, students will understand:

• What analog signals are
• The difference between digital and analog signals
• How microcontrollers read analog values from sensors
• How analog output is simulated using PWM
• Functions used for analog input and output in Arduino programming

This lesson explains how microcontrollers handle continuous signals from sensors and control devices with variable output.


1️⃣ What is an Analog Signal?

An analog signal is a signal that can have many different values within a range.

Unlike digital signals that only have two states (HIGH or LOW), analog signals can vary continuously.

For example:

📉 Temperature levels
💡 Light intensity
🔊 Sound levels
🌡 Humidity levels

These values change gradually rather than switching between two states.

Because of this, analog signals allow microcontrollers to measure real-world physical conditions more accurately.


2️⃣ Digital vs Analog Signals

It is important to understand the difference between digital and analog signals.

🔌 Digital Signal

Digital signals have only two possible values.

• HIGH (1)
• LOW (0)

Examples include:

• Push buttons
• Limit switches
• IR sensors in digital mode


📊 Analog Signal

Analog signals can have many possible values within a range.

For example, a light sensor may produce different voltage levels depending on how bright the environment is.

This allows the microcontroller to measure precise environmental changes.


3️⃣ Analog Input in Microcontrollers

Microcontrollers read analog signals using special pins called analog input pins.

However, microcontrollers process data digitally, so analog signals must first be converted into digital values.

This conversion is performed by a component called the Analog-to-Digital Converter (ADC).


🔄 Analog-to-Digital Conversion (ADC)

The ADC converts the analog voltage into a numerical value that the microcontroller can process.

For example:

An analog sensor might produce voltages between 0V and 3.3V.

The ADC converts this voltage into a number.

For example:

0V → 0
3.3V → maximum value

This allows the program to read sensor values and make decisions.


4️⃣ Reading Analog Input

In Arduino programming, analog values are read using the analogRead() function.

Example:

 
int sensorValue = analogRead(34);
 

In this example:

• Pin 34 reads the analog signal.
• The value is stored in the variable sensorValue.

The value returned typically ranges between:

0 to 4095 (for ESP32 ADC).

This number represents the sensor reading.


5️⃣ Analog Sensors in Robotics

Many sensors used in robotics produce analog signals.

Examples include:

🌡 Temperature sensors
💡 LDR light sensors
🌱 Soil moisture sensors
🎤 Sound sensors

These sensors provide continuous data about the environment.

The microcontroller reads these values and uses them to control robot behavior.


6️⃣ Analog Output and PWM

Most microcontrollers cannot generate true analog voltage directly.

Instead, they simulate analog output using a technique called PWM (Pulse Width Modulation).

PWM works by rapidly switching a digital signal ON and OFF.

By adjusting the duration of the ON time, the system can simulate different voltage levels.


Example Uses of PWM

PWM is commonly used to control:

⚙️ Motor speed
💡 LED brightness
🔄 Servo motor control
🎚 Power regulation

By adjusting the PWM signal, devices can operate at different speeds or intensities.


7️⃣ Example of PWM Output

In Arduino programming, PWM signals can be generated using special functions.

Example concept:

If a motor receives a low PWM value, it rotates slowly.

If it receives a higher PWM value, it rotates faster.

This allows the microcontroller to control motor speed smoothly.


8️⃣ Analog Signals in Robotics Projects

Analog signals are important in robotics because they allow the robot to detect gradual changes in the environment.

Examples include:

💡 Detecting light levels using an LDR sensor
🌡 Monitoring temperature sensors
⚙️ Adjusting motor speed using PWM
📏 Measuring sensor values precisely

Using analog signals allows robots to behave more intelligently.


🚀 What Happens Next

Now that you understand how analog signals allow microcontrollers to read varying sensor values and control devices, the next step is to learn about conditional statements, which allow programs to make decisions.

Scroll to Top