IOT Lab Manual Exp 11 & 12
IOT Lab Manual Exp 11 & 12
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 remotely control an LED’s brightness using the Blynk mobile app with an ESP32. This
experiment demonstrates a basic IoT system using WiFi, PWM, and a smartphone slider.
Apparatus
Introduction:
In this experiment, 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, which then uses PWM to adjust the LED’s brightness. This basic IoT setup is a
foundation for more advanced projects.
Procedure:
1. Hardware Setup:
1.1. Connect one end of a 220 Ω resistor to GPIO 2 of the ESP32.
1.2. Connect the other end of the resistor to the anode (long leg) of the LED.
1.3. Connect the cathode (short leg) of the LED to a GND pin on the ESP32.
1.4. Refer to Figure 1 for the circuit diagram.
3. Software Setup:
3.1. Connect the ESP32 to your PC using the USB cable.
3.2. Open the Arduino IDE and select the correct ESP32 board and COM port.
4. Programming:
4.1. Copy and paste the following code into the Arduino IDE:
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: receives 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:
5.1. Open the Blynk app on your smartphone.
5.2. Use the slider widget to adjust the LED brightness.
5.3. Observe the LED; it should dim or brighten in response to the slider value.
5.4. Refer to Figure 2 for an overview of the IoT control system.
Conclusion:
If the LED brightness changes with the slider, the ESP32 is correctly connected to WiFi and
communicating with the Blynk server. This experiment demonstrates a basic IoT system
where remote control is achieved via a smartphone. It forms an essential foundation for more
advanced IoT applications.
52
SLRTCE BE MECH IOT
Figures
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