ESP32-CONTROLLING
LED BRIGHTNESS
Aim:
To vary the intensity of LED using potentiometer.
Description:
This experiment shows how to read
an analog input value connected to onboard pot and display it on the serial
monitor of the Arduino Software (IDE).
Hardware required:
ESP32-Microcontroller development
board
Pin connection:
Pin Mapping:
Development Board
|
ESP32
|
Potentiometer
|
I034
|
LED
|
I05
|
Procedure:
1.
The above pin connection shows how to control the
brightness of LED using potentiometer in ESP32
board.
2.
Do the connections as shown in the pin diagram and pin mapping.
3.
Connect the USB cable to the board.
4.
Open Arduino IDE .Select DOIT ESP32 DEVKIT V1in boards and select COM port.
5.
Verify the program and Upload it.
6.
Open the serial monitor to observe the
values.
7.
Now using a screw driver rotate the potentiometer. The
LED will be very bright at the highest point and low as you turn the
potentiometer in the opposite direction.
Program:
void setup(void)
{
/*
set baud rate */
Serial.begin(9600);
/*
Initialize the input pin */ pinMode(34,INPUT);
/*
Initialize the output pin */ pinMode(5,OUTPUT);
}
/*
the loop function runs over and over again forever */
void loop(void)
void loop(void)
{
int
outputvalue=analogRead(34);
int value=map(outputvalue,0,1023,0,255);
analogWrite(5,outputvalue);
analogWrite(5,outputvalue);
/*
Print a value on the serial monitor */ Serial.println(outputvalue); delay(1000);
}
No comments:
Post a Comment