Professional Documents
Culture Documents
IoT File
IoT File
IoT File
Lab Manual
of
Embedded System Design with IoT Laboratory
Subject Code: 4EC06
Semester: 7th
Academic Year: 2023-24
Name of Student: Shalini Kotecha
Id No.: 20EC413
BACHELOR OF TECHNOLOGY
IN ELECTRONICS AND COMMUNICATION
1|Page
20EC413
Certificate
This is to certify that Miss Shalini Kotecha with ID. No.
20EC413 of Electronics & Communication has satisfactorily
completed the entire practical in the subject of 4EC06 –
Embedded System Design with IoT Laboratory.
2|Page
20EC413
INDEX
SR. PAGE
DATE AIM SIGN
NO. NO.
Write a program to control an LED with a switch
01 05/07/2023 04
using Arduino on TinkerCAD.
Write a program to control LED intensity based on
02 12/07/2023 a PIR sensor and LDR using Arduino on 07
TinkerCAD.
Write a program to implement a light - following
03 19/07/2023 robot based on LDR and DC motors using Arduino 10
on TinkerCAD.
Write a program to create a web server based on
04 26/07/2023 14
ESP32 to host a web page.
Write a program to update data on a web page
05 26/07/2023 17
hosted on ESP32.
Write a program to auto - update data on a web
06 12/09/2023 24
page using AJAX.
Write a program to control an LED from a web
07 12/09/2023 29
page using ESP32.
Write a program to read data from a switch on the
08 12/09/2023 Blynk dashboard and update the status of the 33
hardware LED.
Write a program to read data from hardware and
09 26/09/2023 36
update the status on the Blynk dashboard.
Write a program to control a servo motor from the
10 26/09/2023 39
Blynk dashboard.
3|Page
20EC413
PRACTICAL NO.: 01
AIM:
SOFTWARE USED:
TinkerCAD
CIRCUIT:
PROGRAM:
int toggle = 0;
void setup()
{
pinMode(13, OUTPUT); //LED
4|Page
20EC413
void loop()
{
if (!(digitalRead(7))){
if (toggle){
toggle = 0;
}
else{
toggle = 1;
}
digitalWrite (13, toggle);
while (!(digitalRead(7)));
}
}
OUTPUT:
5|Page
20EC413
CONCLUSION:
In this practical, an LED was successfully controlled using a switch through Arduino on
TinkerCAD.
6|Page
20EC413
PRACTICAL NO.: 02
AIM:
Write a program to control LED intensity based on a PIR sensor and LDR using Arduino on
TinkerCAD.
SOFTWARE USED:
TinkerCAD
Arduino Uno R3, Photoresistor (LDR), Voltage Multimeter, 10 kΩ Resistor, Red LED, PIR
Sensor, 220 Ω Resistor
CIRCUIT:
7|Page
20EC413
PROGRAM:
void setup()
{
pinMode (2, INPUT); //PIR Signal Pin
pinMode (9, OUTPUT); //LED
Serial.begin(9600);
}
void loop()
{
float N = analogRead(A0); //LDR
float PIR = digitalRead(2);
float V = N * 5000 / 1024; //10 bit ADC
8|Page
20EC413
OUTPUT:
CONCLUSION:
Thus, we have demonstrated the program to control LED intensity based on the input from a PIR
sensor and LDR using Arduino on TinkerCAD.
9|Page
20EC413
PRACTICAL NO.: 03
AIM:
Write a program to implement a light - following robot based on LDR and DC motors using
Arduino on TinkerCAD.
SOFTWARE USED:
TinkerCAD
Arduino Uno R3, DC Motors, L293D H-bridge Motor Driver, 1 kΩ Resistor, Photoresistor,
Voltage Multimeter
CIRCUIT:
PROGRAM:
int Rldr = A0;
int Lldr = A1;
int in1 = 2;
int in2 = 3;
int in3 = 4;
int in4 = 5;
10 | P a g e
20EC413
void setup()
{
pinMode(in1, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in1, OUTPUT);
Serial.begin(9600);
}
void loop()
{
float leftVal = analogRead (Lldr);
float rightVal = analogRead (Rldr);
float ILeft = leftVal * 5000 / 1024;
float IRight = rightVal * 5000 / 1024;
int LLight = map (ILeft, 241, 4740, 0, 100);
int RLight = map (IRight, 241, 4740, 0, 100);
if (LLight > RLight)
{
digitalWrite (in1, HIGH);
digitalWrite (in2, LOW);
digitalWrite (in3, LOW);
digitalWrite (in4, HIGH);
Serial.println ("Rotate Right");
}
else if (LLight < RLight)
{
digitalWrite (in1, LOW);
digitalWrite (in2, HIGH);
digitalWrite (in3, HIGH);
digitalWrite (in4, LOW);
Serial.println ("Rotate Left");
}
else
{
digitalWrite (in1, HIGH);
digitalWrite (in2, LOW);
digitalWrite (in3, HIGH);
digitalWrite (in4, LOW);
Serial.println ("Move Forward");
11 | P a g e
20EC413
}
}
OUTPUT:
12 | P a g e
20EC413
CONCLUSION:
13 | P a g e
20EC413
PRACTICAL NO.: 04
AIM:
Write a program to create a web server based on ESP32 to host a web page.
SOFTWARE USED:
NodeMCU
CIRCUIT:
PROGRAM:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "index.h" //Our HTML webpage
void handleRoot() {
String s = MAIN_page; //Read HTML contents
server.send(200, "text/html", s); //Send web page
}
14 | P a g e
20EC413
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
void loop(void){
server.handleClient(); //Handle client requests
}
index.h
15 | P a g e
20EC413
</BODY>
</HTML>
)=====";
OUTPUT:
shalini
20EC413 shalini
kotecha
CONCLUSION:
Thus, we have successfully created a web server using a Wi-Fi-enabled board, allowing the
board to host a simple webpage. This basic program sets up a server, connects to Wi-Fi, and
responds to incoming client requests by sending a basic HTML page.
16 | P a g e
20EC413
PRACTICAL NO.: 05
AIM:
SOFTWARE USED:
NodeMCU
CIRCUIT:
PROGRAM:
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#include <SPIFFS.h>
#else
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <Hash.h>
#include <FS.h>
#endif
#include <ESPAsyncWebServer.h>
17 | P a g e
20EC413
AsyncWebServer server(80);
18 | P a g e
20EC413
19 | P a g e
20EC413
void setup() {
Serial.begin(115200);
// Initialize SPIFFS
#ifdef ESP32
if(!SPIFFS.begin(true)){
Serial.println("An Error has occurred while mounting
SPIFFS");
return;
}
#else
if(!SPIFFS.begin()){
Serial.println("An Error has occurred while mounting
SPIFFS");
return;
}
#endif
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
20 | P a g e
20EC413
21 | P a g e
20EC413
void loop() {
// To access your stored values on inputString, inputInt,
inputFloat
String yourInputString = readFile(SPIFFS, "/inputString.txt");
Serial.print("*** Your inputString: ");
Serial.println(yourInputString);
OUTPUT:
22 | P a g e
20EC413
CONCLUSION:
We have successfully created a program to update data on a web page hosted by a Wi-Fi-enabled
board.
23 | P a g e
20EC413
PRACTICAL NO.: 06
AIM:
SOFTWARE USED:
NodeMCU
CIRCUIT:
PROGRAM:
String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n
\r\n";
24 | P a g e
20EC413
<script>
function updateCount()
{
ajaxLoad('getCount');
}
function ajaxLoad(ajaxURL)
{
if(!ajaxRequest){ alert('AJAX is not supported.'); return;
}
ajaxRequest.open('GET',ajaxURL,true);
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4 && ajaxRequest.status ==
200)
{
var ajaxResult = ajaxRequest.responseText;
document.getElementById('count_P').innerHTML =
ajaxResult;
}
}
ajaxRequest.send();
}
25 | P a g e
20EC413
setInterval(updateCount, 5000);
</script>
<title>Auto Update Example Using Javascript 2</title>
</head>
<body>
<div id='main'>
<h2> Auto Update Using AJAX </h2>
<div id='count_DIV'>
<p id='count_P'>Count = 0</p>
</div>
</div>
</body>
</html>
)=====";
#include <ESP8266WiFi.h>
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("Serial started at 115200");
Serial.println();
// Connect to a WiFi network
Serial.print(F("Connecting to ")); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
26 | P a g e
20EC413
Serial.println("");
Serial.println(F("[CONNECTED]"));
Serial.print("[IP ");
Serial.print(WiFi.localIP());
Serial.println("]");
// start a server
server.begin();
Serial.println("Server started");
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) { return; }
// Read the first line of the request
request = client.readStringUntil('\r');
if ( request.indexOf("getCount") > 0 )
{
count ++;
client.print( header );
client.print( "Count = " );
client.print( count );
Serial.print("Count=");
Serial.println(count);
}
else
{
client.flush();
client.print( header );
client.print( html_1 );
count = 0;
}
delay(5);
}
27 | P a g e
20EC413
OUTPUT:
CONCLUSION:
We have successfully implemented a program that uses AJAX to auto-update data on a web
page.
28 | P a g e
20EC413
PRACTICAL NO.: 07
AIM:
SOFTWARE USED:
CIRCUIT:
PROGRAM:
#include <ESP8266WiFi.h>
WiFiServer server(80);
29 | P a g e
20EC413
void setup()
{
Serial.begin(115200);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.print("Connecting to the Newtork");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin(); // Starts the Server
Serial.println("Server started");
Serial.print("IP Address of network: ");
Serial.println(WiFi.localIP());
}
void loop()
{
WiFiClient client = server.available();
if (!client)
{
return;
}
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r');
client.flush();
int value = LOW;
if(request.indexOf("/LED=ON") != -1)
{
digitalWrite(LED, HIGH); // Turn LED ON
value = HIGH;
}
if(request.indexOf("/LED=OFF") != -1)
{
digitalWrite(LED, LOW); // Turn LED OFF
30 | P a g e
20EC413
value = LOW;
}
OUTPUT:
31 | P a g e
20EC413
CONCLUSION:
We have successfully created a program to control an LED from a web page using a Wi-Fi-
enabled board.
32 | P a g e
20EC413
PRACTICAL NO.: 08
AIM:
Write a program to read data from a switch on the Blynk dashboard and update the status of the
hardware LED on Wi-Fi enabled board.
SOFTWARE USED:
CIRCUIT:
PROGRAM:
#define BLYNK_TEMPLATE_ID "TMPL3KAxnsbrP"
#define BLYNK_TEMPLATE_NAME "LED"
#define BLYNK_AUTH_TOKEN "DtGrkeuUR4lr8Ly1t-WmTsyWpSfQHTr9"
33 | P a g e
20EC413
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(ledpin,OUTPUT);
}
void loop()
{
Blynk.run();
}
OUTPUT:
34 | P a g e
20EC413
CONCLUSION:
We successfully implemented a program that reads data from a switch on the Blynk dashboard
and updates the status of a hardware LED. The Blynk library facilitates seamless communication
between the hardware and the Blynk app, allowing for remote control of the LED through the
Blynk dashboard switch.
35 | P a g e
20EC413
PRACTICAL NO.: 09
AIM:
Write a program to read data from hardware and update the status on the Blynk dashboard.
SOFTWARE USED:
CIRCUIT:
PROGRAM:
#define BLYNK_TEMPLATE_ID "TMPL3KAxnsbrP"
#define BLYNK_TEMPLATE_NAME "LED"
#define BLYNK_AUTH_TOKEN "DtGrkeuUR4lr8Ly1t-WmTsyWpSfQHTr9"
36 | P a g e
20EC413
BlynkTimer timer;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "V2029";
char pass[] = "shalu_71";
BLYNK_WRITE(V0)
{
int Switch_state = param.asInt();
digitalWrite(ledpin, Switch_state);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(ledpin,OUTPUT);
timer.setInterval(2000, readState);
}
void readState()
{
Blynk.virtualWrite(V1, "20EC402");
int LED_state = digitalRead(ledpin);
if (LED_state == HIGH){
Blynk.virtualWrite(V2, "LED ON");
}
else
{
Blynk.virtualWrite(V2, "LED OFF");
}
}
void loop()
{
Blynk.run();
timer.run();
}
37 | P a g e
20EC413
OUTPUT:
CONCLUSION:
We have successfully implemented a program that reads data from hardware and updates the
status on the Blynk dashboard.
38 | P a g e
20EC413
PRACTICAL NO.: 10
AIM:
SOFTWARE USED:
CIRCUIT:
PROGRAM:
#define BLYNK_TEMPLATE_ID "TMPL3KAxnsbrP"
#define BLYNK_TEMPLATE_NAME "LED"
#define BLYNK_AUTH_TOKEN "DtGrkeuUR4lr8Ly1t-WmTsyWpSfQHTr9"
39 | P a g e
20EC413
Servo myservo;
BlynkTimer timer;
int pos = 0;
BLYNK_WRITE(V2)
{
int pos = param.asInt();
myservo.write(pos);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
myservo.attach(13); //D7 pin
}
void loop()
{
Blynk.run();
}
40 | P a g e
20EC413
OUTPUT:
CONCLUSION:
By establishing a connection to the Blynk server and utilizing the Blynk library, the servo
motor's position is updated in real-time based on the slider value on the Blynk app.
41 | P a g e