0% found this document useful (0 votes)
10 views45 pages

IAP R22 Lab Manual

The document is a lab manual for the EC506PC: IoT Architectures and Protocols course for B.Tech ECE students. It includes guidelines for writing observation books, lab do's and don'ts, institutional and departmental visions and missions, program educational objectives, program outcomes, and specific outcomes. Additionally, it outlines a list of experiments related to IoT applications, including interfacing with sensors and cloud services using various protocols.

Uploaded by

srilekhaboda.ece
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views45 pages

IAP R22 Lab Manual

The document is a lab manual for the EC506PC: IoT Architectures and Protocols course for B.Tech ECE students. It includes guidelines for writing observation books, lab do's and don'ts, institutional and departmental visions and missions, program educational objectives, program outcomes, and specific outcomes. Additionally, it outlines a list of experiments related to IoT applications, including interfacing with sensors and cloud services using various protocols.

Uploaded by

srilekhaboda.ece
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LABMANUAL

Of
EC506PC: IoT ARCHITECTURES AND
PROTOCOLS
(III [Link] ECE- I Semester- R22 AY: 2025-2026)

Departmentof
Electronics&communicationEngineering
2025-2026
[Link]
LAB INSTRUCTIONS

GUIDELINES TO WRITE YOUR OBSERVATION BOOK

1. AssemblyLanguagePrograms(ALP’s),Algorithm,TheoreticalResultand PracticalResultshouldbeon rightside.


2. Flowchartshouldbeleftside
3. Resultshouldalwaysbeintheending.
4. YouallareadvisedtoleavesufficientnoofpagesbetweenALP’sfortheoreticalormodelcalculations purpose.

DO’S AND DON’TS IN THE LAB:

DO’S:

1. Properdresshastobemaintainedwhileentering intheLab.(BoysTuck inandshoesand girls


should be neatly dressed)
2. Studentsshouldcarryobservationnotesandrecordcompletedinall aspects.
3. ALPanditstheoreticalresultshouldbethereintheobservationbefore comingtothe next
lab.
4. Studentshouldbeawareofnext ALPs.
5. Studentsshouldbeat theirconcerneddesktop,unnecessarymoment is restricted.
6. Student should follow the procedure to start executing the ALP they have to get signed
bytheLab instructorfor theoreticalresultthenwiththepermissionofLabinstructorthey need
to switch on the desktop and after completing the same they need to switch off and keep
the chairs properly.
7. AftercompletingtheALPStudentsshouldverifytheALPbytheLabInstructor.
8. ThePracticalResultshouldbenoteddownintotheir observationsandresultmustbe shown
to the Lecturer In-Charge for verification.
9. Studentsmustensurethatallswitchesarein theOFFposition,desktopisshutdown
properly.

DON’TS:
1. Don’tcomelatetotheLab.
2. Don’tleavetheLabwithoutmakingpropershutdownofdesktopandkeepingthechairs
properly.
3. Don’tleavetheLabwithoutverificationbyLabinstructor.
4. Don’tleavethelabwithoutthepermissionoftheLecturerIn-Charge
DEPARTMENTOFELECTRONICS&COMMUNICATION ENGINEERING

INSTITUTION VISION

To be a reputed institute in technical education towards research, industrial and societal needs.

INSTITUTION MISSION

Provide state-of-the-art infrastructure, review, innovative and experiment teaching –learning


methodologies.
Promote training, research and consultancy through an integrated institute industry symbiosis.
Involve in activities to groom professional, ethical values and social responsibility

DEPARTMENT VISION

To be a centre of excellence in electronics and communication education and research to serve


industry and society needs.

DEPARTMENT MISSION

The Department has following Missions:

Mission of the department is to achieve International or Recognition by:

DM 1: Provide state-of-art academic facilities, practice quality teaching learning process with
qualified faculty.

DM 2: Impart skill based training and multi-disciplinary research activities with collaborations.

DM 3: Organizing with activities to enable overall development of stakeholders and serve the
community.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)

The Program Educational Objectives (PEOs) of the Computer Science and Engineering are listed
below: The graduate after 3-5 years of programme completion will

PEO1: Graduates will be able to solve Electronics and Communication Engineering problems and
exhibit proficiency in computational tools.

PEO2: Graduates will be able to communicate effectively and work in multidisciplinary teams
practice the professional ethics with a sense of social responsibility.

PEO3: Graduates will be able to have lifelong learning attitude and improve the professional
knowledge.

PEO4: Graduates will be able to pursue career in industry or research, shine as exerts and
entrepreneur.
ProgramOutcomes(POs)

PO1:AnabilitytoapplyknowledgeofScience,Mathematics,Engineering&Computing fundamentals for the


solutions of Complex Engineering problems.

PO2:Anabilitytoidentify,formulates,researchliteratureandanalyzecomplexengineeringproblems
using first principles of mathematics and engineering sciences.

PO 3:Anability todesign solutionstocomplexprocessorprogram tomeet desiredneeds

PO4:Abilitytouseresearch-basedknowledgeandresearchmethodsincludingdesignof experiments to
provide valid conclusions.

PO5:Anabilitytouseappropriatetechniques,skillsandtoolsnecessaryforcomputing practice.

PO6:Abilitytoapplyreasoninginformedbythecontextualknowledgetoassesssocial issues,
consequences & responsibilities relevant to the professional engineering practice.

PO7:Abilitytounderstandtheimpactofengineeringsolutionsinaglobal,economic, environmental, and societal


context with sustainability.

PO8:Anunderstandingof professional,ethical,socialissuesandresponsibilities.

PO 9: Anability tofunctionas an individual, andas a member or leader in diverse teams and in


multidisciplinary settings.
PO10:Anabilitytocommunicateeffectivelyoncomplexengineeringactivitieswithinthe engineering
community.

PO11:Abilitytodemonstrateandunderstandingoftheengineeringandmanagement principles as a
member and leader in a team.

PO12:Abilityto engageinindependentandlifelonglearningin thecontextof technological change.

PROGRAM SPECIFIC OUTCOMES (PSO)

PSO1: Design Skills: Design and develop the integrated Electronics and Communication Systems

PSO2: Simulation and Tools Usage: Use Modern electronic tools such as MATLAB, Xilinx and
Multisim to design and analyse the complex electronics and communication systems.

List of Experiments

III Year [Link]. I Sem. LTPC0021

Course Outcomes: Upon completing this course the students will be able to:
Utilize the different sensors like room temperature, DHT, Humidity etc.,
 Interface the sensors and processor for transmission of data.
 Capture the images and process it on Arduino/NodeMCU/Raspberry Pi.
 know the utilization of various protocols like I2c, UART communication etc.,

List of Experiments:

1. Demonstrate blinking of an LED at every 5 seconds and to control the brightness of an LED.
2. Read Humidity and Room Temperature using DHT sensor and display the readings.
3. Send the recorded values of Temperature/Humidity to the Internet via GSM module
usingArduino/NodeMCU/Raspberry Pi.
4. Demonstrate Interfacing NodeMCU/Raspberry Pi with the Cloud using REST API and
MQTTprotocol.
5. Demonstrate Switching lights on /off remotely using Arduino/NodeMCU/Raspberry Pi.
6. Voice-based Home Automation for switching lights on/off using Google Assistant, IFTTT andMQTT.
7. Interfacing DHT11 sensor with Raspberry pi/equivalent and upload temperature and humidityvalues to
the cloud.
8. Design an obstacle detection unit using ultrasonic sensor.
9. Capture images from web camera using Raspberry Pi/equivalent and apply filters in increaseimage
quality.
10. Access a remote computer from Raspberry Pi and display the remote screen.
11. Design an automatic water sprinkler based on soil moisture using Arduino/NodeMCU/Raspberry Pi.
12. Design an RFID based attendance system using Arduino/NodeMCU/Raspberry Pi.
13. Write an arduino program to demonstrate interrupts
14. Write an arduino program to demonstrate UART communication protocol
15. Write an arduino program to demonstrate I2C communication protocol
16. Write an arduino program to demonstrate SPI communication protocol
Arduino IDE 2.0 Installed

Before proceeding make sure you have Arduino IDE 2.0 installed in your computer. Go

to the Arduino website and download the version for your operating system.
 Windows: run the file downloaded and follow the instructions in the installation guide.
 Mac OS X: copy the downloaded file into your application folder.
 Linux: extract the downloaded file, and open the arduino-ide file that will launch the IDE.

If you have doubts, you can go to the Arduino Installation Guide.

To install the ESP8266 board in your Arduino IDE, follow these next instructions:
1. In your Arduino IDE 2.0, go to File > Preferences.
2. Copy and paste the following line to the Additional Boards Manager URLs
field. [Link]
Adding ESP8266 Board Manager

In the Additional Boards Manager enter below URL.


[Link]
As highlighted in the figure and enter OK.
Selecting Board

Now open the tools in that select Board: “Arduino/Genuino Uno” and click on the Boards Manager as
shown in the figure

ESP8266 Board Package


The Boards Manager window opens, scroll the window page to bottom till you see the module with the
name ESP8266. Once we get it, select that module and select version and click on the Install button.
When it is installed it shows Installed in the module as shown in the figure and then closes the window.

Selecting ESP8266 Arduino Board

To run the esp8266 with Arduino we have to select the Board: “Arduino/Genuino Uno” and then
change it to NodeMCU 1.0 (ESP-12E Module) or other esp8266 modules depending on what you have
to select and select port, Upload the program.
EXPERIMENT : 1
Demonstrate blinking of an LED at every 5 seconds and to control the brightness of an LED.

//BLINKING OF LED

#define led 2

void setup()
{
pinMode(led,OUTPUT);
}
void loop()
{
digitalWrite(led,HIGH);
delay(5000);
digitalWrite(led,LOW);
delay(5000);
}

//CONTROLLING BRIGHTNESS OF LED

#define led 3

void setup()
{
}
void loop()
{
for(int i=0;i<=255;i=i+1)
{
analogWrite(led,i);
delay(50);
}
for(int i=255;i>=0;i=i-1)
{
analogWrite(led,i);
delay(50);
}
EXPERIMENT : 2
Read Humidity and Room Temperature using DHT sensor and display the readings.

#include <DHT.h>
#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float t,h;

void setup()
{
[Link](9600);

[Link]();

delay(100);
}

void loop()
{
t=[Link]();
h=[Link]();

[Link]("TEMPERATURE : ");[Link](t);[Link](" *C");


[Link]("HUMIDITY : ");[Link](h);[Link](" %");
delay(1000);
}
EXPERIMENT : 3

Send the recorded values of Temperature/Humidity to the Internet via GSM module using
Arduino/NodeMCU/Raspberry Pi.

#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(2,3);

#include <String.h>
#include <DHT.h>
#define DHTPIN A0
DHT dht(DHTPIN, DHT11);

void setup()
{
[Link](9600); // the GPRS baud rate
[Link](9600); // the GPRS baud rate
[Link]();

delay(1000);
}

void loop()
{
float h = [Link]();
float t = [Link]();
delay(100);

[Link]("Temperature = ");
[Link](t);
[Link](" °C");
[Link]("Humidity = ");
[Link](h);
[Link](" %");
if ([Link]())
{
[Link]([Link]());
}

[Link]("AT");
delay(1000);

[Link]("AT+CPIN?");
delay(1000);

[Link]("AT+CREG?");
delay(1000);

[Link]("AT+CGATT?");
delay(1000);

[Link]("AT+CIPSHUT");
delay(1000);

[Link]("AT+CIPSTATUS");
delay(2000);

[Link]("AT+CIPMUX=0");
delay(2000);

ShowSerialData();

[Link]("AT+CSTT=\"[Link]\"");//start task and setting the APN,


delay(1000);

ShowSerialData();

[Link]("AT+CIICR");//bring up wireless connection


delay(3000);
ShowSerialData();

[Link]("AT+CIFSR");//get local IP adress


delay(2000);

ShowSerialData();

[Link]("AT+CIPSPRT=0");
delay(3000);

ShowSerialData();

[Link]("AT+CIPSTART=\"TCP\",\"[Link]\",\"80\"");//start up the connection


delay(6000);

ShowSerialData();

[Link]("AT+CIPSEND");//begin send data to remote server


delay(4000);
ShowSerialData();

String str="GET [Link] + String(t)


+"&field2="+String(h);
[Link](str);
[Link](str);//begin send data to remote server

delay(4000);
ShowSerialData();

[Link]((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
[Link]();

ShowSerialData();
[Link]("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}
void ShowSerialData()
{
while([Link]()!=0)
[Link]([Link]());
delay(5000);
}
EXPERIMENT : 4

Demonstrate Interfacing NodeMCU/Raspberry Pi with the Cloud using REST API and MQTTprotocol.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "YOUR_WIFI_SSID";


const char* password = "YOUR_WIFI_PASSWORD";
const char* mqtt_server = "YOUR_MQTT_BROKER_ADDRESS"; // e.g., "[Link]"
const int mqtt_port = 1883; // or 8883 for TLS

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {
delay(10);
[Link]();
[Link]("Connecting to ");
[Link](ssid);
[Link](ssid, password);
while ([Link]() != WL_CONNECTED) {
delay(500);
[Link](".");
}
[Link]("");
[Link]("WiFi connected");
[Link]("IP address: ");
[Link]([Link]());
}

void reconnect() {
while (![Link]()) {
[Link]("Attempting MQTT connection...");
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
if ([Link](clientId.c_str())) {
[Link]("connected");
[Link]("outTopic", "hello world"); // Example publish
[Link]("inTopic"); // Example subscribe
} else {
[Link]("failed, rc=");
[Link]([Link]());
[Link](" try again in 5 seconds");
delay(5000);
}
}
}

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


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

void setup() {
[Link](115200);
setup_wifi();
[Link](mqtt_server, mqtt_port);
[Link](callback);
}

void loop() {
if (![Link]()) {
reconnect();
}
[Link]();
// Add your sensor reading and publishing logic here
}
EXPERIMENT : 5

Demonstrate Switching lights on /off remotely using Arduino/NodeMCU/Raspberry Pi

#include <ESP8266WiFi.h>
const char* ssid = "********"; // Enter SSID here
const char* password = "*******"; //Enter Password here
String header;
String LED1State = "off";
const int LED1 = D0;
WiFiServer server(80);
void setup()
{
[Link](115200);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
[Link]("Connecting to ");
[Link](ssid);
[Link](ssid, password);
while ([Link]() != WL_CONNECTED)
{
delay(500);
[Link](".");
}
// Print local IP address and start web server
[Link]("");
[Link]("WiFi connected-->");
[Link]("Copy this IP address: ");
[Link]([Link]());
[Link]();
}
void loop()
{
WiFiClient client = [Link]();
if (client)
{
[Link]("new client connected");
String currentLine = ""; // make a String to hold incoming data from the client
while ([Link]())
if ([Link]()) { // if there's bytes to read from the client,
char c = [Link]();
[Link](c);
header += c;
if (c == '\n') { // if the byte is a newline character
if ([Link]() == 0) {
[Link]("HTTP/1.1 200 OK");
[Link]("Content-type:text/html");
[Link]("Connection: close");
[Link]();
if ([Link]("GET /LED1/on") >= 0) {
[Link]("LED1 on");
LED1State = "on";
digitalWrite(LED1, HIGH);
} else if ([Link]("GET /LED1/off") >= 0) {
[Link]("LED1 off");
LED1State = "off";
digitalWrite(LED1, LOW);
}
// Display the HTML web page
[Link]("<!DOCTYPE html><html>");
[Link]("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
[Link]("<link rel=\"icon\" href=\"data:,\">");
[Link]("<style>html { font-family: Cairo; display: inline; margin: 0px auto; text-align: center;
background-color: #ccffb3;}");
[Link](".button { background-color: #006699; border: none; color: white; padding: 16px
40px;");
[Link]("text-decoration: none; font-size: 35px; margin: 2px; cursor: pointer;}");
[Link](".button2 {background-color: #555555;}</style></head>");
[Link]("<svg width=\"300\" height=\"80\"><text fill=\"#00bfbf\" font-family=\"serif\" font-
size=\"24\" id=\"svg_1\" stroke=\"#000000\" text-anchor=\"middle\" transform=\"matrix(1.35388 0 0
1.42308 -6.66283 -8.67308)\" x=\"86.5\" xml:space=\"preserve\" y=\"41.5\">Circuit Digest</text></svg>");
// Web Page Heading
[Link]("<body><h1>Welcome to ESP12e Web Server</h1>");
[Link]("<p>LED1_State: " + LED1State + "</p>");
// If the LED1State is off, it displays the ON button
if (LED1State=="off") {
[Link]("<p><a href=\"/LED1/on\"><button class=\"button\">ON</button></a></p>");
[Link]("<svg width=\"500\" height=\"300\"><ellipse cx=\"258.5\" cy=\"125.5\"
fill=\"#ffffff\" rx=\"47\" ry=\"52\" stroke=\"#ffffaa\" stroke-width=\"5\"/><rect fill=\"#cccccc\"
height=\"40\" stroke=\"#ffffaa\" stroke-width=\"5\" transform=\"rotate(-0.485546 261 187.5)\" width=\"39\"
x=\"241.5\" y=\"167.5\"/></svg>");
} else {
[Link]("<p><a href=\"/LED1/off\"><button class=\"button
button2\">OFF</button></a></p>");
[Link]("<svg width=\"500\" height=\"300\"><ellipse cx=\"258.5\" cy=\"125.5\"
fill=\"#ff7f00\" rx=\"47\" ry=\"52\" stroke=\"#ffffaa\" stroke-width=\"5\"/><rect fill=\"#cccccc\"
height=\"40\" stroke=\"#ffffaa\" stroke-width=\"5\" transform=\"rotate(-0.485546 261 187.5)\" width=\"39\"
x=\"241.5\" y=\"167.5\"/></svg>");
}
[Link]("</body></html>");
[Link]();
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
header = "";
[Link]();
[Link]("Client disconnected");
[Link]("");
}
}
EXPERIMENT : 6

Voice-based Home Automation for switching lights on/off using Google Assistant, IFTTT and MQTT.

#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#define Relay1 D0

#define WLAN_SSID "enter your hotspot name" // Your SSID


#define WLAN_PASS " enter your hotspot password" // Your password

#define AIO_SERVER "[Link]"


#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "enter username" // Replace it with your username
#define AIO_KEY "enter key " // Replace with your Project Auth Key
WiFiClient client;

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME,


AIO_KEY);
Adafruit_MQTT_Subscribe Light1 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME"/feeds/BULB"); // FeedName

void MQTT_connect();

void setup()
{
[Link](115200);

pinMode(Relay1, OUTPUT);

// Connect to WiFi access point.


[Link](); [Link]();
[Link]("Connecting to ");
[Link](WLAN_SSID);

[Link](WLAN_SSID, WLAN_PASS);
while ([Link]() != WL_CONNECTED)
{
delay(500);
[Link](".");
}
[Link]();

[Link]("WiFi connected");
[Link]("IP address: ");
[Link]([Link]());

[Link](&Light1);
}

void loop()
{

MQTT_connect();

Adafruit_MQTT_Subscribe *subscription;
while ((subscription = [Link](5000))) {
if (subscription == &Light1) {
[Link](F("Got: "));
[Link]((char *)[Link]);
int Light1_State = atoi((char *)[Link]);
digitalWrite(Relay1, !(Light1_State));
[Link]("DATA : ");[Link](Light1_State);
}
}
}

void MQTT_connect() {
int8_t ret;

// Stop if already connected.


if ([Link]()) {
return;
}

[Link]("Connecting to MQTT... ");

uint8_t retries = 3;

while ((ret = [Link]()) != 0)


{
[Link]([Link](ret));
[Link]("Retrying MQTT connection in 5 seconds...");
[Link]();
delay(5000); // wait 5 seconds
retries--;

if (retries == 0)
{
while (1);
}
}
[Link]("MQTT Connected!");
}
EXPERIMENT : 7

Interfacing DHT11 sensor with Raspberry pi/equivalent and upload temperature and humidity values
to the cloud.

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
WiFiClient client;

unsigned long ch_no = 3117755;//3117755


const char * write_api = "Y2SBIX4PQU76ICOB";//Y2SBIX4PQU76ICOB

char ssid[] = "project01"; // wifi name


char pass[] = "project01"; // wifi password

#include "DHT.h"
#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float t,h;

void setup()
{
[Link](9600);

[Link]();
[Link](ssid, pass);

while ([Link]() != WL_CONNECTED)


{
[Link](".");
delay(100);
}
[Link]("WiFi connected"); [Link]([Link]());
[Link](client);
delay(1000);
}

void loop()
{
t=[Link]();
h=[Link]();
[Link]("TEMPERATURE : ");[Link](t);[Link](" *C");
[Link]("HUMIDITY : ");[Link](h);[Link](" %");
senddata();
delay(1000);
}
void senddata()
{
[Link](1, t);
[Link](2, h);
[Link](ch_no, write_api);
}
EXPERIMENT : 8
Design an obstacle detection unit using ultrasonic sensor.

#define trig D6
#define echo D7
long distance,duration;

#define buzzer D5

void setup()
{
[Link](9600);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
pinMode(buzzer,OUTPUT);
}
void loop()
{
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
duration=pulseIn(echo,HIGH);
distance=duration*0.034/2;

if(distance < 10)


{
[Link]("ALERT");
digitalWrite(buzzer,HIGH);
}
else
{
digitalWrite(buzzer,LOW);
}
[Link]("DISTANCE : "); [Link](distance);[Link]("cm");
delay(1000);
}
EXPERIMENT : 9

Capture images from web camera using Raspberry Pi/equivalent and apply filters in increase image
quality.

import cv2

cap = [Link](0)

while True:
ret, frame = [Link]()

# Apply filters (example: grayscale)


gray_frame = [Link](frame, cv2.COLOR_BGR2GRAY)

# Display the frame


[Link]('Original', frame)
[Link]('Grayscale', gray_frame)

# Exit if the 'q' key is pressed


if [Link](1) & 0xFF == ord('q'):
break

# Release the capture and close the windows


[Link]()
[Link]()

Access a remote computer from Raspberry Pi and display the remote screen.
EXPERIMENT : 10

Designing an Automatic Water Sprinkler Based on Soil Moisture Using Arduino

#define soilMoisturePin A0
int soilMoistureValue;

#define relayPin 2

void setup()
{
[Link](9600);

pinMode(soilMoisturePin, INPUT);
pinMode(relayPin, OUTPUT);
}

void loop()
{
soilMoistureValue = analogRead(soilMoisturePin);
[Link]("Soil Moisture : "); [Link](soilMoistureValue);

if (soilMoistureValue < 300)


{
digitalWrite(relayPin, HIGH);
[Link]("Sprinkler activated");
}
else
{
digitalWrite(relayPin, LOW);
[Link]("Sprinkler deactivated");
}
delay(1000);
}
EXPERIMENT : 11

Design an RFID based attendance system using Arduino/NodeMCU/Raspberry Pi.

#include <MFRC522.h>
#include <SPI.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
[Link]();
mfrc522.PCD_Init();

pinMode(buzzerPin, OUTPUT);
[Link](9600);
}

void loop() {
if (mfrc522.PICC_IsNewCardPresent()) {
if (mfrc522.PICC_ReadCardSerial()) {
String uid = "";
for (byte i = 0; i < [Link]; i++) {
uid += String([Link][i], HEX);
}

[Link]("UID: " + uid);

// Check if the UID is in the attendance database


if (isAuthorized(uid)) {
// Mark attendance
[Link]("Attendance marked");
tone(buzzerPin, 1000, 500); // Play a tone
} else {
[Link]("Unauthorized access");
tone(buzzerPin, 500, 500); // Play a different tone
}
EXPERIMENT : 13
Write an arduino program to demonstrate interrupts

#define led 2
#define sw 3

void setup()
{
[Link](9600);
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
pinMode(sw,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(sw),sw_event,FALLING);
}
void loop()
{
}
void sw_event()
{
digitalWrite(led,HIGH);delay(500);
digitalWrite(led,LOW);delay(500);
[Link]("INTERRUPT OCCURED");
}
EXPERIMENT : 14
Write an arduino program to demonstrate UART communication protocol

//FOR TRANSMITTER CODE


void setup()
{
[Link](9600); //BAUD RATE([Link] BIT CHANGE RATE PER SECOND)
}
void loop()
{
[Link]("HELLO");
//OR
[Link]("HELLO");
}

// FOR RECEIVER CODE


void setup()
{
[Link](9600); //BAUD RATE([Link] BIT CHANGE RATE PER SECOND)
}
void loop()
{
if([Link]())
{
data=[Link](); // EXCPT STRING DATA
//OR
data_string=[Link](); // FOR STRING DATA
}
}
EXPERIMENT : 15
Write an arduino program to demonstrate I2C communication protocol

//MASTER DEVICE CODE

#include<Wire.h>

void setup()
{
[Link]();
}
void loop()
{
[Link](8);//SLAVE ADDRESS TO SEND
[Link]("data"); //DATA
[Link]();

[Link](8,6);//SLAVE ADDRESS TO REQUEST AND DATA SIZE


if([Link]()>0)
{
int data=[Link]();
}
}

//SLAVE DEVICE CODE

#include<Wire.h>

void setup()
{

[Link](8);//SLAVE ADDRESS
[Link](Rx_event);
[Link](Tx_event);
}
void loop()
{

}
void Rx_event(int data_size) //need to mention data size here
{
if([Link]())
{
int data=[Link]();
}
}
void Tx_event()
{
[Link]("data");
}
EXPERIMENT : 16
Write an arduino program to demonstrate SPI communication protocol

// MASTER DEVICE CODE

#include <SPI.h>

void setup()
{
[Link](9600);
[Link](); // Initialize SPI bus
pinMode(SS, OUTPUT); // SS pin as output
digitalWrite(SS, HIGH); // Deselect slave initially
}

void loop()
{
char dataToSend = 'A'; // Data to send
[Link]("Master sending: ");
[Link](dataToSend);

digitalWrite(SS, LOW); // Select slave


char receivedData = [Link](dataToSend); // Send data and receive simultaneously
digitalWrite(SS, HIGH); // Deselect slave

[Link]("Master received: ");


[Link](receivedData);
delay(1000);
}

// SLAVE DEVICE CODE

#include <SPI.h>

volatile boolean processData = false;


volatile byte receivedByte;

void setup()
{
[Link](9600);
pinMode(MISO, OUTPUT); // MISO pin as output
[Link](); // Initialize SPI bus
[Link](MSBFIRST); // Set data order
[Link](SPI_MODE0); // Set SPI mode
[Link](SPI_CLOCK_DIV4); // Set clock divider

// Turn on SPI interrupt


[Link]();
}

ISR(SPI_STC_vect) { // SPI interrupt routine


receivedByte = SPDR; // Read byte from SPI Data Register
processData = true;
}

void loop()
{
if (processData) {
processData = false;
[Link]("Slave received: ");
[Link]((char)receivedByte);

// Slave can also send data back to master


SPDR = receivedByte + 1; // Send back the received byte incremented
}
}

You might also like