Arduino Course on Artificial Intelligence – Dimming Table Lamp (Part 6)

1. Course Introduction

This lesson explains the method and principle of implementing the program for Arduino analog signal output and Pulse Width Modulation (PWM) control.

The hardware required for this lesson: Arduino UNO, angle sensor, LED light.

Arduino Course on Artificial Intelligence - Dimming Table Lamp (Part 6)

2. Knowledge Points

Analog output and PWM control.

3.Module Explanation

Analog output.

Arduino Course on Artificial Intelligence - Dimming Table Lamp (Part 6)

Module location: in the “Pin Operations” section.

Module function: Output PWM signal to the specified port.

Arduino UNO has only 6 digital ports (3, 5, 6, 9, 10, 11) that can achieve PWM output. The PWM output value ranges from 0 to 255.

4. Program

Arduino Course on Artificial Intelligence - Dimming Table Lamp (Part 6)

5. Related Knowledge Explanation

Analog Output and PWM Modulation:

The voltage value of the analog signal output varies from 0 to 5V, but the output ports of the Arduino UNO board are all digital ports, which can only output high (5V) and low (0V) voltage values, so Arduino UNO cannot output true analog signals.

The built-in analog output of Arduino is achieved through PWM (Pulse Width Modulation), using a digital pulse signal that continuously switches between high and low levels to simulate analog signals. Before explaining PWM, it is necessary to understand two concepts: Pulse Period and Duty Cycle.

Pulse Period: The time interval between two adjacent pulses, the reciprocal of the period is the pulse frequency.

Duty Cycle: The ratio of the duration of high level in a pulse period to the pulse period.

PWM actually achieves the output effect of analog signals through rapid switching between high and low levels. In a pulse period, if the duty cycle is 50%, it is equivalent to the light being fully on for half the period, and then off for half the period. The pulse period of Arduino’s PWM signal is only 0.002s, which is 500 pulse periods per second. Due to the visual persistence effect of the human eye, the visual effect presented is equivalent to 50% brightness. At this time PWM equivalent output voltage V=5V×Duty Cycle=5V×50%=2.5V.

Arduino Course on Artificial Intelligence - Dimming Table Lamp (Part 6)

Arduino Course on Artificial Intelligence - Dimming Table Lamp (Part 6)

Leave a Comment

×