IOT Lab Manual Exp 11 & 12-1
IOT Lab Manual Exp 11 & 12-1
EXPERIMENT NO. 11
Blinking an LED with ESP32
Objective:
To demonstrate the basic operation of the ESP32 by blinking an LED. This experiment
verifies that the hardware is correctly set up and that the code properly controls the LED.
Apparatus:
Introduction:
The ESP32 is a powerful microcontroller with integrated WiFi and Bluetooth. In this
experiment, an external LED is connected to a digital output pin (GPIO 2) on the ESP32. By
toggling this pin, the LED will blink at regular intervals. This fundamental task is critical for
building confidence in both hardware interfacing and basic programming before moving on
to more advanced IoT projects.
Procedure:
1. Hardware Setup:
a. Connect one end of the 220 Ω resistor to GPIO 2 of the ESP32.
b. Connect the other end of the resistor to the anode (longer leg) of the LED.
c. Connect the cathode (shorter leg) of the LED to a GND pin on the ESP32.
d. Refer to Figure 1 for the wiring diagram.
2. Software Setup:
a. Connect the ESP32 to your PC using the USB cable.
b. Open the Arduino IDE and select the correct ESP32 board and COM port.
Program:
Enter and upload the following code to the ESP32:
void setup() {
pinMode(LED_PIN, OUTPUT); // Initialize LED_PIN as an output
}
void loop() {
digitalWrite(LED_PIN, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(LED_PIN, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}
49
SLRTCE BE MECH IOT
Conclusion:
The LED blinking confirms that the ESP32 is properly programmed and that the circuit
connections are correct. This basic experiment serves as the foundation for more complex
projects in IoT and embedded systems.
Figure 1:
Image: esp32_led_circuit.jpg
Description: The diagram shows the ESP32 board with an external LED connected
via a 220 Ω resistor to GPIO 2, with the LED’s cathode connected to GND.
50
SLRTCE BE MECH IOT
EXPERIMENT NO. 12
IoT Controlled LED using ESP32 with Blynk App
Objective:
To control an LED’s brightness remotely using the Blynk mobile app with an ESP32. This
experiment demonstrates a basic IoT system using WiFi, PWM, and remote control.
Apparatus:
Introduction:
This experiment shows how to build a simple IoT system with the ESP32. The ESP32
connects to a WiFi network and communicates with the Blynk server. A slider widget in the
Blynk app (assigned to virtual pin V1) sends a brightness value to the ESP32. The ESP32
then uses PWM to adjust the LED’s brightness. This task is a fundamental example of remote
control in IoT applications.
Procedure:
1. Hardware Setup:
a. Connect one end of a 220 Ω resistor to GPIO 2 of the ESP32.
b. Connect the other end of the resistor to the anode (long leg) of the LED.
c. Connect the cathode (short leg) of the LED to a GND pin on the ESP32.
d. Refer to Figure 1 for the wiring diagram.
2. Blynk App Setup:
a. Install the Blynk app on your smartphone and create a new project.
b. Note the authentication token provided.
c. Add a slider widget and assign it to virtual pin V1. Set the slider range to 0–1023.
3. Software Setup:
a. Connect the ESP32 to your PC using the USB cable.
b. Open the Arduino IDE and select the correct ESP32 board and COM port.
4. Programming:
a. Enter and upload the following code to the ESP32.
51
SLRTCE BE MECH IOT
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// Replace with your Blynk auth token, WiFi SSID, and WiFi password
char auth[] = "YourAuthToken";
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
// Blynk function to receive slider value from the app on virtual pin V1
BLYNK_WRITE(V1) {
int brightness = param.asInt(); // Get slider value (0–1023)
ledcWrite(0, brightness); // Set PWM duty cycle on channel 0
}
void setup() {
setupPWM();
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
}
5. Testing:
a. After uploading the code, open the Blynk app on your smartphone.
b. Adjust the slider widget and observe the LED brightness change according to the
slider value.
Conclusion:
If the LED brightness changes with the slider adjustment, the system is working correctly.
This experiment confirms that the ESP32 can connect to WiFi and interact with the Blynk
server to control hardware via PWM. It provides a simple and effective example of IoT
control.
52
SLRTCE BE MECH IOT
Figure 1:
Image: iot_led_circuit.jpg
Description: Circuit diagram showing the ESP32 with an external LED. The LED
(with a 220 Ω resistor) is connected to GPIO 2 and GND.
Figure 2:
Image: iot_block_diagram.jpg
Description: Block diagram illustrating the IoT system. It shows the ESP32
connecting to WiFi, communicating with the Blynk server, and controlling the LED
based on the slider input from the mobile app.
53