0% found this document useful (0 votes)
19 views3 pages

Experiment No 5

The document outlines an experiment to generate analog-like outputs using an Arduino through Pulse Width Modulation (PWM) with the analogWrite() function. It details the required components, the theory behind PWM, and provides a sample code to control an LED's brightness. The experiment successfully demonstrates LED dimming, motor speed control, and audio signal generation applications.

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Experiment No 5

The document outlines an experiment to generate analog-like outputs using an Arduino through Pulse Width Modulation (PWM) with the analogWrite() function. It details the required components, the theory behind PWM, and provides a sample code to control an LED's brightness. The experiment successfully demonstrates LED dimming, motor speed control, and audio signal generation applications.

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

5 : Explore Analog Signal Generation using Arduino

1.Aim / Objective

To understand the process of generating analog-like outputs using an Arduino by simulating


analog signals with Pulse Width Modulation (PWM) through the analogWrite() function.

2. Apparatus Required / Components Required


Arduino Board (e.g., Arduino Uno, Nano, or Mega)
LED (or motor, as an optional component)
Resistor (e.g., 220 ohms for LED)
Breadboard
Connecting Wires
USB Cable (for Arduino connection to PC)
Computer with Arduino IDE

3.Theory

Analog Output Simulation Using PWM

Although the Arduino lacks a true Digital-to-Analog Converter (DAC) for generating variable
voltages, it can simulate analog output using Pulse Width Modulation (PWM). PWM involves
toggling a digital pin between HIGH and LOW at a high frequency. By adjusting the duty cycle
(the percentage of time the pin remains HIGH), an average voltage can be created. For
example, a 50% duty cycle on a 5V Arduino pin results in an effective 2.5V signal.

Pin Configuration

PWM Pins: The Arduino Uno offers PWM on digital pins marked with a tilde (~), such as pins 3,
5, 6, 9, 10, and 11.

The analogWrite() function generates PWM signals on these pins, accepting values from 0 (0%
duty cycle) to 255 (100% duty cycle).
4 . Code

The following C code demonstrates how to control an LED's brightness using PWM on an
Arduino pin:
#define pwmPin 9 // Define PWM pin (9) for the LED
void setup() {
pinMode(pwmPin, OUTPUT); // Set the PWM pin as output
}

void loop() {
for (int brightness = 0; brightness <= 255; brightness++) { // Increase brightness
analogWrite(pwmPin, brightness);
delay(10); // Small delay to observe the gradual change
}

for (int brightness = 255; brightness >= 0; brightness--) { // Decrease brightness


analogWrite(pwmPin, brightness);
delay(10); // Small delay to observe the gradual change
}
}

Explanation of the Code

1. Pin Setup: The PWM pin 9 is defined as the output for the LED.

2. analogWrite() Function: This function generates a PWM signal on the specified pin. Values
from 0 to 255 control the duty cycle, creating an analog-like effect.

3. Brightness Control: A loop is used to gradually increase and decrease the brightness by
adjusting the PWM value.

5. Result

The LED's brightness was successfully controlled using PWM. The LED smoothly transitioned
from off to full brightness and back, demonstrating the analog-like output.

6. Applications

LED Dimming: Control brightness for visual effects in displays


Motor Speed Control: Vary the speed of DC motors in robotics.

Audio Signal Generation: Simulate sound waveforms by adjusting PWM frequency and duty
cycle.

You might also like