Iot Record111
Iot Record111
Aim:
To create various Iot protocol using 6LOWPAN,MQTT Arduino IDE developed in
a sensor in a MQTT request
Procedure:
Step 1: start the arduino program
Step 2: create new project
Step 3:Write to the coding in Electronic MQTT RGB controller
Step 4:Check the MQTT Broker connectiong in URl
Step 5: Run to the Arduino
Step 6: Stop the program
Program:
* MQTT/Phant RGB Controller
* by: Jim Lindblom, SparkFun Electronics
* with lots of help from: Todd Treece (thanks Todd!)
* Fun with MQTT, Arduino, and Phant. This example sketch uses
* MQTT to subscribe to a Phant data stream. When values labeled
* "red", "green", or "blue" change on the Phant stream, the
* Arduino will be notified and update its LEDs accordingly.
#include <SPI.h> // Include SPI for the Ethernet library
#include <Ethernet.h>
#include <PubSubClient.h>
EthernetClient ethClient;
// Create an mqttClient object. Give it the MQTT broker server,
// the MQTT port (default is 1883), a callback function, and
// an EthernetClient object to use:
PubSubClient mqttClient(server, 1883, mqttCallback, ethClient);
// LED pins:
byte redLEDPin = 3;
byte greenLEDPin = 5;
byte blueLEDPin = 6;
void setup()
{
// Initialize LED pins:
pinMode(redLEDPin, OUTPUT);
digitalWrite(redLEDPin, LOW);
pinMode(greenLEDPin, OUTPUT);
digitalWrite(greenLEDPin, LOW);
pinMode(blueLEDPin, OUTPUT);
digitalWrite(blueLEDPin, LOW);
// loop just needs to call the MQTT loop, which keeps the
// connection alive, and checks for any new published data.
void loop()
{
mqttClient.loop();
}
return atoi(val);
}
Output:
Failed to connect. Looping : True
Connected! IP: https://data.sparkfun.com/input/roE6z8QZq5iyEdrMGwdG?
Ethernet.localIP()
Connected Succesfully
AIM:
Algorithm:
Step 1: Needed Components. For the build, you will need the following: ...
Step 2: Building the Circuit. Every LED has two sides - one negative and one
positive. ...
Step 1
need to component:
1 x Raspberry Pi
1 x USB cable
1 x LED
1 x Breadboard
1 x LAN cable
1 x 50-ohm resistor
2 x Jumper wires
Step2
build in circuit:
Step 3
setting up:
Step 4
Program:
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
GPIO.output(18,GPIO.LOW)
Step 5
Run:
python file-name.py
Ex.No:04 To develop an application to send and receive data with Arduino
Date: using HTTP request
Aim:
To implement a simple ESP32 Web Server with HTTP protocol responsible for
communication between Client and Server
Apparatus required:
1. ESP32 Kit -1
2. Connecting Wire -1
3. Breadboard -1
4. LED -2
5. Resistance(220ohm) -2
Program:
#include <WIFI.h>
int gpio16Value;
int gpio17Value;
String request;
void setup()
{
Serial.begin(115200); /* Begin Serial Communication with 115200 Baud Rate */
pinMode(gpio16LEDPin, OUTPUT);
pinMode(gpio17LEDPin, OUTPUT);
digitalWrite(gpio16LEDPin, LOW);
digitalWrite(gpio17LEDPin, LOW);
Serial.print("\n");
Serial.println(ssid);
while(WiFi.status() != WL_CONNECTED)
Serial.print("*");
delay(100);
Serial.print("\n");
Serial.println(WiFi.SSID());
delay(100);
/* The next four lines of Code are used for assigning Static IP to ESP32 */
/* assign it to ESP32 */
/* please un-comment the next four lines and make necessary changes */
//IPAddress ip(192,168,1,6);
//IPAddress gateway(192,168,1,1);
//IPAddress subnet(255,255,255,0);
delay(2000);
Serial.print("\n");
Serial.print("\n");
Serial.print("http://");
Serial.println(WiFi.localIP());
Serial.print("\n");
void loop()
return;
Serial.println("New Client!!!");
while (client.connected())
if (client.available())
char c = client.read();
request += c;
Serial.write(c);
/* character) and the line is blank, the http request has ended, */
* 192.168.1.6/GPIO16ON
* 192.168.1.6/GPIO16OFF
* 192.168.1.6/GPIO17ON
* 192.168.1.6/GPIO17OFF
*/
/* Based on the URL from the request, turn the LEDs ON or OFF */
if (request.indexOf("/GPIO16ON") != -1)
digitalWrite(gpio16LEDPin, HIGH);
gpio16Value = HIGH;
if (request.indexOf("/GPIO16OFF") != -1)
digitalWrite(gpio16LEDPin, LOW);
digitalWrite(gpio17LEDPin, HIGH);
gpio17Value = HIGH;
if (request.indexOf("/GPIO17OFF") != -1)
digitalWrite(gpio17LEDPin, LOW);
gpio17Value = LOW;
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println(); // IMPORTANT
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head>");
client.println("<style>");
text-align: center;}");
client.println("</style>");
client.println("</head>");
client.println("<body>");
if(gpio16Value == LOW)
{
client.println("<p>GPIO16 LED Status: OFF</p>");
client.print("<p><a href=\"/GPIO16ON\"><button class=\"button button1\">Click
to
turn ON</button></a></p>");
}
else
{
client.println("<p>GPIO16 LED Status: ON</p>");
turn OFF</button></a></p>");
if(gpio17Value == LOW)
{
client.println("<p>GPIO17 LED Status: OFF</p>");
turn ON</button></a></p>");
else
turn OFF</button></a></p>");
}
client.println("</body>");
client.println("</html>");
break;
}
if(c == '\n')
{
currentLineIsBlank = true;
currentLineIsBlank = true;
{
currentLineIsBlank = false;
}
//client.print("\n");
}
}
delay(1);
request = "";
//client.flush();
client.stop();
Serial.println("Client disconnected");
Serial.print("\n");
}
Output:
Ex.No:05 Application to Measures the Room Temperature & Posts the
Date: value on the Cloud platform
AIM:
Apparatus required:
1. ESP32
2. DHT11 Sensor
3. Connecting Wires
4. Breadboard
Software Required:
1. Google Firebase
2. Arduino IDE
Algorithm:
#include <FirebaseESP32.h>
#include <WiFi.h>
#include "DHT.h"
#define DHTPIN 14
FirebaseData firebaseData;
FirebaseJson json;
void setup() {
Serial.begin(115200);
dht.begin();
Serial.print("Connecting...");
Serial.print(".");
delay(300);
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST,FIREBASE_Authorization_key);
void loop() {
if (isnan(hum) || isnan(temp) ){
return;
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("°C");
Serial.print(hum);
Serial.print("%");
Serial.println();
delay(200);
}
Output:
325°c
Ex.No:06 Application to Measures the Moisture of Soil & Posts the data
Date: over Google Firebase Cloud platform
AIM:
To develop an application to measures the Soil Moisture level using Soil moisture
sensor interface with ESP32 & Send the Sensor Readings to Google Firebase cloud
platform.
Apparatus required:
1. ESP32
3. Connecting Wires
4. Breadboard
Software Required:
1. Google Firebase
2. Arduino IDE
Algorithm:
#include <FirebaseESP32.h>
#include <WiFi.h>
FirebaseData firebaseData;
FirebaseJson json;
int _moisture,sensor_analog;
void setup(void){
Serial.print("Connecting...");
Serial.print(".");
delay(300);
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST,FIREBASE_Authorization_key);
void loop(void){
sensor_analog = analogRead(sensor_pin);
Serial.print("Moisture = ");
Serial.println("%");
252
Ex.No:07 Application for Measuring the Distance using Ultrasonic sensor
Date: and Post Distance value on Google Cloud IoT platform
AIM:
Apparatus required:
1. ESP32
2. Ultrasonic Sensor
3. Connecting Wires
4. Breadboard
Software Required:
1. Google Firebase
2. Arduino IDE
Algorithm:
#include <FirebaseESP32.h>
#include <WiFi.h>
#define FIREBASE_Authorization_key
"h9C1lYYTitgWPSxmomeljva7fZZNTfKhop32QXhi"
FirebaseData firebaseData;
FirebaseJson json;
long duration;
float distanceCm;
float distanceInch;
void setup() {
Serial.print("Connecting...");
Serial.print(".");
delay(300);
Serial.println();
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST,FIREBASE_Authorization_key);
void loop()
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
// Convert to inches
Serial.println(distanceCm);
Serial.println(distanceInch);
delay(1000);
}
Output:
350
350
350
350
350
350
Ex.No:08 To Develop an application based on ultrasonic sensor
Date:
AIM:
To test ultrasound sensor with arduino UNO board and display in serial
monitor of Arduino IDE.
Apparatus requird:
2. Ultrasound Sensor
3. Connecting wires
Algorithm:
Program:
// defines variables
void setup() {
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
Serial.print(distance);
Serial.println(" cm");
Output:
325
325
325
325
325
325
325
Ex.No:09 To Develop IoT application using Django framework and
Date: Firebase/ Bluemix platform
Aim:
To create an application that reads the data from firebase using Django framework.
Procedure:
Step 1: Go to firebase console by logging into the google account and click on Add
Project. https://console.firebase.google.com/u/0/
Step 2.1: Add the project name and click continue button
Step 2.2: Again click on the continue button
Step 2.3: Select the Default Account for Firebase in the Select an account drop
down list.
Step 2.4: Click on the continue button
Step 3.1: Register the web app by clicking on the web logo
Step 3.2: Add the WebApp name and click on Register app
Step 3.3: Select the Use a <script> tag radio button, copy the highlighted code and
paste it in the notepad or text editor. Click on the Continue to the console button.
Step 4: Create a new real time database from the firebase console by clicking on the
Create Database button and then click Next button.
Step 4.2: Select the test mode radio button and then click Enable button.
Step 5: Add a new child by clicking on the + button. Add the following data in the
database.
Step 6: Open VS code and open a terminal from VS Code, Create a Django project
by using the following command
django-admin
admin startproject firebase_project
Step 7: Change the directory to firebase_project by using the following command:
cd firebase_project
Step 8: Create a Django App within the firebase_project folder by using the
following command.
django-admin
admin startproject fireapp
Step 9: Navigate to the firebase_project directory and edit the settings.py file, Add
the created fireapp in the INSTALLED_APPS list.
Step 10: To connect Firebase and Django, we need to install a ppython package
named pyrebase by using the following command.
Step 11: Create a python file name it as view.py in the fireapp directory and add the
following code
import pyrebase
config = {
"apiKey":
ey": "AIzaSyCRU5AOXrcO4n29Ssn8T-zR39b2LxjhQVo",
"AIzaSyCRU5AOXrcO4n29Ssn8T zR39b2LxjhQVo",
"authDomain": "fireapp
"fireapp-e659f.firebaseapp.com",
"projectId": "fireapp-e659f",
"fireapp
"storageBucket": "fireapp-e659f.appspot.com",
"messagingSenderId": "1059698448539",
"appId": "1:1059698448539:web:17b236061d5879ed880e3e",
"measurementId": "G-3GV9ZR0HD5"
firebase=pyrebase.initialize_app(config)
authe = firebase.auth()
database=firebase.database()
def index(request):
name = database.child('Data').child('Name').get().val()
department = database.child('Data').child('Department').get().val()
college = database.child('Data').child('College').get().val()
context = {
'name':name,
'department':department,
'college':college
<!DOCTYPE html>
<html>
<head>
<title>Firebase Demo</title>
</head>
<body>
<h1>Firebase Database</h1>
<p>Name : {{name}}</p>
<p>Department : {{department}}</p>
<p>College : {{college}}</p>
</body>
</html>
Step 13: We need to update the DIRS to the path of the templates folder in our
settings.py file. Don’t forget to import the os librarar. Add import os on top of the
code.
the following code
Step 14: Next, we edit our urls.py by adding the
urlpatterns = [
path('admin/', admin.site.urls),
Open a web browser and type the URL in the address bar
Step 16:Open
http://localhost:8000/
Output:
Ex.No:10 To Develop a commercial IoT application using temperature
Date:
AIM :
To write Arduino sketch to sense the temperature using DHT 11 sensor and to
monitor its output in mobile using IOT.
COMPONENTS REQUIRED
NODE MCU 1
DHT 11 SENSOR 1
USB cable 1
PROGRAM :
#include <ESP8266WiFi.h>
#include<ESP8266WebServer.h>
#include "DHT.h"
// Uncomment one of the lines below for whatever DHT sensor type you're using!
const char* ssid = "SAIHAAN"; // Enter SSID here/ / type the name of the hotspot
const char* password = "43214321..."; //Enter Password here // type the password of
the hotspot ESP8266WebServer server(80); // DHT Sensor uint8_t DHTPin =D8;
Serial.begin(115200);
{ delay(1000);
Serial.print(".");
Serial.println("");
Serial.println("WiFiconnected..!");
Serial.println(WiFi.localIP());
server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound); server.begin();
void handle_OnConnect() {
void handle_NotFound(){
{
String ptr = "<!DOCTYPE html><html>\n";
align: center;}\n";
bottom:10px;}\n";
}
Output:
Result: