0% found this document useful (0 votes)
42 views5 pages

IOT Lab Manual Exp 11 & 12

The document outlines two experiments using the ESP32 microcontroller: blinking an LED and controlling an LED's brightness via the Blynk app. The first experiment confirms proper hardware setup and programming by blinking an LED, while the second demonstrates a basic IoT system allowing remote control of LED brightness using a smartphone. Both experiments serve as foundational tasks for more complex IoT projects.

Uploaded by

tony15812
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)
42 views5 pages

IOT Lab Manual Exp 11 & 12

The document outlines two experiments using the ESP32 microcontroller: blinking an LED and controlling an LED's brightness via the Blynk app. The first experiment confirms proper hardware setup and programming by blinking an LED, while the second demonstrates a basic IoT system allowing remote control of LED brightness using a smartphone. Both experiments serve as foundational tasks for more complex IoT projects.

Uploaded by

tony15812
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/ 5

SLRTCE BE MECH IOT

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:

1. ESP32 development board


2. LED (external)
3. 220 Ω resistor
4. Breadboard and jumper wires
5. USB cable
6. PC with Arduino IDE installed

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:

#define LED_PIN 2 // Using GPIO 2 for the LED

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

1. ESP32 development board


2. LED (external)
3. 220 Ω resistor
4. Breadboard and jumper wires
5. USB cable
6. PC with Arduino IDE installed
7. Smartphone with the Blynk app (download from Google Play Store or App Store)

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.

2. Blynk App Setup:


2.1. Download the Blynk App:
- Open the Google Play Store (Android) or App Store (iOS) and install the app "Blynk".
2.2. Create a New Project:
- Open Blynk, log in or sign up, then tap "New Project".
- Select "ESP32" as the device and "WiFi" as the connection type.
2.3. Obtain the Auth Token:
- Check your email for the authentication token sent by Blynk.
2.4. Configure the Slider Widget:
- In the project dashboard, tap the “+” button to add a widget.
- Select the "Slider" widget and assign it to virtual pin V1.
- Set the slider range to 0–1023 and save the project.

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";

int ledPin = 2; // LED connected to GPIO 2

// Setup PWM for ESP32: channel 0, 5 kHz frequency, 10-bit resolution


void setupPWM() {
ledcSetup(0, 5000, 10); // Channel 0, 5000 Hz, 10-bit resolution
ledcAttachPin(ledPin, 0);
}

// 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();
}

4.2. Replace "YourAuthToken", "YourWiFiSSID", and "YourWiFiPassword" with your


actual details.
4.3. Upload the code to the ESP32.

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

You might also like