š” AnalogWrite ARDUINO espaƱol desde CERO ć 2021 ć - CapĆtulo #07š
Introduction to Analog Writing with Arduino
Overview of the Lesson
- Joanne PƩrez introduces a class focused on the analog writing capabilities of an Arduino board, contrasting it with digital writing which only allows for two states: off and on.
- The lesson will include a practical example to illustrate how analog writing can be utilized, highlighting that it offers up to 256 distinct values due to its 8-bit resolution.
Materials Needed
- Simple materials required for the exercise include an Arduino board, an LED, a resistor, and jumper wires. The goal is to demonstrate how analog writing functions.
Setting Up the Circuit
Circuit Assembly
- A straightforward circuit is constructed using the components mentioned. The positive lead of the LED is connected to pin 9 (an analog-capable pin), while ensuring proper voltage regulation through a resistor.
- An explanation about PWM (Pulse Width Modulation) is provided as a method used by Arduino for analog output. Only specific pins (3, 5, 6, 9, 10, and 11) support this feature.
Programming Basics
Code Initialization
- The programming begins by defining a variable for pin number 11 as
blueLed, setting it up in the setup function without needing explicit declaration of its mode as digital or analog.
Implementing Analog Write Functionality
- In the loop function, instead of using
digitalWrite,analogWriteis introduced. This allows sending values between 0 and 255 to control brightness levels of the LED.
Understanding Value Ranges
Value Explanation
- Itās clarified that while there are technically 256 possible values (from 0 to 255), only values from this range should be used in coding practices. Using absolute values directly in code is discouraged.
Testing and Troubleshooting
Final Adjustments
Understanding Analog and Digital Signals in Arduino
LED Brightness Control
- The LED turns off when a value of 0 is sent. When an intermediate value, such as 125, is sent, the LED lights up, demonstrating varying brightness levels.
- A practical exercise involves using three brightness values (1, 2, and 3) with delays to observe changes in LED brightness over time.
- The program cycles through brightness values from 0 to 255 at half-second intervals to better visualize voltage differences applied to the LED.
- The code successfully implements the delay function; it cycles through brightness levels: 0 (off), 125 (dim), and 255 (full brightness).
Key Concepts of Signal Types
- A theoretical discussion on the difference between analog and digital signals is introduced using a Cartesian plane where time is represented on the x-axis and voltage on the y-axis.
- An analog signal continuously fluctuates between voltages (e.g., from 0V to 5V), while digital signals can only represent minimum or maximum values (0 or 255).
Binary Values in Arduino
- In binary counting for Arduino, values range from 0 to 255 instead of going up to 256 due to starting at zero. This means that:
- Value
0corresponds to0V
- Value
255corresponds approximately to5V
- Intermediate values like
126represent around2.5V.
Limitations of Arduino's Analog Writing
- Although Arduino cannot directly write real analog values, it can emulate them using PWM (Pulse Width Modulation).
- The lesson emphasizes understanding how analog writing differs from digital writing by offering a range of values rather than just low/high states.
Practical Challenge