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

IoT Lab Manual

Uploaded by

praburam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

IoT Lab Manual

Uploaded by

praburam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 138

1

THE OFFICAIL ACENAAR TECHNOLOGIES


INTERNET OF THINGS TRAINER KIT-Model-B GUIDE

ACENAAR TECHNOLOGIES
IoT trainer Kit-MODEL-B

20A05603P IoT Lab Manual

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


2

Get started with


ACENAAR TECHNOLOGIES
IoT trainer Kit-Model-B

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


3

Welcome
The developments in Internet of Things (IoT) technology played a pivotal role in
spurring innovation and growth. It is a technological revolution and it is bringing
tremendous changes in socioeconomics. And it is occupying omni fields like home
automation, transport, agriculture and whatnot. IoT technology has demand for very huge
skillful manpower in near feature and apart from this, everyone needs to know about this
technology. As it is going to become the integral part of life. This technology fascinates
everyone to learn and use for self-empowerment and to utilize prospects of modern life
style of 21st century.
In the manual we are presenting programming procedure for resourceful
unequivocally designed IoT trainer kit. Special care is taken to keep instruction simple and
clear and yet cover utilization of all resources available in the kit.

In present manual we will focus on 20A05603P (JNTUA-CSE) IoT Lab Manual, which
gives information about getting started with Kit, and write Internet of Things (IoT) C++
programs for different resources of kit (Displays, Actuators, sensors and wireless
connectivity modules). At the end of the exercise, one will acquaint with kit and have
confidence to develop the IoT programs.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


4

CONTENT
JNTUA-ATP: B.Tech. (CSE)-III-I 20A05603P – INTERNET OF THINGS LAB

GETTING STARTED Get to know about your IoT Trainer Kit-Model-B20:


Know-how and getting started with your Acenaar Technology IoT
Trainer Kit -Model-E. Learn to initialize and program

s.no Experiments

ESP32 EXPERIMENTS……………………………………………………………………………………………………………

1 EXPERIMENT-1(a) Controlling Actuators through serial monitor.

Experiment-1(b) Creating different LED patterns and controlling them using Push
button switches.
Experiment-1(c) Controlling servo motor with help of joystick.

2 EXPERIMENT-2 Calculating distance to an object with help of an ultrasonic


sensor and display it on LCD.
3 EXPERIMENT-3(a) Controlling actuators relay state based on ambient light level
using LDR sensor.

Experiment-3(b) Basic Burglar alarm security system with the help of PIR sensor
and buzzer.
Experiment-3(c) Displaying humidity and temperature values on LCD.

Raspberry Pi EXPERIMENTS…………………………………………………………………………………………………..

4 EXPERIMENT-4 (a) Controlling relay state based on input from IR.

EXPERMENT-4(b) Interfacing stepper motor with R-Pi.

EXPERIMENT-4(c) Advanced burglar alarm security system with help of PIR sensor,
buzzer and keypad.
EXPERIMENT-4(d) Automated LED light control based on input from PIR and LDR.

IoT Framework………………………………………………………………………………………………………………………

5 EXPERIMENT-5 Upload humidity and temperature data to ThingSpeak,


Powered by AcenAAr Technology Pvt. Ltd. Kurnool
5

periodically logging ambient level to ThingSpeak.


6 EXPERIMENT-6(a) Controlling LEDs using Blynk App
EXPERIMENT-6(b) Controlling Relay using Blynk App:
EXPERIMENT-6(c) Controlling buzzer using Blynk App:

HTTP based…………………………………………………………………………………………………………………………
7 EXPERIMENT-7 (a) Introduction to HTTP, hosting a basic server from the ESP32 to
control various digital based actuator LED from a simple web-
page:
EXPERIMENT-7 ( b) Introduction to HTTP, Hosting a basic server from the ESP32 to
control various digital based actuator Buzzer from a simple web-
page:
EXPERIMENT-7 ( c) Introduction to HTTP, Hosting a basic server from the ESP32 to
control various digital based actuator Relay from a simple web-
page:
8 EXPERIMENT-8 Displaying various sensor readings on a simple web page hosted
on the ESP32:

MQTT based…………………………………………………………………………………………………………………………

9 EXPERIMENT-9(a) Controlling actuators LEDs/Motors using android App: Step-1:


Develop MIT Android App to send digital data through
Bluetooth.
EXPERIMENT-9(b) Controlling AC appliances from an Android APP with the help of
relay:
10 EXPERIMENT-10 Displaying humidity and temperature data on a web based
application:

UAV/Drone…………………………………………………………………………………………………………………………….

11 EXPERIMENT-11(a) Demonization of UAV elements, flight controller


EXPERIMENT-11(b) Mission planner flight planning design

12 EXPERIMENT-12 Write Python program to read GPS coordinates from flight


controller

Appendices:
Appendix A: Esp32 board specifications.
Appendix B: Get fully acquainted with Raspberry pi and Thonny IDE.
Appendix C: Get fully acquainted with Blynk APP Installation.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


6

IoT Arduino (C++) programming


GETTING STARTED: Get to know about your IoT Trainer Kit-Model-B
Know-how and getting started with your Acenaar Technology IoT
Trainer Kit -Model-B. Learn to initialization of IDEs and first program.
In recent years Learning methods are shifting from conventional class room methods to more
independent methods like self-learning and particularly Do It Yourself (DIY) methods. Acenaar
Technologies IoT trainer Kit-Model-B is source for such an excellent opportunity for leaning. This
trainer Kit is well-organized for easy understanding and user friendly IoT trainer Kit. The aim of developing
this kit is to reach maximum number of Students with minimum human support.

This IoT Trainer kit is consisting Arduino Microcontroller, Raspberry Pi, sensors, activators, display
units and wireless connectivity modules in single board. It works with embedded C++ in open software
Arduino IDE.

Salient features of the IoT trainer kit-Model-B:


S.no Name of unit Particulars of devices
1 Ultrasonic sensor
2 PIR sensor
3 DHT temperature and Humidity sensor
1 SENSOR UNIT 4 IR sensor
5 LDR sensor
6 Key board
7 Air quality sensor
8 Stepper Motor
9 Servo Motor
2 ACTUATORS UNIT 10 Relays
11 Buzzer
12 LCD screen
3 DISPLAY UNIT 13 Seven segment display
14 LEDs (logic controller)
15 RGB led
4 WIRELESS CONNECTIVITY 16 ESP8266 wi-fi module
UNIT 17 Bluetooth module
5 CONTROL UNIT 18 Arduino Nano with extended connectors
19 Raspberry pi-4 B with 2 GB RAM
20 Esp32 IOT module
6 MISCELLANEOUS 21 400 Points Solderless Breadboard

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


7

A guided view of Acenaar Technologies IoT trainer Kit-Model-B


Acenaar Technologies IoT trainer kit-Model-B is consisting of Several important blocks
which are shown in figure-1 they are Control Unit, Sensor Unit, Actuator Unit, Display Unit,
Wireless Connectivity Unit and Miscellaneous. Figure-2 shows the control unit, GPIO
connectors, micro-USB and C-type power supply connectors. For Japan Solderless Terminal (JST)
Connectors 1 to 13 numbering and respective sensors names are given. Apart from these TWO male
burg connectors are provided for general purpose applications. Figure -3 shows the sensors unit. It
consists of SIX SENSORS F-IR sensor, G-PIR sensor, I-DHT11 sensor, H- Ultrasonic sensor, L-LDR
sensor, M-Keypad, further Air quality and TDS meter at bottom side are in figure-8. Figure-4
shows the ACTUATOR UNIT. It consists of THREE ACTUATORS A-Servo motor, B-Relay and C-
Buzzer. Figure-5 shows the DISPLAY UNIT. It consists of FOUR DISPLAY UNITS O- 2x16 LCD, K-
TM1637 seven segment display, J-Eight LEDs and N-RGB LED. Figure-6 shows the wireless
connectivity unit. It consists of TWO Connectivity units D-Wi-Fi module, E-Bluetooth module. In
Miscellaneous, 400 Points Solderless Breadboard is also provided on kit for General purpose
programming applications which is shown in figure-7. Apart form this Raspberry Pi 4 with
Extended GPIO compactable board also available.

NOTE: 1) Proper attention is needed While connecting wire cables.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


8

Figure – 5: Display unit present in kit.

Figure-3: sensor components present in kit.

Figure – 6: WIRELESS CONNECTIVITY UNIT

Figure -4: Activators Components present


in kit.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


9

Figure-7: sensor board control unit 2-Esp32

Figure-8: Raspberry pi

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


10

Getting started first program with IoT trainer


kit-Model-B
Get fully acquainted with IoT trainer kit-Model-B, Arduino IDE and get
started first program.
To start the IoT programming with IoT trainer kit you need to follow step by step procedure which
is given below.
STEP-1: POWER ON the Main power switch by sliding right side on the kit after connecting
power supply to USB C-Type/Micro USB power connector. (Observe POWER LED ON)

Step-2: Connect one end of Micro USB cable to Esp32 board and other end connect to PERSONAL
COMPUTER or LAPTOP port USB-2.0/3.0.

STEP-3: Install Arduino IDE and libraries in PC/Laptop from software folder provided in CD
(windows OS is taken as reference in this entire guide). Or Install Arduino IDE from
https://www.arduino.cc/en/software

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


11

Step-4: Installing ESP32 Board in Arduino IDE

1.open the Arduino IDE and go to File -> Preferences option.

2.A new window pops up. Near the end, there is an option called “Additional Boards Manager URLs”. In
the space next to this option, paste the following URL and click on OK

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-
pages/package_esp32_index.json

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


12

NOTE: You can add multiple URLs by separating with commas.


3.After adding the URL, you are now ready to install the ESP32 boards in Arduino IDE. Go
to Tools -> Board -> Boards Manager. . . option. A Boards Manager window will pop-up.

4.In the search bar on the top, type “esp32” and hit enter. You will get a result saying “esp32 by Espressif
Systems”. Select this and click on install button. Arduino IDE will now download all the necessary files for
ESP32 like boards, tools, programmer etc., from the internet.

Make sure your computer has internet connectivity. This might take a minute or two. Once the
installation is successful, you can close the Boards Manager.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


13

Step-5: Selecting ESP32 Development Board


Now, in order to write programs for ESP32 boards, you have to first select the right board (the
board which you have). To do this, once again go to Tools -> Board. You can see a new option
called ESP32 Arduino added to the list of boards

Go into tools> Board> Esp32 Arduino> DOIT ESP32 DEVKIT V1

Step-6: for port selection Tools->Port-> com port for port selection.

For Arduino COM port selection

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


14

STEP-5: To test the Esp32 and IDE installed, go to FILE -> example-> Basic -> Blink example.,
compile it and upload code by tap upload button. Observe Built-in LED Blinking on Esp32 board.
If you could see LED blinking on Esp32 board, congratulations you have Successfully installed IDE
and configured your board for programming.

For Blink example.

Result:

Step-6: Install libraries (only once) as per the requirements of the experiment ( DHT-11 sensor,
LDC, 7segment, Wi-Fi, Keypad library,MQ135,TDS grove. Etc).

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


15

Note-1: Manually install USB-serial CH324 drivers for Arduino nano for Windows7 and 8.
Note-2: For further more information/ video content visit Acenaar Technology web site and
you tube channel.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


16

Experiment-1
Controlling Actuators through serial monitor: Write C++
program for ESP32 Microcontroller to control Buzzer through serial
monitor

What is a Buzzer?

An audio signalling device like a beeper or buzzer may be


electromechanical or piezoelectric or mechanical type. The main function
working of this is to convert the electrical signal to sound. Generally, it is
powered through DC voltage and used in timers, alarm devices, printers,
computers, etc.

Buzzer Pin Configuration

The pin configuration of the buzzer is shown below. It includes two pins namely positive and
negative. The positive terminal of this is represented with the ‘+’ symbol or a longer terminal.
This terminal is powered through 6Volts whereas the negative terminal is represented with the
‘-‘symbol or short terminal and it is connected to the GND terminal.

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP32 Control unit


Development
board

2. BUZZER Sound buzzer Buzzer (C)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


17

3. connecting wires one - 4 port JST


connecting wires

About the Experiment -


Here we connect the Buzzer on the Acenaar IOT trainer kit and control using the HIGH and LOW
commands.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: Connect the Buzzer module (C) to the ESP32 IoT Module
“GPIO”.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller to control
Buzzer through serial monitor *****************
* Experiment : Exp_01(a) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to IoT Kit Buzzer (C). ******
**************************************************************************************************/
#define Buzzer 19

void setup() {
Serial.begin(9600);
pinMode(Buzzer, OUTPUT); // set the digital pin as output:
}

void loop() {
if (Serial.available())
{
String command = Serial.readStringUntil('\n');
int myInt = command.toInt();
Serial.println(myInt);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


18

if (myInt== 1)
{
digitalWrite(Buzzer, HIGH); // turn on LED
Serial.println("Buzzer ON");
}
else if (myInt == 0)
{
digitalWrite(Buzzer, LOW); // turn off LED
Serial.println("Buzzer OFF");
}
}
}

Result-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


19

Experiment-1(b)
Creating different LED patterns and controlling them using
Push button switches:
Write C++ program for ESP32 Microcontroller to display
different patterns using LEDs on Kit.
What Exactly is an LED?
An LED is a type of diode that turns electrical energy into light. Basically, an LED is an electrical
component that emits light when electricity flows through in one direction. LED is an acronym standing
for ‘Light Emitting Diode’. 5mm LEDs also run at much lower drive currents, maxing out at around 30mA.
LEDs emits the different colours. The symbol and model is given below.

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 ESP-32


Development
board

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


20

2. 8 LEDs 8 LEDs connected Logic (J)


through resistors

4. Keypad 4x3 Matrix keypad keypad (M)

3. connecting wires one - 10 port, One 4 pin JST


connecting wires

About the Experiment - Here we control the 8 LEDS present on the kit by using the
Push buttons.

Interfacing on AcenAAr IOT trainer kit-


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the logic (J) to the ESP-32 Module “LEDS”.
Connect the logic (M) to the ESP-32 Module “keyboard”.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller to display
different patterns using LEDs on Kit. *****************
* Experiment : Exp_01(b) *****************
* Connecting Wires : One 4 pin, one - 10 port JST Connecting Wire*****************
* Connections : Esp-32 (LEDs) to Connector->logic(J) *****************
* Esp-32 (Keypad) to Connector -> keypad(M) ***************
Powered by AcenAAr Technology Pvt. Ltd. Kurnool
21

**************************************************************************************************/
#include <Keypad.h>

const byte ROWS = 4; //four rows


const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {32, 33, 25, 26}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {27, 14, 12}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int pins[8] = {15,2,4,16,17,5,18,19};


int counterValue = 1;
int rightShiftValue = 0;
int andMask;
int extractLSB;
int n = 0;

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

for(int ii = 0; ii < 8; ii++)


pinMode(pins[ii], OUTPUT);
allOff();
}

void loop() {
char key = keypad.getKey();
if (key){
Serial.println(key);
switch(key){
case '1':
allOn();
break;
case '2':
allOff();
break;

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


22

case '3':
allOff();
for(int ii = 1; ii <= 5;ii++)
blinkAll();
break;
case '4':
allOff();
for(int ii = 1; ii <= 5; ii++)
ledWalk();
break;
case '5':
allOff();
binaryCounter();
break;
}
}
}

void allOff()
{
for(int ii = 0;ii < 8; ii++){
//rightShiftValue = counterValue >> ii;
// extractLSB = rightShiftValue & 0x1;
//if(extractLSB == 1)
//digitalWrite(pins[ii], 0);
//else
digitalWrite(pins[ii], 1);
}
}

void allOn()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 0);
}
}

void blinkAll()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 1);
}
delay(500);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


23

for(int ii = 0;ii < 8; ii++){


digitalWrite(pins[ii], 0);
}
delay(500);
}

void ledWalk()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 0);
delay(70);
}
for(int ii = 0;ii < 8; ii++){
delay(70);
digitalWrite(pins[ii], 1);
}
}

void driveCounter(int counterValue)


{
int rightShiftValue, extractLSB;
for(int ii = 0;ii < 8; ii++){
rightShiftValue = counterValue >> ii;
extractLSB = rightShiftValue & 0x1;
if(extractLSB == 1)
digitalWrite(pins[ii], 0);
else
digitalWrite(pins[ii], 1);
}
}
void binaryCounter()
{
for(int ii = 1; ii <= 255; ii++){
driveCounter(ii);
delay(100);
}
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


24

RESULT-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


25

EXPERIMENT-1(c)
Controlling servo motor with help of joystick:

Write C++ program for ESP32 Microcontroller to control servomotor


using Joystick as INPUT device.

JOY STICK:
A joystick is an input device that can be used for controlling the movement of the cursor or a
pointer in a computer device. The pointer/cursor movement is controlled by a lever on the
joystick. The input device is mostly used for gaming applications and, sometimes, in graphics
applications. A joystick also can be helpful as an input device for people with movement
disabilities.

The joystick is mostly used when there is a need to perform a direct pointing or
when a precise function is needed. There are different types of joysticks such
as displacement joysticks, hand-operated joysticks, finger-operated joysticks,
thumb/fingertip-operated joysticks, hand-operated isometric joysticks, etc.

SERVO MOTOR:

The servo motor is an assembly of four things: a normal DC motor, a gear reduction unit, a
position-sensing device, and a control circuit The DC Servo motor is connected with a gear
mechanism that provides feedback to a position sensor which is mostly a potentiometer.

Servo Motor consists of a DC Motor, a Gear system, a position sensor, and


a control circuit. The Gear and shaft assembly connected to the DC motors
lower this speed into sufficient speed and higher torque. The position
sensor senses the position of the shaft from its definite position and feeds
the information to the control circuit. The control circuit accordingly
decodes the signals from the position sensor and compares the actual
position of the motors with the desired position and accordingly controls the direction of rotation
of the DC motor to get the required position. Servo Motor generally requires a DC supply of 4.8V
to 6 V.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


26

List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. Joystick 2-AXIS Button 2 Axis Button (L)


Joystick

3. Servo motor Servo(A)

3. connecting wires one - 4 port & one 10 port JST


connecting wires

About the Experiment -


Here we control the servo motor using the 2-axis joystick button as an input to the MCU.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


27

• Connection of the peripherals: Connect the (X3) to the ESP-32 Module “ADC”.
Connect the Servo (A) to the ESP-32 Module “Ultrasonic”.

Sample code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller to control
servomotor using Joystick as INPUT device. *****************
* Experiment : Exp_01(c) *****************
* Connecting Wires : One 4 pin, JST Connecting Wire *****************
* Connections : Esp-32 (Ultra) to Connector servo(A) *****************
* Esp-32 (ADC) to Connector joystick(X3) *****************
***************************************************************************************************/
#define joyX 34
#define joyY 33
#include <Servo_ESP32.h>

static const int servoPin = 23;

Servo_ESP32 servo1;
int pos=0;
int xValue,yValue;

void setup() {
Serial.begin(115200);
Serial.println("Joy Stick in IDLE State");
servo1.attach(servoPin);
}

void loop()
{
xValue = analogRead(joyX);
yValue = analogRead(joyY);
Serial.print(xValue);
Serial.println(yValue);

if(yValue == 0 && xValue < 3200 )


{
for (pos = 180; pos >= 0; pos -= 1)
{
servo1.write(pos);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


28

delay(20);
Serial.println("Right!!!");
}
}
else if(xValue == 0 && yValue <= 3000)
{
Serial.println("Up!!!");
}
else if(xValue <= 400 && yValue ==4095)
{
for (pos = 0; pos <= 180; pos += 1)
{
servo1.write(pos);
delay(20);
Serial.println("Left!!!");
}
}
else if(xValue == 4095 && yValue == 4095){
Serial.println("Down!!!!");
}else{
Serial.println("Idle State");
}
delay(1000);
}

RESULT-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


29

EXPERIMENT-2
Calculating distance to an object with help of an ultrasonic
sensor and display it on LCD:
Write C++ program for ESP32
Microcontroller to measure distance of an object with help of
Ultrasonic sensor and display it on LCD.

Ultrasonic:
This is a simple and easy to use ultrasonic sensor. It can detect objects Infront
of it within a range of 2-400cm. It is the perfect sensor to use in robotics,
obstacle detection, etc. It has a wide beam angle unlike IR Sensors, which
enables it to detect obstacles withing a wide angle. Signals can be read from
the 4-pin interface (Vcc, Trig, Echo, Gnd). One pin is used to trigger the
ultrasonic transmitter and another one is used to read the echo. This HC SR04
distance sensor offers both accuracy and stable readings that is not affected
by sunlight or object colour.

Liquid Crystal Display


LCD (Liquid Crystal Display) is a type of flat panel display which uses liquid crystals in its
primary form of operation. LEDs have a large and varying set of use cases for consumers and
businesses, as they can be commonly found in Smartphone’s, televisions, computer monitors
and instrument panels.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


30

List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. Ultra-Sonic Sonic Sensor ULTRA SONIC


Sensor HC SRO4 SENSOR(H)

3. LCD Display JHD 162A Display Unit(O)

4. connecting wires two - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


31

About the Experiment -


Here we use ESP32 Microcontroller present on Acenaar IOT KIT to measure distance of an
object with help of Ultrasonic sensor and display it on LCD.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: 1. Connect the Ultrasonic sensor (H) to the ESP32 IoT
Module "Ultrasonic".
2. From Acenaar IoT Kit Display Module(O) to ESP32 IoT
Module "LCD".

Sample code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller to
measure distance of an object with help
of Ultrasonic sensor and display it on LCD. **********
* Experiment : Exp_02 *****************
* Connecting Wires : Two 4 pin JST Connecting Wires *****************
* Connections : 1. From ESP32 IoT Module "Ultra"
to Acenaar IoT Kit Ultrasonic(H). ***********
* 2. From ESP32 IoT Module "LCD" to
Acenaar IoT Kit Display Unit(O). **********
***************************************************************************************************/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16,2);

#define echoPin 39 // attach pin D5 Arduino to pin Echo of HC-SR04


#define trigPin 23 //attach pin D4 Arduino to pin Trig of HC-SR04

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
void setup() {
lcd.init();
lcd.backlight();
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Powered by AcenAAr Technology Pvt. Ltd. Kurnool
32

}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
lcd.setCursor(0, 0);
lcd.print("Distance:");
lcd.setCursor(9,0);
lcd.print(distance);
lcd.setCursor(13,0);
lcd.print("CM");
delay(500);
lcd.clear();
}

RESULT-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


33

EXPERIMENT-3(a)
Controlling actuators relay state based on ambient light level
using LDR sensor:
Write C++ program for ESP32 Microcontroller to
switch ON/OFF Relay based on ambient light intensity level
sensed using LDR sensor.
Relay:
Relays are most commonly used switching devices used in electronics. It can be used to switch
high current loads easily unlike transistors which are limited by the maximum current that can
flow through them and also can’t switch AC loads. This 5V 1A Relay
Module can switch both AC and DC loads. It is an Electromagnetic switch,
when the coil inside is energized with a small current, it can switch ON or
OFF the high current circuit. It has PCB screw terminals to directly
connect. They can be used in Home automation to switch ON or OFF the
appliances, in Electronic circuits to perform switching operations, in
safety circuits to disconnect or connect the heavy loads in case of any
dangerous situation, in Automobile applications like turning on
windscreen wipers, power windows fuel pump, cooling fan etc.

LDR sensor-
An LDR or light dependent resistor is also known as photo resistor, photocell, photoconductor. It
is a one type of resistor whose resistance varies depending on the amount of light falling on its
surface. When the light falls on the surface, then the resistance changes. When the LDR is in
darkness, then it can be used to turn ON a light or to turn OFF a light when it is in the light. A
typical light dependent resistor has a resistance in the darkness of 1 M Ohm, and in the brightness
a resistance of a couple of 1K Ohm. Symbol and example is given below.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


34

Experiment-

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2 LDR module Light dependent LDR(L)


Resistor

2. Relay HEJQC3FC RELAY(B)

3. connecting wires two - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


35

About the Experiment -


Here we control Relay switch (ON/OFF) based on ambient light intensity level using LDR sensor.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: 1. From ESP32 IoT Module “ADC” to Acenaar IoT Kit LDR(L)
2. From ESP32 IoT Module “GPIO” to Acenaar IoT Kit
RELAY(B)
3.from Esp32 IOT Module “LCD” to Acenaar IOT kit
Display unit (O)

Sample code-
/**************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32
Microcontroller to switch ON/OFF Relay
* based an ambient light intensity level
sensed using LDR sensor. *****************
* Experiment : Exp_03(a) *****************
* Connecting Wires : Two 4 pin JST Connecting Wires *****************
* Connections : 1. From ESP32 IoT Module “ADC”
to Acenaar IoT Kit LDR(L). **********
* 2. From ESP32 IoT Module “GPIO”
to Acenaar IoT Kit RELAY(B). ************
3. from Esp32 IOT Module “LCD”
to Acenaar IOT kit Display unit (O). ************
***************************************************************************************************/
#define Relay 19
#define LIGHT_SENSOR_PIN 34 // ESP32 pin GIOP36 (ADC0)
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);

void setup() {
// initialize serial communication at 9600 bits per second:
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(Relay,OUTPUT);
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


36

void loop() {
// reads the input on analog pin (value between 0 and 4095)
int analogValue = analogRead(LIGHT_SENSOR_PIN);

Serial.print("Analog Value = ");


Serial.print(analogValue);// the raw analog reading
lcd.print("Light Intensity");
lcd.setCursor(0,1);
lcd.print(analogValue);

// We'll have a few threshholds, qualitatively determined


if (analogValue < 500)
{
Serial.println(" Relay ON");
digitalWrite(Relay,LOW);
}
else
{
Serial.println(" Relay OFF");
digitalWrite(Relay,HIGH);
}
delay(1000);
lcd.clear();
}

RESULT-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


37

EXPERIMENT-3(b)
Basic Burglar alarm security system with the help of PIR
sensor and buzzer:
Write C++ program to implement ESP32 based
Basic Burglar alarm security system with help of PIR sensor
and Buzzer.
Passive Infrared Sensor (PIR):
PIR sensors allow you to sense motion, almost always used to detect whether a human has
moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and
don't wear out. For that reason, they are commonly found in appliances and gadgets used in
homes or businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR
motion" sensors.

Experiment:
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP32 Control unit


Development
board

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


38

2. BUZZER Sound buzzer Buzzer (C)

3. PIR-Sensor HC SR501 PIR(G)

4. connecting wires two - 4 port JST


connecting wires

About the Experiment -


Here we use a buzzer indicator as an output to the module when we get the input of the PIR
senor is high.

Interfacing AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: 1. From ESP32 IoT Module “ADC” to Acenaar IoT Kit PIR(G)
2. From ESP32 IoT Module “GPIO” to Acenaar IoT Kit
Buzzer(C)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


39

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program to implement ESP32
based Basic Burglar alarm security system
with help of PIR sensor and Buzzer. ***************
* Experiment : Exp_03(b) ****************
* Connecting Wires : Two 4 pin JST Connecting Wires ****************
* Connections : 1. From ESP32 IoT Module “ADC” to
Acenaar IoT Kit PIR(G). **********
* 2. From ESP32 IoT Module “GPIO” to
Acenaar IoT Kit Buzzer(C). ************
***************************************************************************************************/
const int Buzzer =19; // the pin that the LED is atteched to
const int sensor = 34; // the pin that the sensor is atteched to

int val = 0; // variable to store the sensor status (value)

void setup() {
pinMode(Buzzer, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}

void loop(){
val = digitalRead(sensor); // read sensor value
Serial.println(val);
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(Buzzer, HIGH); // turn LED ON
Serial.println("Motion detected!");
delay(1000);
}
else {
digitalWrite(Buzzer, LOW);
Serial.println("Motion Not detected!");// turn LED OFF
delay(1000); // delay 200 milliseconds

}
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


40

Result-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


41

EXPERMENT-3(c)
Displaying humidity and temperature values on LCD:
Write C++ program for ESP32
Microcontroller to measure humidity and temperature and
display on LCD.
DHT-11
The DHT11 is a commonly used Temperature and humidity sensor that comes with a dedicated
NTC to measure temperature and an 8-bit microcontroller to output the values of temperature
and humidity as serial data.

For DHT11 Sensor module

1 Vcc Power supply 3.5V to 5.5V

2 Data Outputs both Temperature and Humidity through serial Data

3 Ground Connected to the ground of the circuit

DHT11 Specifications

• Operating Voltage: 3.5V to 5.5V


• Operating current: 0.3mA (measuring) 60uA (standby)
• Output: Serial data
• Temperature Range: 0°C to 50°C
• Humidity Range: 20% to 90%
• Resolution: Temperature and Humidity both are 16-bit
• Accuracy: ±1°C and ±1%

Note: Complete technical details can be found in the DHT11 datasheet

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


42

Applications

• Measure temperature and humidity


• Local Weather station
• Automatic climate control
• Environment monitoring

Liquid Crystal Display


LCD (Liquid Crystal Display) is a type of flat panel display which uses liquid crystals in its
primary form of operation. LEDs have a large and varying set of use cases for consumers and
businesses, as they can be commonly found in Smartphone’s, televisions, computer monitors
and instrument panels.

Experiment:

List of components

1. Arduino nano Arduino Nano Control


unit
Development
board

2. DHT-11 module DHT 11 Sensor DHT 11(I)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


43

3. Display Unit JHD 162A Display unit (O)

4. connecting wires Two - 4 port JST


connecting wires

About the Experiment -


Here we measure the Temperature and the Humidity using the DHT-11 sensor and represent
the values on the Display unit LCD.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT Module available on Acenaar IoT kit, and
UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: 1. From Acenaar IoT Kit Display Unit(O) to ESP32 IoT
Module "LCD".
2. From ESP32 IoT Module "GPIO "to Acenaar IoT Kit "DHT
11"(I).

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32
Microcontroller to measure humidity
* and temperature and display on LCD. *****************
* Experiment : Exp_03(c) *****************
* Connecting Wires : Two 4 pin JST Connecting Wires *****************
* Connections :1. From Acenaar IoT Kit "Display Unit(O)" to
ESP32 IoT Module "LCD" **********
* 2. From ESP32 IoT Module "GPIO " to
Acenaar IoT Kit "DHT 11"(I). *************
***************************************************************************************************/

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


44

#include "DHT.h"
#define DHTPIN 19 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16,2);

void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

float humidity = dht.readHumidity();


// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
lcd.setCursor(0,0);
lcd.print("Temp");
lcd.setCursor(5,0);
lcd.print((char)223);
lcd.setCursor(6,0);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


45

lcd.print("C");
lcd.setCursor(9,0);
lcd.print("Humi %");
lcd.setCursor(0,1);
lcd.print(temperature);
lcd.setCursor(9,1);
lcd.print(humidity);

}
Result-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


46

EXPERIMENT-4 (a)
Controlling relay state based on input from IR:
Write Raspberry-Pi based Python program
to control relay state using IR sensor.

Experiment-
List of components

Sno Component Description Port Names Board

1. Raspberry Pi Rpi-4 Model-B Traffic

2 IR MODULE LM 393 IR(F)

3. Relay HEJQC3FC RELAY(B)

3. connecting wires two - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


47

About the Experiment -


Here we control the Relay switch present on the IOT kit by using the input signals of the IR
sensor.
Interfacing the 8 LEDs Available on AcenAAr IOT trainer kit-

• To connect Raspberry PI see Appendix B.


• Connect the following connections and run the code in Thonny Python IDE.
• Connection of the peripherals: 1. From RPI GPIO Board "j56" to IR (F)
2. From RPI GPIO Board “UART 2” to Relay (B)

#*************************************************************************************************
#* AcenAAr Mini IoT Trainer Kit 2021 ********
#* Program Name : Write Raspberry-Pi based Python program to
#* control relay state using IR sensor. ********
#* Experiment : Exp_04(a) ********
#* Connector : two-4-pins JST cables ********
#* Connections : From RPI GPIO Board "j56" to IR (F) ********
#* From RPI GPIO Board “UART 2” to Relay (B). ********
#************************************************************************************************

import RPi.GPIO as IO
import time
IO.setwarnings(False)
IO.setmode(IO.BCM)
IRPin = 18
RelayOut= 14
IO.setup(IRPin, IO.IN) #GPIO 18 -> IR sensor as input
IO.setup(RelayOut, IO.OUT)

try:
while True:
if(IO.input(IRPin)==True):
print("Object is far away")
IO.output(RelayOut,IO.LOW)
print("Relay OFF")

elif(IO.input(IRPin)==False):
print("Object is near")
IO.output(RelayOut,IO.HIGH)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


48

print("Relay ON")
time.sleep(1)
except KeyboardInterrupt: # Press 'Ctrl+C' To Stop The Program
GPIO.cleanup()

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


49

EXPERMENT-4(b)
Interfacing stepper motor with R-Pi:
Write Raspberry-Pi based Python program to
rotate stepper motor to different angles.

Experiment-
List of components

Sno Component Description Port Names Board

1. Raspberry Pi Rpi-4 Model-B Traffic

2. stepper stepper(A)

3. connecting wires one - 4 port JST


connecting wires

About the Experiment -


Here we Write Raspberry-Pi based Python program to rotate stepper motor to different angles.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


50

Interfacing the 8 LEDs Available on AcenAAr IOT trainer kit-

• To connect Raspberry PI see Appendix B.


• Connect the following connections and run the code in Thonny Python IDE.
• Connection of the peripherals: From RPI GPIO Board "colour" to esp32 board (J21)

Sample code-
#**************************************************************************************************
#* AcenAAr Mini IoT Trainer Kit 2021 ********
#* Program Name :Write Raspberry-Pi based Python program
# to rotate stepper motor to different angles. ********
#* Experiment : Exp_04(b) ********
#* Connector : 10-pins JST cable ********
#* Connections : From RPI GPIO Board "colour" to
esp32 board (J21) ********
#*************************************************************************************************

import RPi.GPIO as GPIO


import time

IN1 = 4 # pin11
IN2 = 5
IN3 = 6
IN4 = 16

def setStep(w1, w2, w3, w4):


GPIO.output(IN1, w1)
GPIO.output(IN2, w2)
GPIO.output(IN3, w3)
GPIO.output(IN4, w4)

def stop():
setStep(0, 0, 0, 0)

def forward(delay, steps):


for i in range(0, steps):
setStep(1, 0, 0, 0)
time.sleep(delay)
setStep(0, 1, 0, 0)
time.sleep(delay)
setStep(0, 0, 1, 0)
time.sleep(delay)
Powered by AcenAAr Technology Pvt. Ltd. Kurnool
51

setStep(0, 0, 0, 1)
time.sleep(delay)

def backward(delay, steps):


for i in range(0, steps):
setStep(0, 0, 0, 1)
time.sleep(delay)
setStep(0, 0, 1, 0)
time.sleep(delay)
setStep(0, 1, 0, 0)
time.sleep(delay)
setStep(1, 0, 0, 0)
time.sleep(delay)

def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Numbers GPIOs by physical location
GPIO.setup(IN1, GPIO.OUT) # Set pin's mode is output
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)

def loop():
while True:
print("backward...")
backward(0.003, 512) # 512 steps --- 360 angle

print("stop...")
stop() # stop
time.sleep(3) # sleep 3s

print("forward...")
forward(0.005, 512)

print("stop...")
stop()
time.sleep(3)

def destroy():
GPIO.cleanup() # Release resource

if __name__ == '__main__': # Program start from here


setup()

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


52

try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child function destroy() will
be executed.
destroy()

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


53

EXPERIMENT-4(c)
Advanced burglar alarm security system with help of PIR
sensor, buzzer and keypad:
Write Raspberry-Pi based Python program to
implement advanced Burglar Alarm with Buzzer Indication.
Use PIR sensor for person detection and key pad to accept
security code.
Experiment-
List of components

Sno Component Description Port Names Board

1. Raspberry Pi Rpi-4 Model-B Traffic

2. BUZZER Sound buzzer Buzzer(C)

3. PIR-Sensor HC SR501 PIR(G)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


54

4. Keypad 4x3 Matrix keypad keypad (M)

5. connecting wires two -4 port JST & one - 10 port JST


connecting wires

About the Experiment -


Here we use a buzzer indicator as an output to the module when we get the input of the PIR
senor is high. and

Interfacing the 8 LEDs Available on AcenAAr IOT trainer kit-

• To connect Raspberry PI see Appendix B.


• Connect the following connections and run the code in Thonny Python IDE.
• Connection of the peripherals: 1. From RPI GPIO Board "j57" to IOT kit PIR (G).
2. From RPI GPIO Board “j58” to IOT kit Buzzer (C).
3. From RPI GPIO Board “Traffic” to IOT Kit Keypad(M).

Sample code-
#**************************************************************************************************
#* AcenAAr Mini IoT Trainer Kit 2021 ********
#* Program Name : Write Raspberry-Pi based Python program to implement
# Advanced Burglar Alarm with Buzzer Indication.
# Use PIR sensor for person detection and key pad to
accept security code ********
#* Experiment : Exp_04(c) ********
#* Connector : two 4-pins JST cable ********
#* Connections : From RPI GPIO Board "j57" to IOT kit PIR (G) ********
#* From RPI GPIO Board “j58” to IOT kit Buzzer (C)
From RPI GPIO Board “Traffic” to IOT Kit Keypad(M). ***
#************************************************************************************************

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


55

import RPi.GPIO as GPIO


import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
Pir =20
Buzzer= 22

Password = "111111"
Pass = ""

R1 = 6
R2 = 7
R3 = 8
R4 = 9

C1 = 10
C2 = 11
C3 = 12

GPIO.setup(Pir, GPIO.IN)
GPIO.setup(Buzzer, GPIO.OUT)

GPIO.setup(R1, GPIO.OUT)
GPIO.setup(R2, GPIO.OUT)
GPIO.setup(R3, GPIO.OUT)
GPIO.setup(R4, GPIO.OUT)

GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)


GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.output(Buzzer,GPIO.LOW)

def readLine(line, characters):


global Pass
GPIO.output(line, GPIO.HIGH)
if(GPIO.input(C1) == 1):
Pass=Pass+characters[0]
print("*",end='')
if(GPIO.input(C2) == 1):
Pass=Pass+characters[1]

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


56

print("*",end='')
if(GPIO.input(C3) == 1):
Pass=Pass+characters[2]
print("*",end='')
GPIO.output(line, GPIO.LOW)
if len(Pass)==6:
if Pass==Password:
print("PassWord Matched")
Pass=""
GPIO.output(Buzzer,GPIO.LOW)
else:
print("Enter Currect PassWord")
Pass=""

try:
while True:
if(GPIO.input(Pir)==True):
GPIO.output(Buzzer,GPIO.HIGH)
readLine(R1, ["1","2","3"])
readLine(R2, ["4","5","6"])
readLine(R3, ["7","8","9"])
readLine(R4, ["*","0","#"])
time.sleep(0.2)
except KeyboardInterrupt:
GPIO.cleanup()
print("\nApplication stopped!")

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


57

EXPERIMENT-4(d)
Automated LED light control based on input from PIR
and LDR: Write Raspberry-Pi based Python program to
implement Automated LED light control system which can detect
presence of person and switch on light based on ambient light Use
PIR sensor for person detection and LDR for Ambient light
measurement.
Experiment-
List of components

Sno Component Description Port Names Board

1. Raspberry Pi Rpi-4 Model-B Traffic

2. Relay HEJQC3FC RELAY(B)

3. PIR-Sensor HC SR501 PIR(G)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


58

4. connecting wires two 4-port JST


connecting wires

About the Experiment -


Here we control two LEDS using the Relay switch activated by the PIR sensor.

Interfacing the 8 LEDs Available on AcenAAr IOT trainer kit-

• To connect Raspberry PI see Appendix B.


• Connect the following connections and run the code in Thonny Python IDE.

Connection of the peripherals: 1. From RPI GPIO Board "j67" to IOT Kit PIR(G).
2. From RPI GPIO Board “j58” To IoT kit Relay(B).

#**************************************************************************************************
#* AcenAAr Mini IoT Trainer Kit 2021 ********
#* Program Name : Write Raspberry-Pi based Python program to
implement Automated LED light control system
which can detect presence of person and switch
on light based on ambient light Use light measurement. ****
#* Experiment : Exp_04(d) ********
#* Connector : 10-pins JST cable ********
#* Connections : 1. From RPI GPIO Board "j67" to IOT Kit PIR(G) ********
From RPI GPIO Board “j58” To IoT kit Relay(B) *******
#*************************************************************************************************

import spidev
import time
import os
import RPi.GPIO as IO

spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=1000000

IO.setwarnings(False)
IO.setmode(IO.BCM)

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


59

Pir = 8
Led1 =23
Led2 =22
IO.setup(Pir, IO.IN)
IO.setup(Led1, IO.OUT)
IO.setup(Led2, IO.OUT)

def ReadChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data

def ConvertVolts(data,places):
volts = (data * 3.3) / float(1023)
volts = round(volts,places)
return volts

light_channel = 0

while True:
if(IO.input(Pir)==True): #object is far away
print("Motion Detected")

if(IO.input(Pir)==False): #object is near


print("Motion Not Detected")
time.sleep(1)
light_level = ReadChannel(light_channel)
print("Light Intensity: {} ".format(light_level))

if ( IO.input(Pir)==True and light_level<=50):


IO.output(Led1,IO.HIGH)
IO.output(Led2,IO.HIGH)
print("LED Light ON")
else:
IO.output(Led1,IO.LOW)
IO.output(Led2,IO.LOW)
print("LED Light OFF")

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


60

Result-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


61

EXPERIMENT-5
Upload humidity and temperature data to ThingSpeak,
periodically logging ambient level to ThingSpeak: Write C++
program for ESP32 Microcontroller to Upload humidity and
temperature data to ThingSpeak, periodically logging ambient level to
ThingSpeak.

Experiment

List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32

2. DHT-11 module DHT 11 Sensor DHT 11(I)

4. connecting wires one - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


62

About the Experiment –


Here we measure the Temperature and the Humidity using DHT-11sensor. we PUSH
values to the cloud (ThingSpeak cloud). It represents the values using the FIELDS in the
Thinkspeak, like a graph format, here we use two fields one for Temperature and one for
Humidity.

Interfacing the DHT-11


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the DHT-11 module (I) to the ESP-32 “GPIO”.

Sample code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to Upload humidity and temperature data
to Thingspeak, periodically logging ambient
level to ThingSpeak *****************
* Experiment : Exp_05 *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit DHT 11 (I). *****************
***************************************************************************************************/
#include <WiFi.h>
#include "ThingSpeak.h"
#include "DHT.h"

#define DHTPIN 19 // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11 // DHT 11


DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "ACENAARTECHNOLOGY"; // your network SSID (name)


const char* password = "123456789"; // your network password

WiFiClient client;

unsigned long myChannelNumber = 1746705;


const char * myWriteAPIKey = "N0XKWYKGYZ75KC2S";

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


63

// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

// Variable to hold temperature readings


float temperatureC;

float humidity;
//uncomment if you want to get temperature in Fahrenheit
//float temperatureF;

// Create a sensor object


//BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)

void readdht(){
if (isnan(humidity) || isnan(temperatureC) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
}

void setup() {
Serial.begin(115200); //Initialize serial
readdht();
dht.begin();
WiFi.mode(WIFI_STA);

ThingSpeak.begin(client); // Initialize ThingSpeak


}

void loop() {
if ((millis() - lastTime) > timerDelay) {

// Connect or reconnect to WiFi


if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
delay(5000);
}
Serial.println("\nConnected.");
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


64

// Get a new temperature reading


temperatureC = dht.readTemperature();
Serial.print("Temperature (ºC): ");
Serial.println(temperatureC);
humidity = dht.readHumidity();
Serial.print("Humidity (%): ");
Serial.println(humidity);

//uncomment if you want to get temperature in Fahrenheit


/*temperatureF = 1.8 * bme.readTemperature() + 32;
Serial.print("Temperature (ºC): ");
Serial.println(temperatureF);*/

// set the fields with the values


ThingSpeak.setField(1, temperatureC);
//ThingSpeak.setField(1, temperatureF);
ThingSpeak.setField(2, humidity);

// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up


to 8 different
// pieces of information in a channel. Here, we write to field 1.
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
lastTime = millis();
}
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


65

Result-

field-1-Temperature field-2-Humidity

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


66

EXPERIMENT-6(a)
Controlling LEDs using Blynk App:
Step-1: Configure Blynk App to send data from mobile phone to cloud
to control LEDs.
Step-2: Write C++ program for ESP32 Microcontroller to read cloud
data and control LEDs accordingly.

How Blynk Works


Blynk was designed for the Internet of Things. It can control hardware remotely, it can display
sensor data, it can store data, vizualize it and do many other cool things.
There are three major components in the platform:
• Blynk App - allows to you create amazing interfaces for your projects using various widgets
we provide.
• Blynk Server - responsible for all the communications between the smartphone and
hardware. You can use our Blynk Cloud or run your private Blynk server locally. It’s open-
source, could easily handle thousands of devices and can even be launched on a Raspberry
Pi.
• Blynk Libraries - for all the popular hardware platforms - enable communication with the
server and process all the incoming and outcoming commands.
Now imagine: every time you press a Button in the Blynk app, the message travels to space the
Blynk Cloud, where it magically finds its way to your hardware. It works the same in the
opposite direction and everything happens in a blynk of an eye.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


67

Features
• Similar API & UI for all supported hardware & devices
• Connection to the cloud using:
o WIFI
o Bluetooth and BLE
o Ethernet
o USB (Serial)
o GSM
o …
• Set of easy-to-use Widgets
• Direct pin manipulation with no code writing
• Easy to integrate and add new functionality using virtual pins
• History data monitoring via Super Chart widget
• Device-to-Device communication using Bridge Widget
• Sending emails, tweets, push notifications, etc.
• … new features are constantly added!
You can find example sketches covering basic Blynk Features. They are included in the library.
All the sketches are designed to be easily combined with each other.

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 ESP-32


Development
board

2. 8 LEDs 8 LEDs connected Logic (J)


through resistors

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


68

3. connecting wires one - 10 port JST


connecting wires

About the Experiment -


Here we control the 8 LEDS present on the kit by using the BLYNK app.

Interfacing on AcenAAr IOT trainer kit-


• To install and get started with Blynk see Appendix C.
• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the logic (J) to the ESP-32 Module “LEDS”.
• Create particular widget in the blynk app with mentioned virtual pin the code.
• After that copy the device info of your created device from the Blynk IOT site and replace
that on the top of the code.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


69

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32
Microcontroller to read cloud data
* and control LEDs accordingly *****************
* Experiment : Exp_06(a) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “LEDS” to
IoT Kit Logic(J). *****************
*************************************************************************************************/
#define BLYNK_TEMPLATE_ID "TMPLXgHEtqWL"
#define BLYNK_DEVICE_NAME "HomeAutomation"
#define BLYNK_AUTH_TOKEN "P7XtvyvnyjUxir5StLv-MvZKvwCr1wBj"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "ACENAARTECHNOLOGY";
char pass[] = "123456789";

const int Leds[8] = {19,18,5,17,16,4,15};

BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
}

BLYNK_WRITE(V1)
{

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


70

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable


Serial.println(pinValue);
switch(pinValue){
case 0:
digitalWrite(Leds[0], HIGH);
digitalWrite(Leds[1], HIGH);
digitalWrite(Leds[2], HIGH);
digitalWrite(Leds[3], HIGH);
digitalWrite(Leds[4], HIGH);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 1:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], HIGH);
digitalWrite(Leds[2], HIGH);
digitalWrite(Leds[3], HIGH);
digitalWrite(Leds[4], HIGH);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 2:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], HIGH);
digitalWrite(Leds[3], HIGH);
digitalWrite(Leds[4], HIGH);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 3:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], HIGH);
digitalWrite(Leds[4], HIGH);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


71

case 4:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], LOW);
digitalWrite(Leds[4], HIGH);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 5:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], LOW);
digitalWrite(Leds[4], LOW);
digitalWrite(Leds[5], HIGH);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 6:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], LOW);
digitalWrite(Leds[4], LOW);
digitalWrite(Leds[5], LOW);
digitalWrite(Leds[6], HIGH);
digitalWrite(Leds[7], HIGH);
break;
case 7:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);
digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], LOW);
digitalWrite(Leds[4], LOW);
digitalWrite(Leds[5], LOW);
digitalWrite(Leds[6], LOW);
digitalWrite(Leds[7], HIGH);
break;
case 8:
digitalWrite(Leds[0], LOW);
digitalWrite(Leds[1], LOW);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


72

digitalWrite(Leds[2], LOW);
digitalWrite(Leds[3], LOW);
digitalWrite(Leds[4], LOW);
digitalWrite(Leds[5], LOW);
digitalWrite(Leds[6], LOW);
digitalWrite(Leds[7], LOW);
}

void setup()
{
for(int ii = 0; ii < 8; ii++)
pinMode(Leds[ii], OUTPUT);
Serial.begin(9600);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
int wifi_ctr = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


73

Result-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


74

EXPERIMENT-6(b)
Controlling Relay using Blynk App:
Step-1: Configure Blynk App to send data to Switch relay (ON/OFF)
from mobile phone to cloud.
Step-2: Write C++ program for ESP32 Microcontroller to read cloud
data and control Relay state accordingly

Experiment-

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. Relay HEJQC3FC RELAY(B)

3. connecting wires one - 4 port & one 10 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


75

About the Experiment -


Here we control the Relay switch present IOT KIT by using the BLYNK app.

Interfacing on AcenAAr IOT trainer kit-


• To install and get started with Blynk see Appendix C.
• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the Relay (B) to the ESP-32 “GPIO”.
• Create particular widget in the blynk app with mentioned virtual pin the code.
• After that copy the device info of your created device from the Blynk IOT site and replace
that on the top of the code.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32
Microcontroller to read cloud data
* and control Relay state accordingly *****************
* Experiment : Exp_06(b) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit Relay(B). *****************
***************************************************************************************************/
#define BLYNK_TEMPLATE_ID "TMPLXgHEtqWL"
#define BLYNK_DEVICE_NAME "HomeAutomation"
#define BLYNK_AUTH_TOKEN "P7XtvyvnyjUxir5StLv-MvZKvwCr1wBj"

#define BLYNK_PRINT Serial

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


76

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "ACENAARTECHNOLOGY";
char pass[] = "123456789";

int Relay=19;

BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}

BLYNK_WRITE(V0)
{

int value = param.asInt();


Serial.println(value);
if (value==1)
{
digitalWrite(Relay,LOW);
Serial.println("Relay ON");
}
else
{
digitalWrite(Relay,HIGH);
Serial.println("Relay OFF");
}

void setup()
{
pinMode(Relay,OUTPUT);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


77

Serial.begin(9600);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);

int wifi_ctr = 0;

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("WiFi connected");

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);


}

void loop()
{
Blynk.run();
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


78

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


79

EXPERIMENT-6(c)
Controlling buzzer using Blynk App:
Step-1: Configure Blynk App to send data to Buzzer (ON/OFF) from
mobile phone to cloud.
Step-2: Write C++ program for ESP32 Microcontroller to read cloud
data and control Buzzer accordingly

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP32 Control unit


Development
board

2. BUZZER Sound buzzer Buzzer (C)

3. connecting wires one - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


80

About the Experiment -


Here we control the Buzzer module present on the IOT kit by using the BLYNK app.

Interfacing on AcenAAr IOT trainer kit-

• To install and get started with Blynk see Appendix C.


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Create particular widget in the blynk app with mentioned virtual pin the code.
• Connection of the peripherals: Connect the Buzzer(C) to the ESP-32 Module “GPIO”. After
that copy the device info of your created device from the Blynk IOT site and replace that
on the top of the code.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32
Microcontroller to read cloud data
* and control Buzzer accordingly *****************
* Experiment : Exp_06(c) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit Buzzer(C). *****************
***************************************************************************************************/
#define BLYNK_TEMPLATE_ID "TMPLXgHEtqWL"
#define BLYNK_DEVICE_NAME "HomeAutomation"
#define BLYNK_AUTH_TOKEN "P7XtvyvnyjUxir5StLv-MvZKvwCr1wBj"

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


81

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "ACENAARTECHNOLOGY";
char pass[] = "123456789";

int Buzzer=19;

BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}

BLYNK_WRITE(V0)
{

int value = param.asInt();


Serial.println(value);
if (value==1)
{
digitalWrite(Buzzer,LOW);
Serial.println("Buzzer ON");
}
else
{
digitalWrite(Buzzer,HIGH);
Serial.println("Buzzer OFF");
}

void setup()

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


82

{
pinMode(Buzzer,OUTPUT);
Serial.begin(9600);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);

int wifi_ctr = 0;

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("WiFi connected");

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);


}

void loop()
{
Blynk.run();
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


83

EXPERIMENT-7 (a)
Introduction to HTTP, hosting a basic server from the ESP32
to control various digital based actuator LED from a simple
web-page:
Write C++ program for ESP32 Microcontroller to configure it as
basic server to control LEDs, reading data from web page.

HTTP:
HTTP is abbreviated as Hypertext Transfer Protocol, an application layer protocol used primarily
with the WWW (World Wide Web) in the client-server model where a web browser is a client
communicating with the webserver which is hosting the website.

1. Initially, a link to the HTTP server gets opened.


2. Then a request is sent.
3. It does some processing on the server.
4. Once the request processing is done, the response is sent back from the server.
5. Finally, the connection is closed.

Architecture of HTTP

The basic block diagram of web application architecture which makes use of HTTP in it.

Web Client: The client of this client-server architecture asks for a request to a specific server
through the HTTP (TCP/IP connection) as a request method in the form of a URL. It also
contains a MIME-like message that contains request modifier and client information.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


84

Web Server: This accepts the request and process with a response by a status line, together
with the version of the message's protocol as well as the success or error code, followed by a
MIME-like message having server information, some metadata, and possible the entity-body
content holding the requested information.

Features of HTTP

• HTTP is connectionless: An HTTP request is initiated by the browser (HTTP client) as per
the user's request for information. The server will process the request and launch back
with a response which the client waits for.
• HTTP is simple: HTTP/2 does the encapsulation of HTTP messages into frames; i.e., HTTP
is typically designed to be plain and human-readable.

Various HTTP methods (GET, POST, PUT, HEAD, DELETE, TRACE, OPTIONS, and CONNECT.) Are
explained below.

GET Method

The GET method is one of the most commonly used methods of HTTP. It is usually implemented
to request a particular resource data from the Web server by specifying the parameters as
a query string (name and value pairs) in the URL part of the request.

POST Method

The POST method is a commonly used HTTP method that sends data to the Web server in the
request body of HTTP. The various characteristics of the POST method are:

• The POST requests cannot be bookmarked as they do not appear in the URL.

PUT Method

The HTTP PUT request method is used to update existing resources with uploaded content or
to create a new resource if the target resource is not found. The difference between POST and
PUT is that PUT requests are static, which means calling the same PUT method multiple times
will not yield a different result because it will update the same content each time while POST
Request Will create new content each time.

HEAD Method

The HTTP HEAD method is almost identical to the GET method, but the only difference is that it
will not return any response body. For example, if GET/users return a record of users, then
HEAD/users make the same request, but it will not return any of the users' records.

DELETE Method

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


85

The HTTP DELETE method is used to delete any specific resource.

TRACE Method

The HTTP TRACE method is used for performing a message loop-back, which tests the path for
the target resource. It is useful for debugging purposes.

OPTIONS Method

HTTP OPTIONS method is used for describing the communication preferences for any target
resource.

CONNECT Method

HTTP CONNECT method is used for establishing a tunnel to the server recognized by a given
URI.

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 ESP-32


Development
board

2. 8 LEDs 8 LEDs connected Logic (J)


through resistors

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


86

3. connecting wires one - 10 port JST


connecting wires

About the Experiment -


Here we control the 8 LEDS present on the kit by using the HTTP server.

Interfacing on AcenAAr IOT trainer kit-


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the logic (J) to the ESP-32 Modules “LEDS”.
• For result search for to the particular IP address acquired form the result in serial monitor.

Sample Code-
/**************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to configure it as basic server to control
LEDs, reading data from web page. ***************
* Experiment : Exp_07(a) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “LEDS” to
IoT Kit Logic(J). *****************
***************************************************************************************************/
#include <WiFi.h>

// Replace with your network credentials


const char* ssid = "ACENAARTECHNOLOGY";
const char* password = "123456789";

// Set web server port number to 80

WiFiServer server(80);

// Variable to store the HTTP request String header;


String header;

const int LedPin [8] = {19,18,5,17,16,4,2,15};

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


87

String Ledstate = "OFF";// state of green LED

void setup() {
Serial.begin(115200);
// Set the pinmode of the pins to which the LEDs are connected and turn them low to
prevent flunctuations
for(int ii = 0; ii < 8; ii++)
pinMode(LedPin[ii], OUTPUT);
for(int ii = 0; ii < 8; ii++)
digitalWrite(LedPin[ii], LOW);
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());// this will display the Ip address of the Pi which should be
entered into your browser
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,


String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


88

client.println("HTTP/1.1 200 OK");


client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// turns the GPIOs on and off


if (header.indexOf("GET /LED/ON") >= 0) {
Serial.println("LED ON");
Ledstate = "ON";
for(int ii = 0; ii < 8; ii++)
digitalWrite(LedPin[ii], HIGH);
} else if (header.indexOf("GET /LED/OFF") >= 0) {
Serial.println("LED OFF");
Ledstate = "OFF";
for(int ii = 0; ii < 8; ii++)
digitalWrite(LedPin[ii], LOW);
}
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width,
initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your
preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin:
0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white;
padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor:
pointer;}");
client.println(".button2 {background-color: #77878A;}</style></head>");

// Web Page Heading


client.println("<body><h1>WelCome To AcenAAr Technology</h1>");
client.println("<body><h1>ESP32 Web Server</h1>");
// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>LED - State " + Ledstate + "</p>");
// If the red LED is off, it displays the ON button
if (Ledstate == "OFF") {
client.println("<p><a href=\"/LED/ON\"><button
class=\"button\">ON</button></a></p>");
} else {

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


89

client.println("<p><a href=\"/LED/OFF\"><button class=\"button


button2\">OFF</button></a></p>");
}

// Display current state, and ON/OFF buttons for GPIO 27

client.println("</body></html>");

// The HTTP response ends with another blank line


client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


90

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


91

EXPERIMENT-7 (b)
Introduction to HTTP, hosting a basic server from the ESP32
to control various digital based actuator Buzzer from a simple
web-page:
Write C++ program for ESP32 Microcontroller to configure it as
basic server to control Buzzer, reading data from web page.

Experiment-
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP32 Control unit


Development
board

2. BUZZER Sound buzzer Buzzer (C)

3. connecting wires one - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


92

About the Experiment -


Here we control the Buzzer module present on the IOT kit by using the BLYNK app.

Interfacing on AcenAAr IOT trainer kit-

• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the Buzzer(C) to the ESP-32 Module “GPIO”.
• For result search for to the particular IP address acquired form the result in serial monitor.

Sample Code-
/**************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to configure it as basic server to control
Buzzer, reading data from web page. *****************
* Experiment : Exp_07(b) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit Buzzer(C). *****************
***************************************************************************************************/

#include <WiFi.h>

// Replace with your network credentials


const char* ssid = "ACENAARTECHNOLOGY";
const char* password = "123456789";
// Set web server port number to 80

WiFiServer server(80);

// Variable to store the HTTP request String header;


String header;
// Declare the pins to which the LEDs are connected
int BuzzerPin =19;

String Buzzerstate = "OFF";// state of green LED

void setup() {

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


93

Serial.begin(115200);
// Set the pinmode of the pins to which the LEDs are connected and turn them low to
prevent flunctuations
pinMode(BuzzerPin, OUTPUT);
digitalWrite(BuzzerPin, LOW);
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());// this will display the Ip address of the Pi which should be
entered into your browser
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,


String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// turns the GPIOs on and off

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


94

if (header.indexOf("GET /Buzzer/ON") >= 0) {


Serial.println("Buzzer ON");
Buzzerstate = "ON";
digitalWrite(BuzzerPin, HIGH);
} else if (header.indexOf("GET /Buzzer/OFF") >= 0) {
Serial.println("Buzzer OFF");
Buzzerstate = "OFF";
digitalWrite(BuzzerPin, LOW);
}

// Display the HTML web page


client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width,
initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your
preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin:
0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white;
padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor:
pointer;}");
client.println(".button2 {background-color: #77878A;}</style></head>");

// Web Page Heading


client.println("<body><h1>ESP32 Web Server</h1>");
client.println("<body><h2>ACENAAR TECHNOLOGIES</h2>");
// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>Buzzer - State " + Buzzerstate + "</p>");
// If the green LED is off, it displays the ON button
if (Buzzerstate == "OFF") {
client.println("<p><a href=\"/Buzzer/ON\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/Buzzer/OFF\"><button class=\"button
button2\">OFF</button></a></p>");
}

// Display current state, and ON/OFF buttons for GPIO 27

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


95

client.println("</body></html>");

// The HTTP response ends with another blank line


client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


96

EXPERIMENT-7 (c)
Introduction to HTTP, hosting a basic server from the ESP32
to control various digital based actuator Relay from a simple
web-page:
Write C++ program for ESP32 Microcontroller to configure it as
basic server to control Relay stare, reading data from web page.

Experiment-

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. Relay HEJQC3FC RELAY(B)

3. connecting wires one - 4 port & one 10 port JST


connecting wires

About the Experiment -


Powered by AcenAAr Technology Pvt. Ltd. Kurnool
97

Here we control the Relay switch present IOT KIT by using the BLYNK app.

Interfacing on AcenAAr IOT trainer kit-


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the Relay (B) to the ESP-32 Module “GPIO”.
• For result search for to the particular IP address acquired form the result in serial monitor.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to configure it as basic server to control Relay
stare, reading data from web page *****************
* Experiment : Exp_07(c) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit Relay(B). *****************
***************************************************************************************************/
#include <WiFi.h>

// Replace with your network credentials


const char* ssid = "ACENAARTECHNOLOGY";
const char* password = "123456789";
// Set web server port number to 80

WiFiServer server(80);

// Variable to store the HTTP request String header;


String header;
// Declare the pins to which the LEDs are connected
int RelayPin =19;

String RelayState = "OFF";// state of green LED

void setup() {
Serial.begin(115200);
// Set the pinmode of the pins to which the LEDs are connected and turn them low to
prevent flunctuations
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, LOW);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


98

WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());// this will display the Ip address of the Pi which should be
entered into your browser
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,


String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// turns the GPIOs on and off


if (header.indexOf("GET /Relay/ON") >= 0) {
Serial.println("Relay ON");
RelayState = "ON";
digitalWrite(RelayPin, HIGH);
} else if (header.indexOf("GET /Relay/OFF") >= 0) {

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


99

Serial.println("Relay OFF");
RelayState = "OFF";
digitalWrite(RelayPin, LOW);
}

// Display the HTML web page


client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width,
initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your
preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin:
0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white;
padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor:
pointer;}");
client.println(".button2 {background-color: #77878A;}</style></head>");

// Web Page Heading


client.println("<body><h1>ESP32 Web Server</h1>");
client.println("<body><h2>ACENAAR TECHNOLOGIES</h2>");
// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>Relay - State " + RelayState + "</p>");
// If the green LED is off, it displays the ON button
if (RelayState == "OFF") {
client.println("<p><a href=\"/Relay/ON\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/Relay/OFF\"><button class=\"button
button2\">OFF</button></a></p>");
}

// Display current state, and ON/OFF buttons for GPIO 27

client.println("</body></html>");

// The HTTP response ends with another blank line


client.println();
// Break out of the while loop

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


100

break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


101

EXPERIMENT-8
Displaying various sensor readings on a simple web page hosted
on the ESP32:
Write C++ program for ESP32 Microcontroller to read sensor values
and display on web page

Experiment

List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. DHT-11 module DHT 11 Sensor DHT 11(I)

4. connecting wires one - 4 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


102

About the Experiment –


Here we measure the Temperature and the Humidity using DHT-11sensor. we PUSH
values to the HTTP server.

Interfacing on the AcenAAr IOT trainer kit


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the DHT-11 (I) to the ESP-32 module “GPIO”.
• For result search for to the particular IP address acquired form the result in serial monitor.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to read sensor values and display on web page ********
* Experiment : Exp_08 *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit DHT-11(I). *****************
**************************************************************************************************/
#include <WiFi.h>
#include <Wire.h>
#include "DHT.h"

// Uncomment one of the lines below for whatever DHT sensor type you're using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
//DHT Sensor;
#define DHTPin 19
DHT dht(DHTPin, DHTTYPE);
float Temperature;
float Humidity;

const char* ssid = "ACENAARTECHNOLOGY";


const char* password = "123456789";

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


103

WiFiServer server(80);

String header;

void setup() {
Serial.begin(115200);
pinMode(DHTPin, INPUT);
dht.begin();

Serial.print("Connecting to Wifi Network");


Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Successfully connected to WiFi.");
Serial.println("IP address of ESP32 is : ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("Server started");

void loop()
{
Temperature = dht.readTemperature();
Humidity = dht.readHumidity();
WiFiClient client = server.available();

if (client)
{
Serial.println("Web Client connected ");
String request = client.readStringUntil('\r');
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-
scale=1\">");

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


104

client.println("<link rel=\"icon\" href=\"data:,\">");


client.println("</style></head><body><h1>Welcome To AcenAAr Technology</h1>");
client.println("<h2>DHT11</h2>");
client.println("<h2>ESP32 Web Server Reading sensor values</h2>");
client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
client.println(dht.readTemperature());
client.println(" *C</span></td></tr>");
client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
client.println(1.8 * dht.readTemperature() + 32);
client.println(" *F</span></td></tr>");
client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
client.println(dht.readHumidity());
client.println(" %</span></td></tr>");
client.println("</body></html>");
client.stop();
client.println();
Serial.println("Client disconnected.");
Serial.println("");
}
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


105

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


106

EXPERIMENT-9(a)
Controlling actuators LEDs/Motors using android App:
Step-1: Develop MIT Android App to send digital data through
Bluetooth.
Step-2: Write C++ program for ESP32 Microcontroller to read digital
data from Bluetooth module and control LEDs accordingly.
About MIT APP
MIT App Inventor is an intuitive (Natural), visual programming environment that
allows everyone even children to build fully functional apps for smartphones and
tablets. Those new to MIT App Inventor can have a simple first app up and running
in less than 30 minutes. And what's more, our b locks-based tool facilitates the
creation of complex, high-impact apps in significantly less time than traditional
programming environments. The MIT App Inventor project seeks to democratize
software development by empowering all people, especially young p eople, to move
from technology consumption to technology creation .
App Inventor lets you develop applications for Android phones using a web browser and either
a connected phone or emulator. The App Inventor servers store your work and help you keep
track of your projects.

You build apps by working with:

• The App Inventor Designer, where you select the components for your app.
• The App Inventor Blocks Editor, where you assemble program blocks that specify how the
components should behave. You assemble programs visually, fitting pieces together like
pieces of a puzzle.

Your app appears on the phone step-by-step as you add pieces to it, so you can test your work
as you build. When you're done, you can package your app and produce a stand-alone application
to install.

If you don't have an Android phone, you can build your apps using the Android emulator,
software that runs on your computer and behaves just like the phone.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


107

The App Inventor development environment is supported for Mac OS X, GNU/Linux, and
Windows operating systems, and several popular Android phone models. Applications created
with App Inventor can be installed on any Android phone.

Experiment:
List of components

Sno Component Description Port Names Board

1. ESP-32 ESP-32 ESP-32


Development
board

2. 8 LEDs 8 LEDs connected Logic (J)


through resistors

3. connecting wires one - 10 port JST


connecting wires

About the Experiment -


Here we read digital data from Bluetooth module and control LEDs accordingly using MIT app.

Step 1: Import the MIT app to the mobile which have been provide to you in the
document folder.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


108

Step2: Interfacing on the AcenAAr IOT trainer kit


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the logic (J) to the ESP-32 module “LEDS”.

Sample Code-
/**************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to read digital data from Bluetooth module
and control LEDs accordingly *****************
* Experiment : Exp_09(a) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “LEDS” to
IoT Kit Logic(J). *****************
**************************************************************************************************/
#include <WiFi.h> // Para el ESP32
WiFiClient WIFI_CLIENT;
#include <PubSubClient.h>
PubSubClient MQTT_CLIENT;

const char* ssid = "ACENAARTECHNOLOGY";


const char* password = "123456789";

// const byte led4 = D4; // LED ESP8266


const int LedPin [8] = {19,18,5,17,16,4,2,15};

void setup() {
for(int ii = 0; ii < 8; ii++)
pinMode(LedPin[ii], OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println();
Serial.print("Connecting with ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


Powered by AcenAAr Technology Pvt. Ltd. Kurnool
109

delay(500);
Serial.print(".");
}

Serial.println("");
Serial.print("WiFi conected. IP: ");
Serial.println(WiFi.localIP());

// Setting Callback.
MQTT_CLIENT.setCallback(callback);
}

// What to do when it receives the data.


void callback(char* recibido, byte* payload, unsigned int length) {
Serial.print("Message received: ");
Serial.print(recibido);
Serial.print(" ");
for (int i=0;i<length;i++) {
char receivedChar = (char)payload[i];
Serial.print(receivedChar);
if (receivedChar == '1')
{ for(int ii = 0; ii < 8; ii++)
digitalWrite(LedPin[ii], HIGH);
}
if (receivedChar == '0')
{ for(int ii = 0; ii < 8; ii++)
digitalWrite(LedPin[ii], LOW);
}
}
Serial.println();
}

void loop() {
if (!MQTT_CLIENT.connected()) {
reconnect();
}
MQTT_CLIENT.loop(); // Check Subscription.
}

// Reconecta con MQTT broker


void reconnect() {
MQTT_CLIENT.setServer("broker.hivemq.com", 1883);
//MQTT_CLIENT.setServer("mqtt.eclipse.org", 1883);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


110

MQTT_CLIENT.setClient(WIFI_CLIENT);

// Trying connect with broker.


while (!MQTT_CLIENT.connected()) {
Serial.println("Trying to connect with Broker MQTT.");
MQTT_CLIENT.connect("JuanAntonio"); // it isn't necessary..
MQTT_CLIENT.subscribe("AcenAAr/Technology"); // HERE SUBSCRIBE.

// Wait to try to reconnect again...


delay(3000);
}

Serial.println("Conected MQTT.");
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


111

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


112

EXPERIMENT-9(b)
Controlling AC appliances from an Android APP with the help
of relay:
Step-1: Develop MIT Android App to send digital data through
Bluetooth.
Step-2: Write C++ program for ESP32 Microcontroller to read digital
data from Bluetooth module and control Bulb using relay.

Experiment-

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. Relay HEJQC3FC RELAY(B)

3. connecting wires one - 4 port & one 10 port JST


connecting wires

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


113

About the Experiment -


Here we control the Relay switch present IOT KIT by using the MIT app.

Step1: Import the MIT app to the mobile which have been provide to you in the document
folder.

Step2: Interfacing on AcenAAr IOT trainer kit-


• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the Relay (B) to the ESP-32 Module “GPIO”.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Write C++ program for ESP32 Microcontroller
to read digital data from Bluetooth module
and control Bulb using relay. *****************
* Experiment : Exp_09(b) *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit Relay(B). *****************
***************************************************************************************************/
#include <WiFi.h> // Para el ESP32
WiFiClient WIFI_CLIENT;
#include <PubSubClient.h>
PubSubClient MQTT_CLIENT;

const char* ssid = "ACENAARTECHNOLOGY";


const char* password = "123456789";

// const byte led4 = D4; // LED ESP8266


const byte LED2 = 19; // LED ESP32

void setup() {
pinMode(LED2, OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println();
Serial.print("Connecting with ");

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


114

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(500);
Serial.print(".");
}

Serial.println("");
Serial.print("WiFi conected. IP: ");
Serial.println(WiFi.localIP());

// Setting Callback.
MQTT_CLIENT.setCallback(callback);
}

// What to do when it receives the data.


void callback(char* recibido, byte* payload, unsigned int length) {
Serial.print("Message received: ");
Serial.print(recibido);
Serial.print(" ");
for (int i=0;i<length;i++) {
char receivedChar = (char)payload[i];
Serial.print(receivedChar);
if (receivedChar == '1') {digitalWrite(LED2, HIGH);}
if (receivedChar == '0') {digitalWrite(LED2, LOW);}
}
Serial.println();
}

void loop() {
if (!MQTT_CLIENT.connected()) {
reconnect();
}
MQTT_CLIENT.loop(); // Check Subscription.
}

// Reconecta con MQTT broker


void reconnect() {
MQTT_CLIENT.setServer("broker.hivemq.com", 1883);
//MQTT_CLIENT.setServer("mqtt.eclipse.org", 1883);

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


115

MQTT_CLIENT.setClient(WIFI_CLIENT);

// Trying connect with broker.


while (!MQTT_CLIENT.connected()) {
Serial.println("Trying to connect with Broker MQTT.");
MQTT_CLIENT.connect("JuanAntonio"); // it isn't necessary..
MQTT_CLIENT.subscribe("AcenAAr/Technology"); // HERE SUBSCRIBE.

// Wait to try to reconnect again...


delay(3000);
}

Serial.println("Conected MQTT.");
}

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


116

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


117

EXPERIMENT-10
Displaying humidity and temperature data on a web-based
application:

Experiment-

Sno Component Description Port Names Board

1. ESP-32 ESP-32 Control unit


Development
board

2. DHT-11 module DHT 11 Sensor DHT 11(I)

3. connecting wires one - 4 port & one 10 port JST


connecting wires

About the Experiment -


Here we upload the DHT 11 data to the Esp32 and further monitor on the Web server.

Interfacing on AcenAAr IOT trainer kit-

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


118

• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the DHT 11 (I) to the ESP-32 Module “GPIO”.
• For the result search for the broker.hivemq.com in the web page.
• Connect to the server as typing the port number and then type the subscribe topic and
click on subscribe.

Sample Code-
/***************************************************************************************************
* Acenaar IoT Trainer Kit *****************
* Program Name : Displaying humidity and temperature data
on a web-based application: *****************
* Experiment : Exp_10 *****************
* Connecting Wires : One 4 pin JST Connecting Wire *****************
* Connections : From ESP32 IoT Module “GPIO” to
IoT Kit DTH 11 (I). *****************
***************************************************************************************************/

#include <WiFi.h>
#include <PubSubClient.h>
#include <SPIFFS.h>
#include "DHT.h"
#define DHTPIN 19

#define DHTTYPE DHT11


Powered by AcenAAr Technology Pvt. Ltd. Kurnool
119

DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "ACENAARTECHNOLOGY";


const char* password = "123456789";
const char* mqtt_server = "broker.hivemq.com";

WiFiClient espClient;
PubSubClient client(espClient);

unsigned long lastMsg = 0;


#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
#define MSG_BUFFER_SIZE (50)
char msg2[MSG_BUFFER_SIZE];
String sent ="";
char Temp[50];
char Humi[50];
int value = 0;

int temperature;
int humidity;

void readdht(){
if (isnan(humidity) || isnan(temperature) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
}

void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(500);
Serial.print(".");
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


120

randomSeed(micros());

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {


Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}

void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("AcenAAr/outTopic", msg);
// ... and resubscribe
client.subscribe("inTopic");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup() {

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


121

Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}

void loop() {

if (!client.connected()) {
reconnect();
}
client.loop();

unsigned long now = millis();


if (now - lastMsg > 2000) {
lastMsg = now;
++value;
temperature = dht.readTemperature();
humidity = dht.readHumidity();
//sprintf(Temp, "Temperature: %f",temperature );
//sprintf(Humi, "Humidity: %f",humidity );

sent = String(temperature )+ ","+String(humidity);


int length = sent.length() +1;
sent.toCharArray(msg,length);

//snprintf (msg, MSG_BUFFER_SIZE,Temp, value);


//snprintf (msg2, MSG_BUFFER_SIZE,Humi, value);

//Serial.print("Publish message: ");


Serial.println(msg);

/* Serial.print(F("Temperature: "));
Serial.print(Temp);
Serial.println(F("°C"));
Serial.print(F("Humidity: "));
Serial.print(Humi);
Serial.println(F("%"));
*/
client.publish("AcenAAr/outTopic",msg);
}
delay(1000);
}

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


122

Result:

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


123

Appendix A:
ESP 32 Specifications
The ESP32 development boards come with so many versions, pinouts, shapes, etc. In this article,
we are going to see the pinout diagram of ESP32 30-pin Devkit development board. It has a 48
pin QFN (Quad Flat No Leads) package microcontroller IC. As this is a No leads IC, so it is very
difficult to solder manually on a board. So the developer made a module using this
microcontroller is called ESP-WROOM-32. So the ESP 32 development board consists of ESP-
WROOM-32 as the baseboard. This ESP-WROOM-32 IC contains 4 MB SPI Flash memory IC and a
40MHz Crystal Oscillator, PCB Antenna, etc.

As the ESP32 board consists of a 4 MB flash memory to store its primary program, some GPIO
pins are directly connected to this flash memory. So these pins are can be used only for the
programming of the board, these pins are cannot be used for other functions.

ESP32 Pinout Diagram (30-pin Devkit)

Here, you can see the pinout diagram of ESP32 Devkit Development Board.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


124

You can see each of the pins of this board has multiple functions. Each function is clearly noted
with different colors. Now we will discuss about these functions with respective pins to
understand how to and which pins should be used.

GPIO means General Input and Output. In the 30 pin ESP32 board, 25 GPIO pins are available to
connect with external circuits. It also has some other GPIO pins that are connected internally with
some ports and ICs. The GPIO pins are also used for other functions such as ADC, DAC, RTC, etc.
But, only one function work at a time. So, we can configure the GPIO pin as an ADC or a UART in
the program. You can see in the above diagram, the pin no 2 to 13 and pin no 18 to 30 have GPIO
functions.

ADC means Analog to Digital Converter. The ADC pins help to connect external analog devices
and components with this board. So, it can measure analog voltage, current. These ADC pins are
also be used in the sleep mode for low power consumption. The pin no 2 to 13 and 18 to 20 have
ADC functions.

DAC means Digital to Analog. Digital to Analog or DAC helps to convert the digital signal into an
analog signal. These are used for analog output purposes. These pins are comes in the use for
voltage control, PWM control, etc. The GPIO 25 and 26 or pin no 8 and 9 have DAC functions.

PWM means Pulse Width Modulated. There is a difference signal normal digital signal and pulse
width modulated or PWM signal although they look like same. The digital signal has a constant
or fixed time period and frequency whereas PWM signal has variable time period and frequency.
The PWM function comes for very useful applications such as motor control or variable load
controls. In the ESP32 board, almost all the pins are PWM enabled except pin no 1, 14, 15, 16,
17.

The 30 pin ESP32 board has 9 numbers touch sensor pins. The pin no 6, 7, 11, 12, 13, 18, 19, 20
the touch sensor pins. These pins are can be used to implement a capacitive touch sensor or
touchpad without any external hardware.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


125

Appendix B:
Get fully with acquainted Raspberry pi and Thonny IDE.
To start the IoT programming with IoT trainer kit you need to follow step by step procedure which
is given below.
STEP-1: power on the Raspberry pi by connecting the c-type power adopter to c-type power
connector and wait for 1 min for boot loading.

STEP-2: Configure Raspberry pi headeless mode in windows host connecting Internet.

Step -2.1 : Go to Wifi settings and click the change adaptor options

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


126

Step -2.2 : Double Click the Wi-fi Icon

Step -2.3:Enter onto the WIFI PROPERTIES and go to the SHARING tab and mark the allow other
network to connect through computer’s internet connection

Step –2.4:
• Connect the your windows host system ethernet connector to the acenaar raspberry pi
Powered by AcenAAr Technology Pvt. Ltd. Kurnool
127

ethernet connector through Ethernet cross cable


• Download or Copy the Advanced IP scanner software folder in to given CD
• Open the Advance IP scanner application in windows host and scan the ipaddress in
between 192.168.137.1 – 254.
• Findout the raspberry pi IP adderss .

Step – 2.5: Download or copy the VNC viewer from software folder into the given CD and
launch VNC Viewer.
Step – 2.6: Select New connection from the File menu.

Step – 2.7: Enter Raspberry PI IP address 192.168.137.225 in the "VNC Server" field and click
ok button.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


128

Step –2.8: Double-click on the connection icon to connect.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


129

Step – 2.9: Enter the Pi's username and password when prompted. The defaults are
username: pi and password: acenaar@123. Click Ok.

Your Raspberry Pi desktop will then appear in a window on your main computer's desktop.
You'll be able to control everything from there.
STEP-3: click on the MENU bar > open PROGRAMING > open Thonny IDE.
STEP-4: Write your Python programming in Thonny IDE (all programs will be available in the
JNTUA_ATP folder).

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


130

Appendix C:
Get fully acquainted with Blynk APP Installation.
To start the IoT programming with IoT trainer kit you need to follow step by step procedure which
is given below. (Skip Step-1 to step-6 if already done in level-1)
STEP-7: IoT program on Basic IoT trainer kit-2022: Go to your favourite browser and paste the
following URL https://blynk.cloud/dashboard/register and complete the following procedure given
below.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


131

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


132

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


133

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


134

Step-8: In Your Mobile, search for Blynk IoT App in Google App store and install it and follow the
steps given below figures.

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


135

Click here

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


136

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


137

Powered by AcenAAr Technology Pvt. Ltd. Kurnool


138

Powered by AcenAAr Technology Pvt. Ltd. Kurnool

You might also like