0% found this document useful (0 votes)
14 views

IOT File

The document details a series of experiments using the ESP32 microcontroller, focusing on its features, hardware requirements, and software setup using Arduino IDE. It covers interfacing components like LEDs and DHT11 sensors, demonstrating control and data collection capabilities essential for IoT applications. Each experiment concludes with results showcasing the successful implementation of the projects, emphasizing the ESP32's versatility in embedded systems.

Uploaded by

Foram Modi
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)
14 views

IOT File

The document details a series of experiments using the ESP32 microcontroller, focusing on its features, hardware requirements, and software setup using Arduino IDE. It covers interfacing components like LEDs and DHT11 sensors, demonstrating control and data collection capabilities essential for IoT applications. Each experiment concludes with results showcasing the successful implementation of the projects, emphasizing the ESP32's versatility in embedded systems.

Uploaded by

Foram Modi
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/ 39

IOT (3173215) En.No.

: 211310132057

Experiment 1

• Aim: Introduction to ESP32S / Node MCU Development kit.


• Hardware Required: ESP 32
• Software Required: Arduino IDE
• Theory:

Basic of ESP-32:

The ESP-WROOM-32 is a popular module based on the ESP32 microcontroller, which is


widely used in IoT (Internet of Things) and embedded systems projects. Here are some basic
aspects and features of the ESP-WROOM-32:

1. ESP32 Microcontroller: The ESP-WROOM-32 module is built around the ESP32


microcontroller, which is a powerful and versatile chip. It features a dual-core processor, Wi-
Fi and Bluetooth connectivity, and a rich set of I/O peripherals, making it suitable for a wide
range of applications.

2. Wi-Fi and Bluetooth: The ESP32 module comes with built-in Wi-Fi (802.11 b/g/n) and
Bluetooth (Bluetooth Classic and Bluetooth Low Energy) connectivity. This enables it to
connect to the internet and communicate with other devices wirelessly.

3. Dual-Core Processor: The ESP32 microcontroller has two CPU cores, which can be
independently programmed. This allows for multitasking and efficient handling of complex
tasks.

4. Memory: The module typically includes Flash memory for program storage and RAM
for data storage and execution. The exact memory size may vary depending on the specific
variant of the ESP-WROOM-32 module.

5. I/O Pins: The ESP-WROOM-32 module provides a variety of GPIO (General-Purpose


Input/Output) pins that can be used to interface with sensors, displays, and other external
components. These pins support various communication protocols, including UART, SPI,
I2C, and PWM.

6. Peripherals: The ESP32 microcontroller includes a wide range of peripherals, such as


ADCs (Analog-to-Digital Converters), DACs (Digital-to-Analog Converters), timers, touch
sensors, and more. These peripherals make it versatile and suitable for various applications.

7. Development Environment: To program and develop for the ESP-WROOM-32, you can
use the Arduino IDE with the ESP32 board support package, or you can use the Espressif IDF
(IoT Development Framework), which provides more low-level control and customization
options.

1
IOT (3173215) En.No.: 211310132057

8. Power Supply: The module typically operates on a voltage supply of 3.3V and consumes
low power, making it suitable for battery-powered and low-power applications.

9. Compact Form Factor: The ESP-WROOM-32 module is available in a compact


surface- mount module form factor, which simplifies integration into custom PCB
designs.

10. Community and Ecosystem: The ESP32 has a large and active community of developers
and a growing ecosystem of libraries, documentation, and resources, making it easier to find
support and solutions for your projects.

Pin diagram:

Figure 1.1: pin-diagram of ESP-32

Pin description:

1. TX0 (UART0 Transmit):


- This pin is used for serial communication. It is the transmit (TX) pin for UART0,
allowing data to be transmitted from the ESP32 to external devices. It is commonly used
for debugging and data transmission.

2. RX0 (UART0 Receive):


- This pin is used for serial communication. It is the receive (RX) pin for UART0,
allowing data to be received by the ESP32 from external devices. It is commonly used for
receiving data from sensors or other microcontrollers.

3. TX2 (UART2 Transmit):

2
IOT (3173215) En.No.: 211310132057

- This pin is the transmit (TX) pin for UART2. UART2 is an additional serial
communication interface on the ESP32, providing more options for serial communication
with external devices.

4. RX2 (UART2 Receive):


- This pin is the receive (RX) pin for UART2. UART2 is an additional serial
communication interface on the ESP32.

5. GPIO Pins (0 to 36):


- These pins can be used for general-purpose digital input and output. You can configure
them as inputs to read digital signals or as outputs to control external devices like LEDs,
relays, and more.

6. ADC Pins (GPIO32 to GPIO39):


- These pins can function as analog-to-digital converter (ADC) pins, allowing you
to measure analog voltage levels. They are useful for reading analog sensors, such as
temperature sensors and light sensors.

7. I2C Pins (SCL/SDA):


- I2C (Inter-Integrated Circuit) is a communication protocol for connecting multiple devices
on a bus. SCL (Serial Clock) is the clock signal, and SDA (Serial Data) is the data signal.
Thesepins are used for connecting to I2C-compatible sensors and devices.

8. SPI Pins (SCK/MISO/MOSI/CS):


- SPI (Serial Peripheral Interface) is a synchronous serial communication protocol
commonly used for interfacing with devices like displays and flash memory. These pins are
used for SPI communication: SPI_CLK (Clock), SPI_MISO (Master In Slave Out),
SPI_MOSI (Master Out Slave In), and SPI_CS (Chip Select).

Specifications:

- Microcontroller: ESP32-D0WDQ6
- CPU: Dual-core Tensilica LX6
- Clock Frequency: Up to 240 MHz
- Wireless: Wi-Fi (2.4 GHz) and Bluetooth (BLE)
- Flash Memory: 4 MB
- RAM: 520 KB
- GPIO Pins: 36 available
- ADC Resolution: Up to 12 bits
- Operating Temperature: -40°C to +85°C
- Supply Voltage: 3.0V to 3.6V
- Dimensions: Typically around 18mm x 25mm
- Development: Arduino IDE, ESP-IDF
- Security: WPA2-Enterprise, Secure Boot
- Certifications: FCC, CE, IC, SRRC, KCC, and others (varies by module)

3
IOT (3173215) En.No.: 211310132057

Features:

1. Powerful Microcontroller: Built around the ESP32-D0WDQ6 microcontroller, featuring


a dual-core Tensilica LX6 CPU with clock speeds of up to 240 MHz.

2. Wireless Connectivity: Supports 2.4 GHz Wi-Fi (802.11 b/g/n) for wireless
internet connectivity and Bluetooth Classic and Bluetooth Low Energy (BLE) for
wireless communication with other devices.

3. Onboard Antenna: Equipped with an onboard PCB antenna for wireless communication,
reducing the need for external antennas.

4. Memory: Offers 4 MB of Flash memory for program storage and 520 KB of SRAM for
data storage and execution.

5. GPIO Pins: Provides 36 GPIO pins that can be configured for various digital and
analog functions, making it versatile for interfacing with external sensors and devices.

6. Analog-to-Digital Conversion: Supports up to 12-bit analog-to-digital conversion


(ADC) with 18 available channels for analog sensor inputs.

7. Development Environment: Compatible with popular development environments such as


the Arduino IDE and the Espressif IoT Development Framework (ESP-IDF).

8. Security: Features encryption support (WPA2-Enterprise, WPA3, SHA-256) and


Secure Boot functionality to enhance the security of IoT applications.

9. OTA Updates: Supports Over-the-Air (OTA) firmware updates, allowing for remote
updates and maintenance.

10. Low Power: Offers low-power modes and optimizations suitable for battery-powered and
energy-efficient IoT applications.

11. Dimensions: Typically comes in a compact module form factor (around 18mm x 25mm)
for easy integration into custom PCB designs.

4
IOT (3173215) En.No.: 211310132057

Software Installation Steps:

1) Download Arduino IDE


2) Open Arduino IDE > Preferences > Additional Board Manager >
Add this URL: https://dl.espressif.com/dl/package_esp32_index.json

Figure 1.2: Arduino IDE

3) Library > Sketch > include library > manage library


4) Install firebase ESP32 Client Library

Figure 1.3: Installing firebase Esp32 Client library

5
IOT (3173215) En.No.: 211310132057

5) Tools > Board > Board Manager > ESP 32 (expressif sys)

Figure 1.4: Board Manager

6) Install the USB driver


Website: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Driver name: CP210x USB to UART Bridge VCP Drivers

7) In Arduino IDE > Device manager > Ports > CP210x USB to USART Bridge

• Result:

In this experiment, we introduced the ESP-WROOM-32S development kit and explored its
basic features and capabilities. We learned about the ESP32 microcontroller, its dual-core
processor, and its support for both Wi-Fi and Bluetooth connectivity. We also examined the
key GPIO pins, analog-to-digital conversion, and various communication interfaces such as
UART, SPI, and I2C. Additionally, we followed the software installation steps required to set
up the Arduino IDE for ESP32 development.
• Conclusion:

The ESP-WROOM-32S is a versatile and powerful development kit suitable for a wide range
of IoT and embedded systems projects. Its dual-core CPU, wireless connectivity options,
ample memory, and rich set of peripherals make it an excellent choice for prototyping and
building IoT applications. With the development environment configured, we are now ready to
start creating projects that leverage the capabilities of the ESP32 microcontroller and explore
the exciting world of IoT development.

6
IOT (3173215) En.No.: 211310132057

Experiment 2

• Aim: To Interface LED on ESP32 kit and control the on off timing from the code.

• Equipment required: LED, jumper wires, ESP 32

• Software required: Arduino IDE

• Circuit Diagram:

Figure 2.1: Circuit Diagram

• Components:
LED:

Figure 2.2: LED

LED stands for light-emitting diode. LEDs are semiconductor devices that emit light
when an electric current passes through them.

7
IOT (3173215) En.No.: 211310132057

ESP 32:

Figure 2.3: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power systems on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

• Code:
void setup() {
// put your setup code here, to run once://the led is connected to pin 18
//setting pin 18 to output mode
pinMode(18,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//setting the pin to high to supply current

digitalWrite(18,HIGH);

//delaying the glow led for 1 sec


delay(1000);

//setting the pin to low to remove current supplydigitalWrite(18,LOW);


//delaying the program for 1 sec
delay(1000);

8
IOT (3173215) En.No.: 211310132057

• Result and Output:

Figure 2.4: Result and output

• Code:

Figure 2.5: Code

Conclusion:
In this experiment, we successfully interfaced an LED with an ESP32 microcontroller using
the Arduino IDE. By writing a simple Arduino sketch, we were able to control the on-off
timing of the LED. The LED was connected to pin 18 of the ESP32, and the code set this
pin to a high state to turn on the LED, followed by a delay of 1 second. Then, it set the pin
to a low state to turn off the LED, followed by another 1-second delay. This cycle repeated
continuously. As a result, we achieved a clear demonstration of how to control the state and
timing of an LED using the ESP32 microcontroller, which serves as a fundamental building
block for more complex IoT and embedded systems projects.

9
IOT (3173215) En.No.: 211310132057

Experiment 3

• Aim: To Interface LED on ESP32 and control it with the help of PUSH Button.

• Software required: Arduino IDE

• Circuit Diagram:

Figure 3.1: Circuit Diagram

• Components:
LED:

Figure 3.2: LED

LED stands for light-emitting diode. LEDs are semiconductor devices that emit light
when an electric current passes through them.
Button:

Figure 3.3: Button

A push-button (also spelled pushbutton) or simply button is a simple switch mechanism


to control some aspect of a machine or a process.

10
IOT (3173215) En.No.: 211310132057

ESP 32:

Figure 3.4: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power systems on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

• Code:

Figure 3.4: code

11
IOT (3173215) En.No.: 211310132057

• Result and Output:

Figure 3.5: Resultant circuit

• Conclusion:

In this experiment, we successfully interfaced an LED with an ESP32 microcontroller and


controlled it using a push-button. The code configured the LED pin as an output and the
button pin as an input with a pull-up resistor, allowing us to detect when the button is
pressed. When the button is pressed, the LED lights up, and when it's released, the LED
turns off. This simple project demonstrates the basic principles of digital input and output
control using an ESP32 microcontroller. It serves as a foundation for more complex IoT and
automation applications where sensor inputs and actuator outputs are essential components.

12
IOT (3173215) En.No.: 211310132057

Experiment 4

• Aim: To Interface DHT11 with ESP32 to display Temperature and Humidity on the serial
monitor on the computer.

• Equipment required: DHT11, ESP 32

• Software required: Arduino IDE, DHT sensor library (ada fruit)

• Circuit Diagram:

Figure 4.1: circuit Diagram

• Components:

DHT11:

Figure 4.2:

13
IOT (3173215) En.No.: 211310132057

The DHT-11 Digital Temperature and Humidity Sensor is a basic, ultra low-cost digital
temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to
measure the surrounding air and spits out a digital signal on the data pin (no analog input
pins needed).

ESP32:

Figure 4.3: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power systems on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

DHT Sensor Library:

1) Open Arduino IDE


2) Select tool menu
3) Click on manage libraries

Figure 4.4: Manage Libraries

4) Search DHT

14
IOT (3173215) En.No.: 211310132057

5) Install DHT sensor library by Adafruit

Figure 4.5: Installing DHT

• Code:

Figure 4.6: code

15
IOT (3173215) En.No.: 211310132057

• RESULT AND OUTPUT:

Figure 4.7: Resultant Circuit

Figure 4.8: output

• Conclusion:
In this experiment, we successfully interfaced a DHT11 temperature and humidity sensor
with an ESP32 microcontroller and displayed the sensor's readings on the serial monitor via
the Arduino IDE. The code initialized the DHT sensor, read temperature and humidity
values in both Celsius and Fahrenheit, and then printed the values to the serial monitor. This
experiment demonstrates the capability of the ESP32 microcontroller to interface with
sensors and collect data from the physical world. It's a foundational step for various IoT
applications where environmental monitoring and data collection are essential. Overall, by
successfully interfacing and obtaining data from the DHT11 sensor, we've learned the basics
of sensor integration with the ESP32 platform, paving the way for more complex IoT
projects involving data acquisition and analysis.

16
IOT (3173215) En.No.: 211310132057

Experiment 5

• Aim: To Interface DHT11 and OLED with ESP32 kit to display Temperature and
Humidity on the OLED display.

• Equipment Required: DHT11, I2C OLED screen, ESP32 Software

Required: Arduino IDE, DHT Library, SSD 1306 library

• Circuit Diagram:

Figure 5.1: circuit diagram

• Components:

DHT11:

Figure 5.2: DHT-11 Digital Temperature And Humidity Sensor

The DHT-11 Digital Temperature And Humidity Sensor is a basic, ultra low-cost digital
temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to
measure the surrounding air and spits out a digital signal on the data pin (no analog input
pins needed).

17
IOT (3173215) En.No.: 211310132057

I2C OLED Screen:

Figure 5.3: I2C OLED Screen

This oled display works on i2c communication, So it has only four pins. SDA(Serial Data)
carries the data. SCL(Serial Clock) clock line. It is used to synchronize all data transfers
over the I2C bus. GND goes to ground pin.

ESP 32:

Figure 5.4: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power system on a chip microcontroller with integrated


Wi-Fi and dual-mode Bluetooth.
SSD 1306 library:
1) Open Arduino IDE
2) Select tool menu
3) Click on manage libraries

Figure 5.5: Manage Libraries

18
IOT (3173215) En.No.: 211310132057

4) Search SSD 1306


5) Install SSD 1306 Library by ADAfruit

Figure 5.6: Instalingl SSD 1306 Library

Code:
#include <DHT.h>
#define DHT_SENSOR_PIN 19 // ESP32 pin GPIO19 connected to DHT11
sensor#define DHT_SENSOR_TYPE DHT11
#include <Wire.h>
#include
<Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in
pixels#define SCREEN_HEIGHT 64 // OLED height,
in pixels

// create an OLED display object connected to I2C Adafruit_SSD1306


oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);


void setup() {
Serial.begin(9600
);

19
IOT (3173215) En.No.: 211310132057

dht_sensor.begin(); // initialize the DHT sensor


//OLED SETUP
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display

oled.setTextSize(1); // set text size


oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.println("SMIL ROCKS"); // set text oled.display();
// display on OLED
}
void loop() {
// read humidity
float humi = dht_sensor.readHumidity();
// read temperature in Celsius
float tempC = dht_sensor.readTemperature();
// read temperature in Fahrenheit
float tempF = dht_sensor.readTemperature(true);
// check whether the reading is successful or not if (
isnan(tempC) || isnan(tempF) || isnan(humi)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi); Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
oled.clearDisplay(); // clear display
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 10);
oled.printf("Temperature is %0.2f\n", tempC);
oled.printf("Humidity is %0.2f %", humi); // set text oled.display();// display on OLED
}

20
IOT (3173215) En.No.: 211310132057

// wait a 2 seconds between readings


delay(2000);
}

Result and Output:

Figure 5.7: Resultant Circuit

Conclusion:
In this experiment, we successfully interfaced a DHT11 temperature and humidity sensor
with an I2C OLED display using an ESP32 microcontroller. By using the Arduino IDE and
appropriate libraries such as the DHT library and SSD1306 library, we were able to collect
temperature and humidity data from the DHT11 sensor and display it on the OLED screen.
This experiment demonstrates the versatility of the ESP32 microcontroller for integrating
different sensors and display devices, making it a valuable platform for IoT and data
visualization applications. By combining temperature and humidity data with a user-friendly
OLED display, we've created a simple yet effective monitoring system, showcasing the
potential for building more advanced and practical IoT projects in the future.

21
IOT (3173215) En.No.: 211310132057

Experiment 6

• Aim: To Interface ultrasonic sensor (HC-SR04) and OLED withESP32 to display distance
on the OLED Display/Serial Monitor.

• Equipment Required: HC-SR04 ultrasonic sensor, ESP32.

• Software Required: Arduino IDE

• Circuit Diagram:

Figure 6.1: circuit diagram

• Components:

I2C OLED Screen:

Figure 6.2: OLED screen

This oled display works on i2c communication, So it has only four pins. SDA(Serial Data)
carries the data. SCL(Serial Clock) clock line. It is used to synchronize all data transfers
over the I2C bus. GND goes to ground pin.

HC-SR04 Ultrasonic Sensor:


The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just
likethe bats do. It offers excellent non-contact range detection with high accuracy and stable
readings in an easy-to-use package from 2 cm to 400 cm or 1” to 13 feet.

22
IOT (3173215) En.No.: 211310132057

ESP32:

Figure 6.3: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power system on a chip microcontroller with integrated


Wi-Fi and dual-mode Bluetooth.

• Code:
#include <Wire.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define TRIG_PIN 23 // ESP32 pin GPIO23 connected to Ultrasonic Sensor's TRIG pin
#define ECHO_PIN 19 // ESP32 pin GPIO22 connected to Ultrasonic Sensor's ECHO pin
float duration_us, distance_cm;
void setup() {
// begin serial port Serial.begin (9600);
// configure the trigger pin to output mode pinMode(TRIG_PIN, OUTPUT);
// configure the echo pin to input mode pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C if
(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display oled.display();
}
void loop() {
// generate 10-microsecond pulse to TRIG pin digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// measure duration of pulse from ECHO pin duration_us = pulseIn(ECHO_PIN, HIGH);
// calculate the distance distance_cm = 0.017 * duration_us;
// print the value to Serial Monitor Serial.print("distance: ");
Serial.print(distance_cm);

23
IOT (3173215) En.No.: 211310132057

oled.clearDisplay();
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.printf("distance: %0.2f",distance_cm);
oled.display();
Serial.println(" cm");
delay(500);
}

• Result and Output:

Figure 6.4: Resultant Circuit

Figure 6.5: Ouput

Conclusion:
In this experiment, we successfully interfaced an HC-SR04 ultrasonic sensor with an ESP32
microcontroller to measure distance, and we displayed the distance reading on an I2C OLED
display. The code initialized the ultrasonic sensor and used it to calculate the distance based
on the time it takes for an ultrasonic pulse to travel and return. The distance reading was then
displayed on the OLED screen. This experiment demonstrates how the ESP32 can be used
in conjunction with sensors and display modules to create a simple distance measurement
and display system. Such setups are useful in various applications, including robotics,
automated navigation, and proximity detection systems.

24
IOT (3173215) En.No.: 211310132057

Experiment 7

• Aim: To Interface Stepper Motor with ESP32 using motor driver module to Start and
stop the motor and vary its speed in both directions using Blynk App.
• Equipment Required: 28BYJ-48 Stepper Motor, ESP 32
• Software Required: Arduino IDE, Blynk App/Web App, Blynk Library

• Circuit Diagram:

Figure 7.1: circuit diagram

• Components:
28BYJ-48 Stepper Motor:

Figure 7.2: Stepper Motor

The 28BYJ-48 is a 5V, 4-phase unipolar stepper motor with a 5.625-degree step angle and
a 1:64 gear reduction. It is commonly used in DIY projects and low-cost applications
requiring controlled rotation, such as robotics and small automation systems, often driven
by a ULN2003 driver board for precise control.

25
IOT (3173215) En.No.: 211310132057

ESP32:

Figure 7.3: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power system on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

Blynk Library:
1) Open Arduino IDE
2) Select tool menu
3) Click on manage libraries

Figure 7.4: Manage Libraries

4) Search Blynk
5) Install Blynk Library by Volodymyr

Figure 7.5: Instalingl Blynk Library

26
IOT (3173215) En.No.: 211310132057

Setup Blynk Web App:

1) Create new template

Figure 7.6: creating new template

2) Add a data stream with virtual pin v0 range from -20 to 20

Figure 7.7: Add a datastream

3) Add slider widget and get the meta data of the template for the code

Figure 7.8: Add Slider Widget

27
IOT (3173215) En.No.: 211310132057

4) Create new device and select the motor control template

Figure 7.9: Creatig new device

5) Select the device and control

Figure 7.10: Selecting Device control

• Code:
#include <Stepper.h>
#define BLYNK_PRINT Serial // Include Blynk Serial
#include <WiFi.h> // ESP32 WiFi Library #include <WiFiClient.h>
#include <BlynkSimpleEsp32.h> // Stepper Motor Configuration
#define IN1 19 // Define the pin for IN1
#define IN2 18 // Define the pin for IN2
#define IN3 5 // Define the pin for IN3
#define IN4 17 // Define the pin for IN4
// Create a Stepper object for the motor Stepper myStepper(1000, IN1, IN3, IN2, IN4);
// Blynk Template Configuration
#define BLYNK_TEMPLATE_ID "TMPL3A2BPm5Lh"
#define BLYNK_TEMPLATE_NAME "motor control"
#define BLYNK_AUTH_TOKEN "83qzMYL3hPIJ2LuoflDUpB4zdwditCvt" // Blynk Auth
Token
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "WIFI NAME"; // Your WiFi SSID
char pass[] = "abcd@1234"; // Your WiFi password
void setup() {
// Initialize Serial Communication Serial.begin(9600);
// Initialize Blynk

28
IOT (3173215) En.No.: 211310132057

Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);


// Set the speed of the stepper motor myStepper.setSpeed(50);
}
int value = 0;
BLYNK_WRITE(V0) {
value = param.asInt(); // Get the value from the Blynk app
}
void loop() {
Blynk.run(); // Run the Blynk service
Serial.println(value); // Print the value to the serial monitor
myStepper.step(value * 100); // Move the stepper motor based on the Blynk value
}

• Result and Output:

Figure 7.11: Motor control using the slider

• Conclusion:

In this experiment, we successfully interfaced a 28BYJ-48 stepper motor with an ESP32


microcontroller using a motor driver module and controlled its speed and direction using the
Blynk app. The motor responded to the Blynk app's input, allowing us to start and stop it
while varying its speed in both directions. This demonstrates the capability of the ESP32 and
Blynk for remote motor control applications, which can find applications in robotics,
automation systems, and various DIY projects.

29
IOT (3173215) En.No.: 211310132057

Experiment 8

• Aim: To Interface Stepper Motor with ESP32 using motor driver module to Start and stop
the motor and vary its speed in both directions.

• Equipment Required: 28BYJ-48 Stepper Motor, ESP 32

• Software Required: Arduino IDE

• Circuit Diagram:

Figure 8.1: circuit diagram

• Components:

28BYJ-48 Stepper Motor:

Figure 8.2: 28BYJ-48 Stepper Motor

The 28BYJ-48 is a 5V, 4-phase unipolar stepper motor with a 5.625-degree step angle and
a 1:64 gear reduction. It is commonly used in DIY projects and low-cost applications
requiring controlled rotation, such as robotics and small automation systems, often driven
by a ULN2003 driver board for precise control.

30
IOT (3173215) En.No.: 211310132057

ESP 32:

Figure 8.3: pin-diagram of ESP-32

ESP32 is a series of low-cost, low-power system on a chip microcontroller with integrated


Wi-Fi and dual-mode Bluetooth.

• Code:
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
// ULN2003 Motor Driver Pins #define IN1 19
#define IN2 18
#define IN3 5
#define IN4 17
// initialize the stepper library
Stepper myStepper(stepsPerRevolution, IN1, IN3, IN2, IN4);
void setup()
{
// set the speed at 5 rpm
myStepper.setSpeed(5);
// initialize the serial port
Serial.begin(115200);
}
void loop()
{
// step one revolution in one direction: Serial.println("clockwise");
myStepper.step(stepsPerRevolution); delay(1000);
// step one revolution in the other direction: Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution); delay(1000);
}

31
IOT (3173215) En.No.: 211310132057

• Result and Output:

Figure 8.4: Resultant circuit

• Conclusion:
In this experiment, we successfully interfaced a 28BYJ-48 stepper motor with an ESP32
microcontroller using a motor driver module, enabling us to control the motor's direction and
speed. The 28BYJ-48 stepper motor, known for its 5V operation, 5.625-degree step angle, and
1:64 gear reduction, is commonly employed in cost-effective automation and DIY projects. By
utilizing the Arduino IDE and the Stepper library, we programmed the ESP32 to rotate the
motor in both clockwise and counterclockwise directions at a speed of 5 revolutions per minute.
This experiment serves as a foundational step for integrating stepper motors into various
applications, particularly those involving precision movement and automation within the IoT
realm, given the ESP32's capabilities.

32
IOT (3173215) En.No.: 211310132057

Experiment 9

• Aim: To Interface LED on ESP32 and control it with the help of Blynk App.

• Equipment Required: LED, ESP32

• Software Required: Arduino IDE, Blynk Library

• Circuit Diagram:

Figure 9.1: circuit diagram

• Components:

LED:

Figure 9.2: LED

LED stands for light-emitting diode. LEDs are semiconductor devices that emit light when
anelectric current passes through them.

ESP32:

Figure 9.3: pin-diagram of ESP-32

33
IOT (3173215) En.No.: 211310132057

ESP32 is a series of low-cost, low-power system on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

Blynk Library:
1) Open Arduino IDE
2) Select tool menu
3) Click on manage libraries

Figure 9.4:

4) Search Blynk
5) Install Blynk Library by Volodymyr

Figure 9.5:

34
IOT (3173215) En.No.: 211310132057

Setup Blynk Web App:


1) Create new template:

Figure 9.6: creating new template

2) Add a data stream with digital pin 13 range from 0 to 1

Figure 9.7: Adding Data Stream

3) Add slider widget and get the meta data of the template for the code

Figure 9.8: Adding Slider Widget

35
IOT (3173215) En.No.: 211310132057

4) Create new device and select the led blink template

Figure 9.9: Creating new device

5) Select the device and control

Figure 9.10: Selecting Device Control

• Code:
#define BLYNK_PRINT Serial /* include Blynk Serial */
#include <WiFi.h> /*ESP32 WiFi Library*/
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "TMPL3ZsXlzc5B" #define
BLYNK_TEMPLATE_NAME "led blink"
// Enter device Authentication Token
char auth[] ="wAaG9sfTFfOA3QJ5xZhnszIS5on4syfP";
//Enter your WIFI SSID and password char ssid[] = "YOUR WIFI NAME";
char pass[] = "abcd@1234";
void setup(){
Serial.begin(9600); /*Baud rate for serial communication*/
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
void loop()
{
Blynk.run();
}

36
IOT (3173215) En.No.: 211310132057

• Result and Output:

Figure 9.11: Resultant Circuit

• Conclusion:
In this experiment, we successfully interfaced an LED with an ESP32 microcontroller and
controlled it using the Blynk app. By creating a Blynk template with a digital pin and switch
widget, we were able to remotely turn the LED on and off, demonstrating the capability of
ESP32 and Blynk for simple IoT applications. This project showcases the ease of
integrating hardware with the Blynk platform for remote control and monitoring, which can
find applications in home automation and DIY electronics projects.

37
IOT (3173215) En.No.: 211310132057

Experiment 10

• Aim: To Interface Buzzer on ESP32 kit and control the on off timing from the code.

• Equipment Required: passive Buzzer KY-006, ESP32

• Software Required: Arduino IDE

• Circuit Diagram:

Figure 10.1: Circuit Diagram

• Components:

Passive Buzzer KY-006

Figure 10.2: KY-006 Passive Piezoelectric Buzzer

The KY-006 Passive Piezoelectric Buzzer module can produce a range of sound tones
depending on the input signal frequency.
This module consists of a passive buzzer and 3 male header pins. You can use it generate
tones between 1.5 to 2.5kHz by switching it on and off repeatedly at different frequencies
either using delays or PWM.

ESP32:

Figure 10.3: pin-diagram of ESP-32

38
IOT (3173215) En.No.: 211310132057

ESP32 is a series of low-cost, low-power system on a chip microcontroller with


integrated Wi-Fi and dual-mode Bluetooth.

• Code:
int buzzerPin = 13;
void setup()
{
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Turn on the buzzer for 1 second
tone(buzzerPin, 1000); // 1000 Hz tone delay(1000);
noTone(buzzerPin); // Turn off the buzzer
delay(1000); // Wait for 1 second
}

• Result and Output:

Figure 10.4:Resultant Circuit

• Conclusion:
In this experiment, we successfully interfaced a passive buzzer with the ESP32
microcontroller and controlled its on-off timing using the Arduino code. The buzzer
produced an audible tone at a frequency of 1000 Hz, turning on for 1 second and then
turning off for 1 second in a continuous loop. This experiment demonstrates how to
generate simple sound patterns using an ESP32 and a passive buzzer, which can be used in
applications like alarms, notifications, or simple musical compositions.

39

You might also like