IOT CLOUD MANUAL-modified

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 1
Create any Cloud Platform account, explore IoT services
And register a thing on the platform.
Date:

AIM: To Create Adafruit Cloud Platform account, explore IoT services and register
a thing on the platform.
REQUIREMENTS:
1. Computer or mobile device
2. Adafruit account
3. IoT device or sensor
4. Internet connectivity

DESCRIPTION:
The Adafruit Cloud Platform is a cloud-based service that enables users to
create and manage Internet of Things (IoT) projects. It provides a platform for
developers and hobbyists to connect their devices and sensors to the cloud, store
and analyze data, and control their devices remotely.
With the Adafruit Cloud Platform, users can register their IoT devices and
sensors, create custom dashboards to visualize and analyze data, and set up triggers
and alerts to automate their devices. The platform supports various protocols for
connecting IoT devices such as MQTT, HTTP, and WebSocket, making it versatile
for different types of devices and projects.
Users can also create custom APIs to interact with their devices and build
custom applications. The platform has a user-friendly interface and provides several
pre-built blocks and widgets for creating custom dashboards and visualizations,
making it easy for users to get started with their projects.
PROCEDURE:
For the creation of an Adafruit Cloud Platform account and register a thing
on the platform, we should follow these steps:

1
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

1. Go to the Adafruit Cloud Platform website at https://io.adafruit.com


https://io .

2. Click on the “SIGN IN” button located in the top right corner of the page.

3. Click on “SIGN UP” button .

2
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

4. Fill out the required information, including your name, email address, and a
password. Then click on the "Create A
Account"
ccount" button to submit your
registration.

5. Once you have created your account, log in to the Adafruit Cloud Platform
using your email address and password.

3
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

6. Your Adafruit Account page will open as shown below.

RESULT: Hence, creating


ing a Cloud Platform account is completed successfully.

4
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 2
Date: Push sensor data to cloud

AIM: To push sensor data to cloud


DESCRIPTION:
DHT11 sensor is a low-cost digital sensor for sensing temperature and
Humidity. This sensor can be easily interfaced with any micro-controller such as
Arduino, Raspberry pi etc to measure Humidity and Temperature instantaneously.
DHT11 sensor consists of a capacitive Humidity sensing element and a
thermistor for sensing temperature. The Humidity sensing capacitor has two
electrodes with a moisture helding substrate as a dielectric between them change in
the capacitance value occurs with the change in Humidity values.
It has three pins-VCC, GND and Data pin.
PROCEDURE:
1. First to open the Arduino IDE and go to file and select preferences in that to
give path as below
https://arduino.esp8266.com/stable/package_esp8266com_index.json
2. Install board ->ESP8266 as well as libraries like Adafruit io Arduino, DHT11
sensor.
3. To implement the code click on file->examples->Adafruit Io Arduino-
>publish code.
4. After publish code open “Config.h” header file and give IO_USENAME,
IO_KEY, WIFI_SSID, and WIFI_PASS.
5. In publish code we have to add some code of DHT sensor that has given
below.
6. Create a new feed for temperature and name it whatever you like.
7. Create “new dashboard” and add a new block as following figure:

5
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

8. Choose a guage and select a feed as below

6
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Now we can add some settings for the display of the guage

9. We have to compile and dump the code to the NODEMCU board.


10.Connect NODEMCU with dht11 sensor as:
 Dht11 Data pin to GPIO14(D5)
 Dht11 VCC to NODEMCU VCC

7
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

 Dht11 GND to NODEMCU GND


11.The output was displayed on serial monitor as well as in Adafruit cloud
Stream.

CIRCUIT DIAGRAM:

For implementing this experiment we need publish code and config.h code.
SOURCE CODE:
PUBLISH CODE:
#include "config.h"
int count = 0;
Adafruit IO_Feed *counter = io.feed("Temperature");
void setup() {
Serial.begin(115200);
While (! Serial);
Serial.print("Connecting to Adafruit IO");
io. connect ();
While (io.Status() < AIO_CONNECTED) {
Serial.Print (".");
delay (500);
}

8
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Serial.Println ();
Serial.Println (Io.status Text());
}
void loop() {
io.run();

Serial.print("sending -> ");


Serial.println(count);
counter->save(count);
count++;
delay (3000);

OUTPUT:

RESULT:
Push sensor data to cloud was successfully completed.

9
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 3
Date: Control an Actuator through cloud

AIM: To control an actuator through cloud.


HARDWARE REQUIREMENTS:
 NodeMCU
 Jumper wires
 USB cable
 LED lights

SOFTWARE REQUIREMENTS:
 Arduino IDE
 Adafruit

DESCRIPTION:
Adafruit cloud can store, control and monitor the any actuator using
development boards. Here we are using the ON/OFF button from the adafruit cloud
we are controlling the LED light. By switching ON/OFF the button through the
cloud we can control the LED from any remote area. There is not need of real
switch controlling can be done through virtual switch.
PROCEDURE:
1. Open adafruit cloud to create a feed related to experiment and a new
dashboard to be created.

2. In dashboard create a layout with on/off switch and give the value ON as HIGH

10
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

&OFF as low in code.

3.Then in arduino ide open example->adafruit io Arduino->subscribe.

4. Subscribe code is used to control actuator from cloud.


5. In subscribe code we have changes the code with LED code as shown below.

11
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

6. Then we have to complete the code and it is dumped to the NodeMCU.


7. Then by we have to connect the NodeMCU board to LED.
PROGRAM:
#include "config.h"
#define LED_PIN 12
AdafruitIO_Feed *output = io.feed("led");
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
output->onMessage(handleMessage);
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
output->get();
}
12
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

void loop() {
io.run();
}
void handleMessage(AdafruitIO_Data *data) {
String cmd= data->value();
Serial.print("received <- ");
Serial.println(cmd);
if(cmd == "HIGH"){
Serial.println("Rx HIGH");
digitalWrite(LED_PIN, HIGH);
}
else if(cmd == "LOW"){
Serial.println("Rx LOW");
digitalWrite(LED_PIN, LOW);
}
}
OUTPUT:

RESULT:
Accessing the data pushed from the sensor to cloud and applying any data
analytics or visualization service is successfully completed.

13
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 4
Date: Data Analytics Or Visualization Services

AIM:
To Access The Data Pushed From Sensor To Cloud And Apply Any Data
Analytics Or Visualization Services
HARDWARE REQUIREMENTS:
1.DHT11 sensor
2.Jumper wires
3.NodeMCU
4.Power Adapter
SOFTWARE REQUIREMENTS:
1. Arduino IDE
2. Libraries for DHT sensor
3. Libraries for node MCU
4. Libraries for esp8266
5. Adafruit cloud platform
6. Adafruit IO Arduino libraries

COMPONENTS DESCRIPTIION :
DHT11 SENSOR: The DHT11 is a basic, ultra low-cost digital temperature and
humidity sensor. It uses a capacitive humidity sensor and a thermostat to measure
the surrounding air and spits out a digital signal on the data pin (no analog input
pins needed).

DHT11 Applications:
It gives accurate temperature and humidity.
14
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

NODE MCU: Node MCU is an open source firmware for which open source
prototyping board designs are available
available.. The name "NodeMCU" combines
comb
"node" and "MCU" (micro--controller
controller unit). Strictly speaking, the term "NodeMCU"
refers to the firmware rather than the associated development kits.

BLOCK DIAGRAM:

15
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

1. Data pin of DHT11 sensor is connected to D5 pin of NODEMCU.


2. vcc pin of DHT11 sensor is connected to 3v3 pin of NODEMCU.
3. GND pin of DHT11 sensor is connected to GND pin of NODEMCU.
4. Connect an adaptor to the kit and provide power supply to the system.
5. Using an cable(USB) connect the kit to the laptop.

PROCEDURE:
1. First to write the code we have to go to file->examples->
Adafruit IO Arduino->Arduino_subscribe ..then we have to write the record
regarding our project.
2. While writing the code then we have to give names of feed as of we have
provided in the cloud(adafruit.com).
3. After implement the code we have to compile it.
4. To upload the code to the nodeMCU, firstly we have to connect the system to
the nodeMCU using a data cable.
5. Then we should connect the sensor to the kit using the cables and should
provide power supply.
6. Then after all the connections are done correctly then we have to select the
feed (which we provide in the code) in the cloud platform (Adafruit.com).

16
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

7. Then after selecting the feed we have to select the dashboard of the name
Temperature and Humidity. Then we have to create the new block and select
the guage for showing the output of humidity and temperature.

8. After selecting the guage we have to provide the lower limit for the gauges
we have selected.

9. Then we have to create the actions to send the mail. For this we have to select
the new action under action tab ->reactive->choose the action->setup our
action->account setting->time zone->again to action->email verification.

17
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

18
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

10.Then we can get alert mails to our registered and verified mail.

SOURCE CODE
SUBSCRIBE CODE:

#include "config.h"
#include "DHT.h"
#define DHTPIN 14
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int count = 0;
AdafruitIO_Feed *Temperature = io.feed("Temperature");
AdafruitIO_Feed *Humidity = io.feed("Humidity");
void setup() {
Serial.begin(115200);
Serial.println(F("DHTxx test!"));
dht.begin();
while(! Serial);
Serial.print("Connecting to Adafruit IO");
19
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

io.connect();
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
}
void loop() {
io.run();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.println("sending data -> ");
Temperature->save(t);
Humidity->save(h)
delay(30000);
}
CONFIG CODE:
#define IO_USERNAME "AliyaSyed"
#define IO_KEY "aio_EKBA07YKKoySuioNArMqmwCBiu5"
#define WIFI_SSID "Aliya"
#define WIFI_PASS "12345"
20
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT)) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE
ADAFRUIT_METRO_M4_AIRLIFT_LITE)
||
defined(ADAFRUIT_PYPORTAL
ADAFRUIT_PYPORTAL)
#if !defined(SPIWIFI_SS)
#define SPIWIFI SPI
#define SPIWIFI_SS 10
#define NINA_ACK 9
#define NINA_RESETN 6
#define NINA_GPIO0 -1
#endif
AdafruitIO_WiFi io(IO_USERNAME,
IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS,
SPIWIFI_SS, NINA_ACK,
NA_ACK, NINA_RESETN, NINA_GPIO0, &
&SPIWIFI)
SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME,
IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS
WIFI_PASS);
#endif
OUTPUT:

ALERT MESSAGE FROM ADAFRUIT:


From: Adafruit IO
Sent: 16 March 2023 14:51
To: @gmail.com
Subject: Adafruit IO Action: dht11 fe
feed
ed has a new value: 30.799999
The dht11 feed has a new value: 30.799999 at 2023
2023-03-16T09:21:30Z
16T09:21:30Z
21
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

This email was templated by Aliyasyed and generated automatically by Adafruit IO


in response to a user defined trigger.
Result:
Hence, Accessing the Data Pushed From Sensor To Cloud And Apply Any
Data Analytics Or Visualization Services are successfully done.

22
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 5
Date: To control any two actuators using Bluetooth

AIM: TO CONTROL ANY TWO ACTUATORS USING BLUETOOTH.

HARDWARE REQUIRMENTS :
 NODE MCU
 BLUETOOTH MODULE
 POWER MODULE
 TWO MOTORS
 MICRO USB CABLE
 12-V ADAPTER
 JUMPER WIRES
SOFTWARE REQUIRMENTS :
 ARDUINO IDE
 ARDUINO BLUECONNECT
DESCRIPTION :

 NODE MCU :
o The NodeMCU (Node MicroController Unit) is an open-source
software and hardware development environment built around an
inexpensive System-on-a-Chip (SoC) called the ESP8266.
o The ESP8266 is also hard to access and use. You must solder wires,
with the appropriate analog voltage,
o The Arduino project created an open-source hardware design and
software SDK for their versatile IoT controller. Similar to NodeMCU

 HC-05 Technical Specifications

o Serial Bluetooth module for Arduino and other microcontrollers.


o Operating Voltage: 4V to 6V (Typically +5V).
o Operating Current: 30mA.
o Range: <100m.
o Works with Serial communication (USART) and TTL compatible
o Follows IEEE 802.15.1 standardized protocol.
o Uses Frequency-Hopping Spread spectrum (FHSS).
23
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

o Can operate in Master, Slave or Master/Slave mode.


o Can be easily interfaced with Laptop or Mobile phones with Bluetooth.
Supported baud rate: 9600,19200,38400,57600,115200,230400,460800.

PROCEDURE:
 VCc,GND,Tx,Rx pins of Bluetooth module is connected to the NodeMcu.
 Tx is connected to the Rx of NodeMCU.
 Rx is connected to the Tx of NodeMCU.
 The power module contains two 5v pins and two GND. These two pins are
connected to the NodeMCU.
 The two motors are interconnected and these interconnected pins are
connected to the 12v and GND of power module.
 The Connections of motor is as fillows:
o Motor 11 is connected to the 16 pin.
o Motor 12 is connected to the 8 pin.
o Motor 21 is connected to the 4 pin.
o Motor 22 is connected to the 2 pin.
 12v is supplies to the kit.
 ArduinoBlueControl app is available in playstore and is downloaded in our
mobile.
 Bluetooth module is named as HC-05 is connected to our mobile.
 We can control the two motors by using the mobile application by giving
commands.

HC-05
ArduinoBlueControl

24
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

SOURCE CODE:
const int Motor11 = 16;
const int Motor12 = 5;
const int Motor21 = 4;
const int Motor22 = 0;
void setup() {
Serial.begin(9600);
pinMode(Motor11, OUTPUT);
pinMode(Motor12, OUTPUT);
pinMode(Motor21, OUTPUT);
pinMode(Motor22, OUTPUT);

}
void loop() {
if(Serial.available()>0)
{
char data= Serial.read();
if (data == 'F'){
digitalWrite(Motor11, HIGH);
digitalWrite(Motor12, LOW);
digitalWrite(Motor21, HIGH);
digitalWrite(Motor22, LOW);
}
if (data == 'B'){
digitalWrite(Motor11, LOW);
digitalWrite(Motor12, HIGH);
digitalWrite(Motor21, LOW);
digitalWrite(Motor22, HIGH)
}
if (data == 'L'){
digitalWrite(Motor11, HIGH);
digitalWrite(Motor12, LOW);
digitalWrite(Motor21, LOW);
digitalWrite(Motor22, LOW);
}
if (data == 'R'){
digitalWrite(Motor11, LOW);
digitalWrite(Motor12, LOW);
digitalWrite(Motor21, HIGH);
digitalWrite(Motor22, LOW);
}
if (data == 'S'){
digitalWrite(Motor11, LOW);
digitalWrite(Motor12, LOW);
digitalWrite(Motor21, LOW);
25
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

digitalWrite(Motor22, LOW);
}

OUTPUT:

Result: Hence the control of any two actuators by using Bluetooth is successfully
completed.

26
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 6
Date: Control any two actuators using Ultra Sonic Sensor

Aim: To read data from sensor (ultrasonic sensor) and send it to a requesting client.
Description: Adafruit io-platform can store, control, monitor any data from and
send it to a requesting client.
By using the ultrasonic sensor data stream sent to the cloud and process it and
send it to any requesting client or can control actuators (led) based on the
thresholds. We can even setup actions to notify us via email whenever an object is
detected.
Hardware Requirements:
 NodeMCU,
 Ultrasonic Sensor,
 Led,
 Breadboard & Connecting wires.
Software Requirements:
 Arduino IDE,
 Adafruit IO platform & libraries.

Procedure:

Step-1: Setup Arduino IDE for nodeMCU and register in Adafruit IO platform.
Step-2: open Adafruit IO platform and in IO section > open feeds tab and create a
new feed for reading sensor data.
Step-3: in dashboards tab> create a new dashboard and add a new data element
to layout.
Step-4: in alerts tab> create a new alert for sending an email when an activity is
noticed.
Step-5: now in Arduino IDE, open ”sub&pub” sketch under File>examples>Arduino
IO Adafruit.
Step-6: in the config.h file configure credentials such as API KEY, USERNAME,
WIFI SSID, WIFI PASSWORD.
Step-7: in the sketch file, add “feed” and code to read data from sensor and to control
actuator
Step-8: Connect the components as shown in the block diagram and ensure that
wi-fi is established and connect the nodeMCU to ultrasonic sensor with the pins
27
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

accordingly.
Ultrasonic Sensor NodeMCU
Vin Vcc
TRIG D1
ECHO D2
GND Gnd
Step-9: Now, compile the code and dump it onto the nodeMCU board
and check the serial monitor for the output.
Source Code:
#include "config.h"
#define TRIG D1
#define ECHO D2
#define LED D4
#define SPEED 0.343
AdafruitIO_Feed *Distance = io.feed("ultrasonic-sensor.distance");
AdafruitIO_Feed *Alert = io.feed("ultrasonic-sensor.alert");
void setup() {
Serial.begin(115200);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(LED, OUTPUT);
while(!Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
Alert->onMessage(handleMessage);
while(io.status() < AIO_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println(); Serial.println(io.statusText());
}
void loop() {
io.run();
digitalWrite(TRIG, LOW);
delayMicroseconds(5);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10); digitalWrite(TRIG, LOW);
int duration = pulseIn(ECHO, HIGH);
int distance = (duration / 2 ) * SPEED; Serial.print("distance:");
Serial.println(distance);
if(distance!=0 && distance<20) Alert->save("alert");
else Alert->save("noActivity");
if(distance!=0){
Distance->save(distance);}
delay(1000);}

28
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

void handleMessage(AdafruitIO_Data *data){


String msg = (String) data->value(); Serial.print("received <- ");
Serial.println(data->value());
if(msg == "alert") digitalWrite(LED,1);
if(msg == "noActivity") digitalWrite(LED,0);
}
Result: Hence, the data from sensor is read and stored in cloud and sent to
requesting client successfully.

29
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 7
Date: Detection of smoke using gas sensor

Aim: To detect smoke or gas by using (Gas sensor) and send it to the
cloud.

Description: Adafruit io platform can store, control, monitor


any data from and send it to a cloud platform.

By using the Gas sensor gas stream is detected sent to the cloud and
process it and send it to any requesting cloud or We can even setup actions to
notify us via email whenever LPG or smoke is detected gas sensors are
employed in factories and homes detect gas leakages.

Hardware Requirements:
 Node MCU,
 MQ-2 Gas sensor
 Breadboard & Connecting wires.
Software Requirements:
 Arduino IDE,
 Adafruit IO platform & libraries.

Procedure:
Step-1: Setup Arduino IDE for node MCU and register in Adafruit IO
platform.
Step-2: open Adafruit IO platform and in IO section > open feeds tab and create
a new feed for reading sensor data.
Step-3: in dashboards tab> create a new dashboard and add a new data element
to layout.
Step-4: in alerts tab> create a new alert for sending an email when an activity is
noticed.
Step-5: now in Arduino IDE, open ”sub&pub” sketch under
File>examples>Arduino IO
Adafruit.
Step-6: in the config.h file configure credentials such as API KEY,
USERNAME, WIFI SSID, WIFI PASSWORD.

Step-7: in the sketch file, add “feed” and code to read data from sensor and

30
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

tocontrol actuator.
Step-8: Connect the components as shown in the block diagram and ensure
that wi-fi is established and connect the node MCU to Gas sensor with the pins
accordingly.
MQ-2 GAS SENSOR NODE MCU
Vcc Vin
A0 A0
D0 No Connectin
GND GND

9: Now, compile the code and dump it onto the nodeMCU board and check the
serial monitor for the output.

Block Diagram
Source code:

#include "config.h"
int co= A0;
AdafruitIO_Feed *counter = io.feed("Welcome Feed");
void setup() {
Serial.begin(115200);
pinMode(co,INPUT);
pinMode(14,OUTPUT);
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
31
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

delay(500);
}
Serial.println();
Serial.println(io.statusText());
}
void loop() {
io.run();
int data = analogRead(co);
Serial.println(data);
delay(100);
Serial.print("sending -> ");
Serial.println(data);
counter->save(data);
if(data >600){
digitalWrite(14,HIGH);
delay(100);
}
if(data < 600)
{
digitalWrite(14,LOW);
delay(100);
}
delay(10000);

}
CONFIG CODE:

#define IO_USERNAME "yoganandham"


#define IO_KEY "30221d2013104e17ae3046055e87be2f"
#define WIFI_SSID "IOTLAB"
#define WIFI_PASS "Iotlab@123"
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
|| \
defined(ADAFRUIT_PYPORTAL)
#if !defined(SPIWIFI_SS)
#define SPIWIFI SPI
#define SPIWIFI_SS 10
#define NINA_ACK 9
#define NINA_RESETN 6
#define NINA_GPIO0 -1
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS,
SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif

32
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Confirmation email:-

OUTPUT:-

33
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 8
Date: Transferring Accelerometer Reading over WiFi

AIM: Design a system which transfers accelerometer readings over WiFi.

HARDWARE REQUIRMENTS :
 NODE MCU
 MICRO USB CABLE
 JUMPER WIRES
 ACCELEROMETER SENSOR
SOFTWARE REQUIRMENTS :
 ARDUINO IDE
 ARDUINO ACCELEROMETER LIBRARY
 ADAFRUIT ACCOUNT WITH FEED NAME
DESCRIPTION :

NODEMCU:

 The NodeMCU (Node MicroController Unit) is an open-source software and


hardware development environment built around an inexpensive System-on-a-
Chip (SoC) called the ESP8266.
 The ESP8266 is also hard to access and use. You must solder wires, with the
appropriate analog voltage,
 The Arduino project created an open-source hardware design and software
SDK for their versatile IoT controller. Similar to NodeMCU.

Accelerometer Sensor:

 Accelerometers measure linear acceleration and are also used for other
purposes such as inclination and vibration measurement. MEMS
accelerometers embed several useful features for motion and acceleration
detection, including free-fall, wakeup, single/double-tap recognition,
activity/inactivity detection, and
6D/4D orientation.

34
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Setting up a cloud platform:


To setup the platform on Adafruit, follow these steps:
 Go to the Adafruit website (https://www.adafruit.com/) and click on the
"Account" button in the top right corner of the page.
 Create a new feed of Accelerometer in the IO option of the Adafruit.
 And then create a new dashboard for Accelerometer.
 Take a guage by clicking on “New Block” option from the dashboard and
name it as X.
 Similarly, Take another gauges for each directions if you want.
 And then save the changes in dashboard.
PROCEDURE:
 The Accelerometer module has 5 pins.They are:
a) VCC
b) GND
c) X
d) Y
e) Z
 VCC – The Voltage pin should be connected to NodeMCU +3.3v.
 X - To be connected to Analog Pin A0 of the NodeMCU.
 Y – NIL (No Connection).It means it doesn’t need any connection to
NodeMcu.
 Z – NIL (No Connection).This also doesn’t need any connection to
NodeMcu.
 GND - To be connected to Ground Pin (GND) of the NodeMCU.
 Since NodeMCU has only one Analog Pin, you can connect either of X, Y, or
Z pin to it.
Circuit Diagram:

35
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Code:
Main code:
#include "config.h"
int x= A0;
AdafruitIO_Feed *counter = io.feed("Welcome Feed");
void setup() {
Serial.begin(115200);
pinMode(x,INPUT);
pinMode(12,OUTPUT);
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
while(io.status() < AIO_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
}
void loop() {
io.run();
int data = analogRead(x);
Serial.println(data);
delay(100);
Serial.print("sending -> ");
Serial.println(data);
counter->save(data);
if(data >500){
digitalWrite(14,HIGH);
delay(100);
}
36
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

if(data < 500)


{
digitalWrite(14,LOW);
delay(100);
}
delay(10000);
}

Config code:
#define IO_USERNAME "Akash_19"
#define IO_KEY "aio_CGJA68VfWFPZP7dovM2YZbHsIYk4"
#define WIFI_SSID "Akash"
#define WIFI_PASS "akash1907"
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
#defined(ADAFRUIT_PYPORTAL)
#if !defined(SPIWIFI_SS)
#define SPIWIFI SPI
#define SPIWIFI_SS 10
#define NINA_ACK 9
#define NINA_RESETN 6
#define NINA_GPIO0 -1
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS,
SPIWIFI_SS,NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
RESULT:
Hence, the system which transfers accelerometer readings over WiFi is
successfully performed.

37
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 9
Date: Perform smart alarm clock using iot

AIM: TO perform smart alarm clock using iot.

HARDWARE REQUIRMENTS :
 NODE MCU
 Rtc module
 MICRO USB CABLE
 12-V ADAPTER
 JUMPER WIRES
 RELAY MODULE
SOFTWARE REQUIRMENTS :
 ARDUINO IDE
 ARDUINO BLUECONNECT
DESCRIPTION :

 NODE MCU :

o The NodeMCU (Node MicroController Unit) is an open-source software and


hardware development environment built around an inexpensive System-on-
a-Chip (SoC) called the ESP8266.
o The ESP8266 is also hard to access and use. You must solder wires, with the
appropriate analog voltage,
o The Arduino project created an open-source hardware design and software
SDK for their versatile IoT controller. Similar to NodeMCU

 RTC Module:
o The real time clock module is the one in the figure below (front and back
view). When you first use this module, you need to solder some header
pins. As you can see in the picture above, the module has a backup battery
installed. This allows the module to retain the time, even when it’s not
being powered up.

38
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

 Buzzer:

o Buzzer is used get the sound when the alarm is triggered.

 RELAY MODULE:

o Relay modules are straightforward components. Essentially, they work


as switches. Your average relay module comprises two internal m etal
contacts. Usually, these contacts do not connect or touch each other.
However, relays include an internal switch connecting these contacts to
complete an electrical circuit that allows current flow.

39
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

PROCEDURE:

o Connect vcc- 3v to the node mcu and connect GND to GND pin of
the Node Mcu.
o Connnect SDA of the rtc module to the node mcu pin -D2
o Connect SCL of the rtc module to the node mcu pin -D3
o SQW AND 32K is not used in the project
o Add the library file to the Arduino IDE “RTC lib by Adafruit” ,
Install the librarys from manage librarys
o Connect the buzzer to the relay module .
o Connect the relay VCC,GND,IN pins with repective pins of the node
mcu.

SOURCE CODE:
#include "config.h"
#include "RTClib.h"

RTC_DS1307 rtc;

int h1,m1;
String h,m;
/************************ Example Starts Here *******************************/

// Relay is connected to PyPortal's D3 connector


#define RELAY_POWER_PIN 12 //D6
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"};

// Set up the 'relay feed'


AdafruitIO_Feed *relay = io.feed("Relay");

void setup() {

// start the serial connection


Serial.begin(115200);
pinMode(RELAY_POWER_PIN, OUTPUT);
// wait for serial monitor to open
while(! Serial);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
40
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:

// When time needs to be re-set on a previously configured device, the


// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2023, 3, 2, 5, 57, 0));
Serial.print("Connecting to Adafruit IO");

// connect to io.adafruit.com
io.connect();

// set up a message handler for the 'relay' feed.


// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io
relay->onMessage(handleMessage);

// wait for a connection


while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());

// Get the last known value from the feed


relay->get();

void loop() {
io.run();
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
41
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Serial.print(now.second(), DEC);
Serial.println();
// Check to see if the morning scheduled trigger has executed
if ((now.hour() == h1)&& (now.minute
minute() == m1)) {
Serial.println("Alarm ON");
digitalWrite(RELAY_POWER_PIN,
RELAY_POWER_PIN, HIGH HIGH);
delay(500);
Serial.println("Alarm OFF");
digitalWrite(RELAY_POWER_PIN,
RELAY_POWER_PIN, LOW LOW);
delay(50);
}
delay(2000);
}

void handleMessage(AdafruitIO_Data
ta *data) {

Serial.print("feed
"feed received new data <
<- ");
Serial.println(data->toChar());

String newdata= data->toChar();


Serial.println(newdata);
h= newdata.substring(0, 2);
h1 = h.toInt();
Serial.println(h);
m= newdata.substring(2, 4);
m1 = m.toInt();
Serial.println(m);
}

OUTPUT:

Result: Hence the control of smart alarm clock is successfully completed.

42
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 10
Date: Design a controller of light using Alexa and Arduino
IOT Cloud
Aim:To design a controller of light using Alexa and Arduino IOT Cloud.
Components:
Hardware : 1.NodeMcu
2.Relay
3.Bulb,Bulb holder
Software: 1.Arduino IDE
2.Adafruit IO platform & libraries.
3.Alexa App in Playstore.
Connections:
Relay Connected to NodeMcu
Power Supply connectd to NodeMcu
Bulb Connected to Relay.
Description:
Now you can securely connect Alexa to your Arduino IoT
Cloud projects with no additional coding required. You could use Alexa to
turn on the lights in the living room, check the temperature in the bedroom,
start the coffee machine, check on your plants, find out if your dog is
sleeping in the doghouse… the only limit is your imagination!

Below are some of the features that will be available:

 Changing the color and the luminosity of lights


 Retrieving temperature and detect motion activity from sensors
 Using voice commands to trigger switches and smart plugs
Being compatible with one of the most recognized cloud-based
services on the market, bridges the communication gap between different
applications and processes, and removes many tricky aspects that usually
follows wireless connectivity and communication. Using Alexa is as simple
as asking a question — just ask, and Alexa will respond instantly.

Procedure:

>First you have to search for the IFTTT in google,then open the first page.

43
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

>then there will appear a Applets tab,click on that.

>then we have to sign in to our google account.Then we have to select


Amazon Alexa.

>Click on Continue.Now You have to create a new trigger: if This

ADD

44
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

45
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

46
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

>then select “say a specific phrase” then we have to give a new phrase under
‘what phrase?’ as ”trigger lights on”.

>then click on continue.Then That ADD

>then select “say a specific phrase” then we have to give a new phrase under
‘what phrase?’ as ”trigger lights off”.
>Then send data to Adafruit IO.
>then create a new feed”Alexa”
>then save the data.
>Now you have to create a new Action as “HIGH” and “LOW”.
Source Code:

#include "config.h"
#define LED_PIN 13
47
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

AdafruitIO_Feed *output = io.feed("alexa");


void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
output->onMessage(handleMessage);
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
output->get();
}
void loop() {
io.run();
}
void handleMessage(AdafruitIO_Data *data) {
String cmd= data->value();
Serial.print("received <- ");
Serial.println(cmd);
if(cmd == "HIGH"){
Serial.println("Rx HIGH");
digitalWrite(LED_PIN, HIGH);
}
else if(cmd == "LOW"){
Serial.println("Rx LOW");
digitalWrite(LED_PIN, LOW);
}
}
Config.h file:
#define WIFI_SSID "Akash"
#define WIFI_PASS "akash1907"
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined
(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
defined(ADAFRUIT_PYPORTAL)
#if !defined(SPIWIFI_SS)
#define SPIWIFI SPI
#define SPIWIFI_SS 10
#define NINA_ACK 9
#define NINA_RESETN 6
#define NINA_GPIO0 -1
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS,
48
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

SPIWIFI_SS,
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
Output:

Result:Hence, the designing and controlling of light using Alexa and


Arduino IOT cloud was successfully executed

49
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 11
Date: Design an arduino colud based system to interact with
a simple webpage

Aim:To Design an arduino colud based system to interact with a simple webpage.

Hardware required :
• Node mcu

• Buzzer

• Relay

• Light

• Connecting wires

Software required:
• Arduino IDE

• Google chrome

Description:

To design an Arduino cloud-based system to interact with a simple webpage


means creating a system that allows users to remotely control an Arduino board
over the internet through a webpage. The system consists of several components,
including the Arduino board, an Ethernet or WIFI shield to connect the Arduino to
the internet, a cloud-based platform to host the backend server, and a webpage to
interact with the system.

The system allows users to control various functions of the Arduino


board, such as turning on or off LEDs, controlling motors, reading sensor data, and
so on. Users can interact with the Arduino board using a simple webpage that sends
commands and receives data to and from the board.

Overall, a cloud-based Arduino system allows for remote control and


monitoring of the board from anywhere with an internet connection. The system can
50
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

be used in a variety of applications, such as home automation, robotics, and IoT


devices.

Procedure:
• Setup the arduino IDE for nodemcu.and place the code.

• Make sure initially the should be no connections to nodemcu.

• Compile and upload the code to node mcu through cable.

• After uploading place the connections as follow

• Hardware configuration:

• AC load is directly connected light.

• DC load is connected to buzzer

• Relay is connected to D6 of nodemcu.

• 5v relay is connected to D7 of nodemcu

• After giving the connections upload the code again

• In the output it will show the ip address .

• Enter that ip iddress in google chrome.

• A wed page will open as follow

51
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

• When we press on button in web page bulb will on and when we press of
button the bulb will off.

Source code:
#include <ESP8266WiFi.h>
const char* ssid = "IOTLAB";
const char* password = "Iotlab@123";
WiFiServerserver(80);
String header;
String output5State = "off";

52
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

String output4State = "off";


const int output5 = 12;
const int output4 = 13;
unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long timeoutTime = 2000;
void setup() {
Serial.begin(115200);
pinMode(output5, OUTPUT);
pinMode(output4, OUTPUT);
digitalWrite(output5, LOW);
digitalWrite(output4, LOW);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}

void loop(){
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
currentTime = millis();
previousTime = currentTime;
while (client.connected() &&currentTime - previousTime<= timeoutTime) {
currentTime = millis();
if (client.available()) {
char c = client.read();
Serial.write(c);
header += c;
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

if(header.indexOf("GET /5/on") >= 0) {


53
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Serial.println("GPIO 5 on");
output5State = "on";
digitalWrite(output5, HIGH);
} else if (header.indexOf("GET /5/off") >= 0) {
Serial.println("GPIO 5 off");
output5State = "off";
digitalWrite(output5, LOW);
} else if (header.indexOf("GET /4/on") >= 0) {
Serial.println("GPIO 4 on");
output4State = "on";
digitalWrite(output4, HIGH);
} else if (header.indexOf("GET /4/off") >= 0) {
Serial.println("GPIO 4 off");
output4State = "off";
digitalWrite(output4, LOW);
}
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:,\">");
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>");
client.println("<body><h1>PBRVITS Web Server</h1>");
client.println("<p>GPIO 5 - State " + output5State + "</p>");
if (output5State=="off") {
client.println("<p><a href=\"/5/on\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/5/off\"><button class=\"button
button2\">OFF</button></a></p>");
}
client.println("<p>GPIO 4 - State " + output4State + "</p>");

if (output4State=="off") {
client.println("<p><a href=\"/4/on\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/4/off\"><button class=\"button
button2\">OFF</button></a></p>");
}
client.println("</body></html>");
client.println();
54
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
header = "";
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

Output:

When we press on button in web page light will on

55
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Result: Hence, designing of arduino cloud based system to interact with a simple
webpage was successfully completed.

56
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 12
Date:
Medicine remainder system

Aim: To design the Medicine Alert system which alerts the elderly patients to take
medicines on time.

Components:
software:
1. Adafruit
2. Arduino IDE
Hardware:
1.NODE-MCU
2. connecting wires/jumper wires
3.Rtc module
4. Buzzer
5.4-pin LCD display
Libraries:
1- Adafruit IO Arduino
2. RTC.h Library
3. Node-MCU libraries.

Description:
1. Some people overlook to take care of health because of the Lack of an expert,
people are forced to submit in frequent health related problems .
2.By Analyzing the data an IoT based Reminder system has been developed. It is
designed to assist the patient who forgot to take medicine.
3.By this system, patients will no longer have to worry about their daily medication.
The application will send the notification when its time take medicine.
4.The medicine reminder will facilitate the users to require the right medication on
time.
5.This system provides a real- time monitoring system that allow related people to
monitor the patients activity remotely.

57
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Block diagram:

Circuit Connection:

RTC MAodule:
SCL->D1
SDA-> D2
VCC -> 3.3V/5V
GND->Ground
LCD 4 pin display :
SCL-> D1
SDA-> D2
VCC->3.3V
GND->GND
Buzzer:
Two ends/pins:
One end -> D6 , other end -> GND

Procedure :-
1.Let's get into the Adafruit software process to run the code.
2.Firstly, open the Arduino IDE platform -> go to file -> Examples ->Adafruit I0
Arduino ->Arduino_00_publish. And place the code in that publish file.
3.It will provide another file called “config.h” file.
4.In that config file there are some changes need to be done:
5.we have to provide IO_ Username, IO_KEY which is available in the adafruit.
6. Also we have to provide WIFI_SSID , WIFI_PASS which means wifi network
name & wifi password.

58
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

7.After that go to Adafruit & click on the new dashboard & set a new feed then
click on the new block-> select text block.
8.Now we have to set the alarms (morning, afternoon ,evening/night) for taking
medicines.
9.By setting these alarms the system will remind the medicine to take on time &
alert the patients.

SOURCE CODE :

#include "config.h"
#include "RTClib.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int h1,m1,h2,m2,h3,m3;
String hs1,ms1,hs2,ms2,hs3,ms3;
int Buzzer = 12; //d6
#define RELAY_POWER_PIN 12
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
AdafruitIO_Feed *relay = io.feed("Relay");
void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Smart Medicine ");
lcd.setCursor(5,1);
lcd.print("Reminder");
delay(2000);
pinMode(Buzzer,OUTPUT);
Serial.begin(115200);
pinMode(RELAY_POWER_PIN, OUTPUT);
while(! Serial);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
59
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

rtc.adjust(DateTime(2023, 3,5,14,34, 0));


Serial.print("Connecting to Adafruit IO");
io.connect();
relay->onMessage(handleMessage);
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
relay->get();
lcd.clear();
}

void loop() {
io.run();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

lcd.setCursor(0,0);
lcd.print(now.hour(), DEC);
lcd.setCursor(2,0);
lcd.print(":");
lcd.setCursor(3,0);
lcd.print(now.minute(), DEC);
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print(now.day(), DEC);
lcd.setCursor(8,0);
lcd.print("/");
60
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

lcd.setCursor(9,0);
lcd.print(now.month(), DEC);
lcd.setCursor(11,0);
lcd.print("/");
lcd.setCursor(12,0);
lcd.print(now.year(), DEC);

lcd.setCursor(2,1);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);

delay(1000);
if ((now.hour() == h1)&& (now.minute() == m1)) {

Serial.println("Medicen 1 reminder ON");

lcd.setCursor(0,0);
lcd.print("Medicen1 Reminder");
lcd.setCursor(0,1);
lcd.print(" !!Alert!! ");
digitalWrite(RELAY_POWER_PIN, HIGH);
delay(500);
lcd.clear();
Serial.println("Medicen1 reminder OFF");
digitalWrite(RELAY_POWER_PIN, LOW);
delay(50);
}

if (((now.hour() == h2)&& (now.minute() == m2))) {

Serial.println("Medicen 2 reminder ON");

lcd.setCursor(0,0);
lcd.print("Medicen2 Reminder");
lcd.setCursor(0,1);
lcd.print(" !!Alert!! ");
digitalWrite(RELAY_POWER_PIN, HIGH);
delay(500);
lcd.clear();
Serial.println("Medicen2 reminder OFF");
digitalWrite(RELAY_POWER_PIN, LOW);
delay(50);
}
if ((now.hour() == h3)&& (now.minute() == m3)) {

Serial.println("Medicen3 reminder ON");

lcd.setCursor(0,0);
61
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

lcd.print("Medicen3 Reminder");
lcd.setCursor(0,1);
lcd.print(" !!Alert!! ");
digitalWrite(RELAY_POWER_PIN, HIGH);
delay(500);
lcd.clear();
Serial.println("Medicen3 reminder OFF");
digitalWrite(RELAY_POWER_PIN, LOW);
delay(50);
}
//delay(1000);
}

void handleMessage(AdafruitIO_Data *data) {

Serial.print("feed received new data <- ");


Serial.println(data->toChar());

String newdata= data->toChar();


Serial.println(newdata); // M1=09:00+M2=12:00+M3=20:00
hs1= newdata.substring(3, 5); //save 3,4 location
ms1= newdata.substring(6, 8);
hs2= newdata.substring(12, 14);
ms2= newdata.substring(15, 17);
hs3= newdata.substring(21, 23);
ms3= newdata.substring(24, 27);
h1 = hs1.toInt();
Serial.println(h1);

m1 = ms1.toInt();
Serial.println(m1);

h2 = hs2.toInt();
Serial.println(h2);

m2 = ms2.toInt();
Serial.println(m2);

h3 = hs3.toInt();
Serial.println(h3);

m3 = ms3.toInt();
Serial.println(m3);

62
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

OUTPUT :

RESULT : Hence ,medicine reminder alert system was executed successfully.

63
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Expt. No. 13
Date: Design a system which connects your door to the cloud
and open it from anywhere
Aim:To design a system which connects your door to the cloud and open it from
anywhere

Hardware Requirements:
1.Relay module
2.NodeMcu
3.5v power supply
4.12v power supply
5.jumper wires
6.EM(electromagnetic lock)

Software Requirements:
1.Arduino IDE
2.Adafruit IO adruino library
3.ESP8266 Module

Description:
EM lock stands for electromagnetic lock, which is a type of lock that uses an
electromagnet to hold the door closed. To design a system that connects your door
to the cloud and allows you to open it from anywhere using an EM lock, you will
need the following components:
1. An EM lock: An EM lock is an electronic lock that uses an electromagnet to
hold the door closed. It can be easily installed on your door and is compatible with
most access control systems.
2. A Wi-Fi enabled access control system: A Wi-Fi enabled access control
system is a device that connects your EM lock to the internet. It allows you to
control the lock from anywhere.
64
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

3. A cloud
oud server: A cloud server is a remote server that stores data and
provides services over the internet. In this case, it will store the access credentials
for your lock and allow you to remotely access and control it.

Block diagram:

Circuit Diagram:

Procedure:
1.Setup Arduino IDE for node MCU and register in Adafruit IO platform.
2. open Adafruit IO platform and in IO section > open feeds tab and create a new
feed as Door
3.in dashboards tab> create a new dashboard as lock and add a new data elem
element to
layout

65
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

4. now in Arduino IDE, open “subscriber” sketch under File>examples>Arduino IO


Adafruit .
5. in the config.h file configure credentials such as API KEY, USERNAME, WIFI
SSID, WIFI PASSWORD.
6. in the sketch file, add “feed” as door
7. Connect the components as shown in the block diagram and ensure that wi-fi is
established and connect the node MCU to ultrasonic sensor with the pins
accordingly.
Relay NodeMcu
IN1 D6
Vcc vcc
GND GND
8.Give 5v of power supply and 12v power supply to board
9. Now, compile the code and dump it onto the node MCU board
10.After we can check output by clicking the toggle as OPEN and CLOSE at
adafruit platform
Source Code:
#include "config.h"
#define LED_PIN 12
AdafruitIO_Feed *output = io.feed("led");
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
while (!Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
output->onMessage(handleMessage);
while (io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
output->get();
}

void loop() {
io.run();
}
void handleMessage(AdafruitIO_Data *data) {
String cmd = data->value();
66
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Serial.print("received <- ");


);
Serial.println(cmd);
if (cmd == "HIGH") {
Serial.println("Rx HIGH");
digitalWrite(LED_PIN, HIGH);

}
else if (cmd == "LOW") {
Serial.println("Rx LOW");
digitalWrite(LED_PIN, LOW);
}
}

Output:

we can see in the below figure the lock was opened

Conclusion: Design a system which connects your door to the cloud and open it
67
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

from anywhere was successfully completed.

Expt. No. 14
Date: Build a line follower robot using raspberry pi

Aim : To build a line follower robot using raspberry pi.


Components :
Software Requirements:
• vnc viewer
Hardware Requirements:
• power supply
• raspberry pi control robot
Description :
Line Follower Robot is able to track a line with the help of an IR sensor. It
has an IR Transmitter and IR receiver. The IR transmitter (IR LED) transmits the
light and the Receiver (Photodiode) waits for the transmitted light to return back.
An IR light will return back only if it is reflect by a surface. Whereas, all surfaces
do not reflect an IR light, only white the colour surface can completely reflect them
and black colour surface will completely observe them as shown in the figure
below.

68
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

Block Diagram:

Procedure :
1. Give the power supply to robot and then switch on it .
2. Make sure your laptop, mobile, raspberry pi should be connected to same
hotspot.
3. Install the vnc viewer and then open it.
4. In mobile phone connected devices it will show the raspberry pi Ip address
5. Enter that Ip address in vnc viewer .
6. It will ask username and password .
69
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

7. Username is pi and password is raspberry pi and click on ok.


8. It will open the raspberry pi window and the open the file which consists of Line
follower code
9. Click on run module and place the robot on black line with white surface.
10. The robot follows only black line and reflect the white surface.
Source Code:

import RPi.GPIO as GPIO


import time
# Pin Definitions:
L_sensor=2
R_sensor=3
m10 = 4
m11 = 17
m20 = 27
m21 = 22
# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(m10, GPIO.OUT)
GPIO.setup(m11, GPIO.OUT)
GPIO.setup(m20, GPIO.OUT)
GPIO.setup(m21, GPIO.OUT)

GPIO.setup(L_sensor, GPIO.IN)
GPIO.setup(R_sensor, GPIO.IN)

GPIO.output(m10, GPIO.LOW)
GPIO.output(m11, GPIO.LOW)
GPIO.output(m20, GPIO.LOW)
GPIO.output(m21, GPIO.LOW)
print("Here we go! Press CTRL+C to exit")
try:
while 1:
if (GPIO.input(L_sensor) == False and GPIO.input(R_sensor) == True): #
pressed
GPIO.output(m10,GPIO.LOW)
GPIO.output(m11,GPIO.LOW)
GPIO.output(m20,GPIO.HIGH)
GPIO.output(m21,GPIO.LOW)
print('Turn Left')
if ((GPIO.input(L_sensor) == True) and (GPIO.input(R_sensor) == False)): #
pressed
GPIO.output(m10,GPIO.HIGH)
GPIO.output(m11,GPIO.LOW)
GPIO.output(m20,GPIO.LOW)
70
IOT DEVELOPMENT USING CLOUD LAB DEPARTMENT OF CSE

GPIO.output(m21,GPIO.LOW)
print('Turn Right')
if ((GPIO.input(L_sensor) == True) and (GPIO.input(R_sensor) == True)):
# pressed
GPIO.output(m10,GPIO.HIGH)
GPIO.output(m11,GPIO.LOW)
GPIO.output(m20,GPIO.HIGH)
GPIO.output(m21,GPIO.LOW)
print('Move forward')
if ((GPIO.input(L_sensor) == False) and (GPIO.input(R_sensor) == False)):
# pressed
GPIO.output(m10,GPIO.LOW)
GPIO.output(m11,GPIO.LOW)
GPIO.output(m20,GPIO.LOW)
GPIO.output(m21,GPIO.LOW)
print('Stop')
pwm.stop()
GPIO.cleanup()
Result :
Hence, we had successfully built a line follower robot using raspberry pi.

71

You might also like