# Analog output with Arduino UNO board.[Code and circuit diagram]

## Analog output with Arduino UNO board

Hello guys, Welcome back to my blog. We talked about how digital pins work in a previous article. I hope you remember that. Please read my previous articles or study them and come to this article. So, let’s move on to today’s post.
Today I am going to show you how to use analog output pins and what is PWM? In the previous articles, we tried how to get digital outputs and in this article, we will try to get analog outputs.HIGH (5v) and LOW (0v) voltages are available from digital outputs. Analog outputs can take any voltage from 0v to 5v. We can control this voltage. For example, bulb brightness control and motor speed control.

### What is PWM?

The PWM process is called pulse width modulation. We can control the voltage as we want. This is also known as analog output. The pins on the Arduino board that can do this are called PWM pins. From these pins, we can get a value from 0 to 255.(0=0v and 255 = 5v ) If we want 2.5 volts, we have to give a value of 128. We will talk about this in the code.
We test this functionality in practice. There is a brightness control circuit used for this function. The components required for this are given below.

### Step 1

Get the components you need. I will describe them one by one below.
Arduino UNO
The Arduino UNO board is best suited for this project.
LED Bulb
Lighting Emitting Diode
1k Resistor
This component is used to control the current. Use these as the current coming through the Arduino board can go through the bulbs and burn out.
It is most useful to test the electronic circuit
Jumper Wires
This item is most useful for connecting the Arduino board with other components. There are three types of jumper wires. They are male to male, female to female, and female to male. In this project, I used two male-to-male jumper wires.

### Step 2

Connect the LED bulb to the breadboard.

### Step 3

Connect the resistor to the LED anode leg.

### Step 4

Connect the circuit to the Arduino board.
Use the PWM pins on the Arduino board for this. For that, we can use D3, D5, D6, D10, and D11 pins.

### Step 5

Connect the Arduino board to the computer.

### Step 6

Create code for the project.

### Source code

``````void setup() {
pinMode(3, OUTPUT); //define arduino pin
}

void loop() {
for (int a = 0; a <= 255; a++) {
analogWrite(3, a);
delay(10);
}
for (int b = 254; b > 0; b--) {
analogWrite(3, b);
delay(10);
}
}``````
The code in the void setup informs the Arduino board of the pin we want. The void loop code causes the LED bulb light to increase or decrease. I have used this project for two FOR LOOPs.My previous post explained how FOR LOOP works. Today we take a look at the newly added analog output.
analogWrite(3 , a);
The first value in parentheses indicates the analog pin and the second value indicates the value at which the LED bulb should blink. This value should be between 0-255. This function is performed by FOR LOOP. The first loop increases the light and the second loop decreases the light. This work continues using FOR LOOPS. You can control the speed of the brightness by changing the delay time.

### Step 6

Verify this code.
Step 7
Select the Arduino board and port

Step 8