Implementation of Iot
Implementation of Iot
By
Mr S K Hiremath
Asst Professor
Department of Computer Science and Engineering
3
BVRIT HYDERABAD College of Engineering for Women
4
BVRIT HYDERABAD College of Engineering for Women
The Internet of Everything (IoE) brings together people, process, data, and things to make
networked connections more relevant and valuable than ever before-turning information into
actions that create new capabilities, richer experiences, and unprecedented economic opportunity
for businesses, individuals, and countries.
5
BVRIT HYDERABAD College
src of Engineering for Women
IoT for Sports
Before After
(Generates Enough Data)
7
BVRIT HYDERABAD College of Engineering for Women
Activity Trackers
Fitbit helps you live a healthy, balanced life by tracking your all-day activity, exercise,
sleep, and weight.
8
BVRIT HYDERABAD College of Engineering for Women
http://blog.claricetechnologies.com/2014/03/demystifying-the-internet-of-things/ 9
BVRIT HYDERABAD College of Engineering for Women
Microcontroller-based devices are more constrained & your application code run directly on the processor without the support of an OS. 10
BVRIT HYDERABAD College of Engineering for Women
11
BVRIT HYDERABAD College of Engineering for Women
12
BVRIT HYDERABAD College of Engineering for Women
Arduino Pinout - https://www.arduino.cc/en/Main/FAQ
8-bit
CPU
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a
signal switched between on and off. 14
BVRIT HYDERABAD College of Engineering for Women
For example, we can use PWM to change the brightness of an LED; the wider the “ON” pulses, the brighter the LED glows.
analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the
DEFAULT: The default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V
Arduino boards)
INTERNAL: Built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56
volts on the ATmega8(not available on the Arduino Mega)
EXTERNAL: The voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Syntax
analogReference(type)
INTERNAL2V56, or EXTERNAL)
15
BVRIT HYDERABAD College of Engineering for Women
Arduino IDE - Download from
https://www.arduino.cc/en/Main/Software
16
BVRIT HYDERABAD College of Engineering for Women
https://create.arduino.cc
17
BVRIT HYDERABAD College of Engineering for Women
Arduino Web Editor
18
BVRIT HYDERABAD College of Engineering for Women
https://github.com/arduino-libraries
https://cloud.arduino.cc/cloud
19
BVRIT HYDERABAD College of Engineering for Women
Built-in (Pin 13) LED Blink
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
20
BVRIT HYDERABAD College of Engineering for Women
RGB - LED
21
BVRIT HYDERABAD College of Engineering for Women
1 - RGB Connections - Safer to connect
via resistors
22
BVRIT HYDERABAD College of Engineering for Women
2 - RGB Connections - Safer to connect
via resistors
23
BVRIT HYDERABAD College of Engineering for Women
Fading RGB
If you want to use it for common cathode leds you'll have to change all the "analogWrite( COLOR, 255 - colorVal );" lines to "analogWrite( COLOR, colorVal );" (without
the "255 - "), then it should work (i didn't test it). http://www.instructables.com/id/Fading-RGB-LED-Arduino/?ALLSTEPS
#define GREEN 3
#define BLUE 5 redVal = 0;
#define RED 6 blueVal = 0;
#define delayTime 20 greenVal = 255;
void setup() { for( int i = 0 ; i < 255 ; i += 1 ){
pinMode(GREEN, OUTPUT); blueVal += 1;
pinMode(BLUE, OUTPUT); greenVal -= 1;
pinMode(RED, OUTPUT); analogWrite( BLUE, 255 - blueVal );
digitalWrite(GREEN, HIGH); analogWrite( GREEN, 255 - greenVal );
digitalWrite(BLUE, HIGH);
digitalWrite(RED, HIGH); delay( delayTime );
} }
int redVal;
int blueVal; redVal = 0;
int greenVal; blueVal = 255;
void loop() { greenVal = 0;
int redVal = 255; for( int i = 0 ; i < 255 ; i += 1 ){
int blueVal = 0; redVal += 1;
int greenVal = 0; blueVal -= 1;
for( int i = 0 ; i < 255 ; i += 1 ){ analogWrite( RED, 255 - redVal );
greenVal += 1; analogWrite( BLUE, 255 - blueVal );
redVal -= 1;
analogWrite( GREEN, 255 - greenVal ); delay( delayTime );
analogWrite( RED, 255 - redVal ); }
delay( delayTime ); }
}
24
BVRIT HYDERABAD College of Engineering for Women
RGB Random Colors
int ledcolor = 0; //http://www.instructables.com/id/Arduino-Examples-1-Make-An-RGB-Led-Randomly-Flash/?ALLSTEPS
int a = 1000; //this sets how long the stays one color for
int red = 11; //this sets the red led pin
delay(a);
int green = 12; //this sets the green led pin
analogWrite(red, 0);
int blue = 13; //this sets the blue led pin
digitalWrite(green, LOW);
break;
void setup() { //this sets the output pins
case 4: //if ledcolor equals 4 then the led will turn
cyan
pinMode(red, OUTPUT);
analogWrite(red, 168);
pinMode(green, OUTPUT);
digitalWrite(blue, HIGH);
pinMode(blue, OUTPUT);
delay(a);
}
analogWrite(red, 0);
digitalWrite(blue, LOW);
void loop() {
break;
int ledcolor = random(7); //this randomly selects a number between 0 and 6
case 5: //if ledcolor equals 5 then the led will turn
magenta
switch (ledcolor) {
digitalWrite(green, HIGH);
case 0: //if ledcolor equals 0 then the led will turn red
digitalWrite(blue, HIGH);
analogWrite(red, 204);
delay(a);
delay(a);
digitalWrite(green, LOW);
analogWrite(red, 0);
digitalWrite(blue, LOW);
break;
break;
case 1: //if ledcolor equals 1 then the led will turn green
case 6: //if ledcolor equals 6 then the led will turn
digitalWrite(green, HIGH);
white
delay(a);
analogWrite(red, 100);
digitalWrite(green, LOW);
digitalWrite(green, HIGH);
break;
digitalWrite(blue, HIGH);
case 2: //if ledcolor equals 2 then the led will turn blue
delay(a);
digitalWrite(blue, HIGH);
analogWrite(red, 0);
delay(a);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
digitalWrite(blue, LOW);
break;
break;
case 3: //if ledcolor equals 3 then the led will turn yellow
}
analogWrite(red, 160); 25
BVRIT HYDERABAD College of Engineering for Women
digitalWrite(green, HIGH);
}
123d.circuits.io - Design, Compile, and Simulate your electronic projects Online – for
Free
26
BVRIT HYDERABAD College of Engineering for Women
Random & Fading RGB simulation using
Random RGB: 123d.circuits.io [Hands-on]
● https://123d.circuits.io/circuits/1806406-random-rgb-leds/embed#brea
dboard
● https://123d.circuits.io/circuits/1806406-random-rgb-leds/embed#sche
matic
● https://123d.circuits.io/circuits/1806406-random-rgb-leds/embed#pcb
Fading RGB:
● https://123d.circuits.io/circuits/1806331-fading-rgb-leds/embed#breadb
oard
● https://123d.circuits.io/circuits/1806331-fading-rgb-leds/embed#schem
atic
● https://123d.circuits.io/circuits/1806331-fading-rgb-leds/embed#pcb
27
BVRIT HYDERABAD College of Engineering for Women
Simulation using LDR and LM35 Sensor
28
BVRIT HYDERABAD College of Engineering for Women
https://circuits.io/circuits/3434475-reaction/embed#breadboard
29
BVRIT HYDERABAD College of Engineering for Women
https://circuits.io/circuits/3434475-reaction/embed#breadboard
30
BVRIT HYDERABAD College of Engineering for Women
31
BVRIT HYDERABAD College of Engineering for Women
Sensors Bring IoT Projects to Life
Sensors are the nose, eyes and ears…Without sensors, there's no IoT. src
Img Src
32
BVRIT HYDERABAD College of Engineering for Women
List of Sensors
33
BVRIT HYDERABAD College of Engineering for Women
LM35 Analog Temperature
Sensor
34
BVRIT HYDERABAD College of Engineering for Women
LM35 Features
● Calibrated Directly in Celsius (Centigrade)
● Linear + 10-mV/°C Scale Factor
● Operates from 4 V to 30 V
● Suitable for Remote Applications
● Rated for Full −55°C to 150°C Range
● Low Self-Heating, 0.08°C in Still Air
35
BVRIT HYDERABAD College of Engineering for Women
LM35 Applications
● Power Supplies
● Battery Management
● HVAC
37
BVRIT HYDERABAD College of Engineering for Women
const int groundpin = A0;
const int powerpin = A2;
int tempPin = A1;
float tempC;
float reading;
void setup() {
Serial.begin(9600);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
analogReference(INTERNAL);
}
void loop() {
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.print("Temperature: ");
Serial.println(tempC);
delay(1000); 38
} BVRIT HYDERABAD College of Engineering for Women
const int groundpin = A0;
const int powerpin = A2; void loop() {
int tempPin = A1;
if(Serial.available() > 0) {
con = Serial.read();
float tempC;
}
int reading;
int led=13;
if(con == '1') {
int con=0; digitalWrite(led, HIGH);
} else {
void setup() { digitalWrite(led, LOW);
}
Serial.begin(9600);
pinMode(groundpin, OUTPUT); reading = analogRead(tempPin);
pinMode(powerpin, OUTPUT); tempC = reading / 9.31;
pinMode(led, OUTPUT); Serial.println(tempC);
digitalWrite(groundpin, LOW); delay(1000);
digitalWrite(powerpin, HIGH); }
analogReference(INTERNAL);
}
39
BVRIT HYDERABAD College of Engineering for Women
Analog-to-Digital Converter (ADC)
40
BVRIT HYDERABAD College of Engineering for Women
Arduino 3D Print Cases
41
BVRIT HYDERABAD College of Engineering for Women
LDR - Light Dependent Resistor
Sensor
42
BVRIT HYDERABAD College of Engineering for Women
LDR Sensor - Resistance vs Light
Intensity
43
BVRIT HYDERABAD College of Engineering for Women
LDR Connections
44
BVRIT HYDERABAD College of Engineering for Women
Blink the LED if LDR crosses 500
//http://www.hobbytronics.co.uk/arduino-tutorial8-nightlight
int sensorPin = A0; // select the input pin for the ldr
unsigned int sensorValue = 0; // variable to store the value coming from the ldr
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
// read the value from the ldr:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if(sensorValue>500) digitalWrite(13, HIGH); // set the LED on
else digitalWrite(13, LOW); // set the LED on
// For DEBUGGING - Print out our data, uncomment the lines below
//Serial.print(sensorValue, DEC); // print the value (0 to 1024)
//Serial.println(""); // print carriage return 45
BVRIT HYDERABAD College of Engineering
//delay(500); for Women
DHT11 - Digital Humidity and
Temperature
Safer to connect a resistor between pin 1 and 2
46
BVRIT HYDERABAD College of Engineering for Women
DHT11 Features
● Low cost
● 3 to 5V power and I/O
● 2.5mA max current use during conversion (while
requesting data)
● Good for 20-80% humidity readings with 5% accuracy
● Good for 0-50°C temperature readings ±2°C accuracy
● No more than 1 Hz sampling rate (once every second)
● Body size 15.5mm x 12mm x 5.5mm
● 4 pins with 0.1" spacing
47
BVRIT HYDERABAD College of Engineering for Women
DHT11 Applications
● Weather stations for providing humidity at
cheaper cost
● Sense temperature level of soil
● Power Supplies
● Battery Management
● HVAC (stands for Heating, Ventilation and Air Conditioning)
delay(2000); 50
BVRIT HYDERABAD College of Engineering for Women }
ADXL335
Accelerometer
51
BVRIT HYDERABAD College of Engineering for Women
ADXL335 Features
● 3-axis sensing
● Small, low-profile package
● Low power - 350 μA (typical)
● Single-supply operation
● 1.8 V to 3.6 V
● 10,000 g shock survival
● Excellent temperature stability
● BW adjustment with a single capacitor per axis
● RoHS Restriction of Hazardous Substances /WEEE Waste Electrical and Electronic Equipment Directive
lead-free compliant
BVRIT HYDERABAD College of Engineering for Women
52
ADXL335
Applications
● Cost sensitive, low power, motion and tilt-sensing
applications
● Mobile devices
● Gaming systems
● Disk drive protection
● Image stabilization
● Sports and health devices
53
BVRIT HYDERABAD College of Engineering for Women
Connections
55
BVRIT HYDERABAD College of Engineering for Women
HC - SR04 Ultrasonic Range Sensor -
Details
Product features: Ultrasonic ranging module HC - SR04 provides 2cm - 400cm
non-contact measurement function, the ranging accuracy can reach to 2mm.
The module includes ultrasonic transmitter, receiver and control circuit. The
basic principle of working is:
(1) IO trigger for at-least 10μs high level signal
(2) The Module automatically sends eight 40 kHz and detects whether there is
a pulse signal back
(3) If the signal is back, through high level, then the time of high output IO
duration is the time from sending ultrasonic to returning
Test distance = (high level time×velocity of sound (340ms-1) / 2
56
BVRIT HYDERABAD College of Engineering for Women
/* HC-SR04 Sensor // The sensor is triggered by a HIGH
https://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor- pulse of 10 or more microseconds.
distance-measuring-module-133696 // Give a short LOW pulse beforehand
to ensure a clean HIGH pulse:
This sketch reads a HC-SR04 ultrasonic rangefinder and pinMode(trigPin, OUTPUT);
returns the distance to the closest object in range. To do digitalWrite(trigPin, LOW);
this, it sends a pulse to the sensor to initiate a reading, delayMicroseconds(2);
then listens for a pulse to return. The length of the digitalWrite(trigPin, HIGH);
returning pulse is proportional to the distance of the delayMicroseconds(10);
object from the sensor. digitalWrite(trigPin, LOW);
The circuit: // Read the signal from the sensor: a
* VCC connection of the sensor attached to +5V HIGH pulse whose duration is the time
* GND connection of the sensor attached to ground (in microseconds) from the sending of
* TRIG connection of the sensor attached to digital pin the ping to the reception of its echo
2 off of an object.
* ECHO connection of the sensor attached to digital pin pinMode(echoPin, INPUT);
4 duration = pulseIn(echoPin, HIGH);
Original code for Ping))) example was created by David A. // convert the time into a distance
Mellis inches =
Adapted for HC-SR04 by Tautvidas Sipavicius microsecondsToInches(duration);
This example code is in the public domain.*/ cm =
const int trigPin = 2; microsecondsToCentimeters(duration);
const int echoPin = 4; Serial.print(inches);
void setup() { Serial.print("in, ");
// initialize serial communication: Serial.print(cm);
Serial.begin(9600); Serial.print("cm");
} Serial.println();
57
BVRIT HYDERABAD College of Engineering for Women
void loop() {
// establish variables for duration of the ping, }
delay(100);
Contd - Details here
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
58
BVRIT HYDERABAD College of Engineering for Women
Ultrasonic Distance Sensor Piezo
Buzzer
59
BVRIT HYDERABAD College of Engineering for Women
If the soil is homogeneous &
receives similar watering over
an area then a single probe will
give a representative reading
for that area. If regions of soil
are different in composition,
for example sandy or loamy,
then you may want to use a
probe for each type of soil
region, and for areas that
receive different watering. Src
60
BVRIT HYDERABAD College of Engineering for Women
void loop()
Soil Moisture Sensor YL-69 {
int s = analogRead(A0); //take a sample
/* Connection pins: Serial.print(s);
Serial.print(" - ");
Arduino Soil Moisture Sensor YL-69
A0 Analog A0 if(s >= 1000) {
Serial.println("Sensor is not in the Soil or
5V VCC DISCONNECTED");
}
GND GND if(s < 1000 && s >= 600) {
*/ Serial.println("Soil is DRY");
}
void setup() if(s < 600 && s >= 370) {
{ Serial.println("Soil is HUMID");
}
Serial.begin(9600); if(s < 370) {
pinMode(A0, INPUT); //set up analog pin 0 to beSerial.println("Sensor in WATER");
}
input delay(1000);
// pinMode(2, OUTPUT); // red led }
Specifications:
62
BVRIT HYDERABAD College of Engineering for Women
http://www.instructables.com/id/Simple-2-way-motor-control-for-the-arduino/?ALLSTEPS
//2-Way motor control
int motorPin1 = 9; // One motor wire connected to digital pin 9 void rotateLeft(int speedOfRotate, int length){
int motorPin2 = 10; // One motor wire connected to digital pin 10 analogWrite(motorPin1, speedOfRotate); //rotates
motor
// The setup() method runs once, when the sketch starts digitalWrite(motorPin2, LOW); // set the Pin
motorPin2 LOW
void setup() { delay(length); //waits
// initialize the digital pins as an output: digitalWrite(motorPin1, LOW); // set the Pin
pinMode(motorPin1, OUTPUT); motorPin1 LOW
pinMode(motorPin2, OUTPUT); }
}
void rotateRight(int speedOfRotate, int length){
// the loop() method runs over and over again,as long as the Arduino has power analogWrite(motorPin2, speedOfRotate); //rotates
motor
void loop() digitalWrite(motorPin1, LOW); // set the Pin
{ motorPin1 LOW
rotateLeft(150, 500); delay(length); //waits
rotateRight(50, 1000); digitalWrite(motorPin2, LOW); // set the Pin
rotateRight(150, 1000); motorPin2 LOW
rotateRight(200, 1000); }
rotateLeft(255, 500);
rotateRight(10, 1500);
}
63
BVRIT HYDERABAD College of Engineering for Women
Source
PIR Sensor
64
BVRIT
Source HYDERABAD College of Engineering for
Source Women
/* http://www.arduinoeletronica.com.br */ Codebender Link
int PIR = 2;
int led = 13;
void setup(){
Serial.begin(9600);
pinMode(PIR, INPUT);
pinMode(led,OUTPUT);
}
void loop(){
int lerPIR = digitalRead(PIR);
if(lerPIR == LOW){ //was motion detected
digitalWrite(led,HIGH);
Serial.println("Motion Detected!");
// delay(2000);
}
else{
digitalWrite(led,LOW);
Serial.println("No Motion!");
}
} 65
BVRIT HYDERABAD College of Engineering for Women
HC05 Bluetooth
Module
66
BVRIT HYDERABAD College of Engineering for Women
HC05 Bluetooth
Features
● 2.45GHz Frequency
● Asynchronous Speed 2.1Mbps (max) 160 Kbps
● Security: Authentication
● Profile: Bluetooth Serial Port
● Power Supply: +3.3 VDc
● Working Temperature: >20C
● Cost : Around INR 300
67
BVRIT HYDERABAD College of Engineering for Women
HC05 Bluetooth Module
68
BVRIT HYDERABAD College of Engineering for Women
Setting up Name and Password with AT
Commands
● VCC Pin ➝ 5V
● GND Pin ➝ GND
● RX Pin ➝ RX
● TX Pin ➝ TX
● Key Pin/State Pin ➝ 5V
● Baud Rate: 9600
■ Press RESET BUTTON of your Bluetooth [if available]
● In Serial Monitor, type:
○ Type “AT”, Check for response “OK”
○ AT+NAME=”name_of_your_interest”
○ AT+PSWD=”4_digit_password”
● Password must be 4-digit
69
BVRIT HYDERABAD College of Engineering for Women
ArduDroid - Reading Input using Bluetooth from Android
70
BVRIT HYDERABAD College of Engineering for Women
Code for controlling built-in LED using Bluetooth Module
int ledPin = 13;
if (state == '0') {
int state = 0;
//int flag = 0; digitalWrite(ledPin, LOW);
// if(flag == 0) {
void setup() { Serial.println("LED: off");
pinMode(ledPin, OUTPUT); //flag = 1;
digitalWrite(ledPin, LOW);
Serial.begin(9600); // Default connection }
//rate for my BT module
} else if (state == '1') {
digitalWrite(ledPin, HIGH);
void loop() { //if(flag == 0){
if(Serial.available() > 0){
state = Serial.read(); Serial.println("LED: on");
//flag=0; //flag = 1;
} }
}
71
BVRIT HYDERABAD College of Engineering for Women
Single Channel Relay Switch
72
BVRIT HYDERABAD College of Engineering for Women
Step by Step Guide: IoT
with MITCustom
App AppInventor
73
BVRIT HYDERABAD College of Engineering for Women
ESP8266 Wifi Serial
Module
74
BVRIT HYDERABAD College of Engineering for Women
Always connect VCC, CH_PD to 3.3V
only
75
BVRIT HYDERABAD College of Engineering for Women
76
BVRIT HYDERABAD College of Engineering for Women
ESP8266 Wifi Serial Module
● 802.11 b/g/n protocol
● Wi-Fi Direct (P2P), Soft-AP- SoftAP is an abbreviated term for "software enabled access point." This is software enabling a
computer which hasn't been specifically made to be a router into a wireless access point. It is often used interchangeably with the term "virtual router".
related information
● Summarizing data to reduce the volume and eliminate
79
BVRIT HYDERABAD College of Engineering for Women
https://thingspeak.com
80
BVRIT HYDERABAD College of Engineering for Women
#include<stdlib.h>
const int groundpin = A0; ThingSpeak API with LM35 sensor
const int powerpin = A2;
const int receiver = 0; if(Serial.find("Error")){
float tempC; Serial.println("AT+CIPSTART error");
int reading; return;
int tempPin = A1; }
int led=13; int con=0; // prepare GET string
String apiKey = "27RPRHYGBJ335YGE"; String getStr = "GET /update?key=";
void setup() { getStr += apiKey;
Serial.begin(115200); getStr +="&field1=";
pinMode(groundpin, OUTPUT); getStr += String(strTemp);
pinMode(powerpin, OUTPUT); getStr += "\r\n\r\n";
pinMode(led, OUTPUT); // send data length
digitalWrite(groundpin, LOW); cmd = "AT+CIPSEND=";
digitalWrite(powerpin, HIGH); cmd += String(getStr.length());
analogReference(INTERNAL); Serial.println(cmd);
// reset ESP8266 if(Serial.find(">")){
Serial.println("AT+RST"); Serial.print(getStr);
Serial.println("AT+CIPMUX=0"); }
} else{
void loop() { // alert user
reading = analogRead(tempPin); Serial.println("AT+CIPCLOSE");
tempC = reading / 9.31; }
// convert to string // thingspeak needs 15 sec delay between updates
char buf[16]; delay(5000);
String strTemp = dtostrf(tempC, 5, 2, buf); }
Serial.println(tempC);
// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "api.thingspeak.com"; // api.thingspeak.com
cmd += "\",80";
81
Serial.println(cmd);
BVRIT HYDERABADDetails
College of Engineering for Women
#include<stdlib.h>
int reading; ThingSpeak API with LDR sensor
int led=13; int con=0;
String apiKey = "N3EC0RWRM8JJG0RD"; if(Serial.find("Error")){
void setup() { Serial.println("AT+CIPSTART error");
Serial.begin(115200); return;
}
pinMode(led, OUTPUT); // prepare GET string
String getStr = "GET /update?key=";
analogReference(INTERNAL); getStr += apiKey;
// reset ESP8266 getStr +="&field1=";
Serial.println("AT+RST"); getStr += String(reading);
Serial.println("AT+CIPMUX=0"); getStr += "\r\n\r\n";
} // send data length
void loop() { cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
reading = analogRead(A0); Serial.println(cmd);
if(Serial.find(">")){
// convert to string Serial.print(getStr);
Serial.println(reading); }
// TCP connection else{
String cmd = "AT+CIPSTART=\"TCP\",\""; // alert user
cmd += "api.thingspeak.com"; // api.thingspeak.com Serial.println("AT+CIPCLOSE");
cmd += "\",80"; }
Serial.println(cmd); // thingspeak needs 15 sec delay between updates
delay(5000);
}
82
BVRIT HYDERABADDetails
College of Engineering for Women
#include<stdlib.h>
int reading;
int led=13; int con=0;
String apiKey = "N3EC0RWRM8JJG0RD";
void setup() {
Serial.begin(115200);
pinMode(led, OUTPUT); 83
BVRIT HYDERABAD College of Engineering for Women
84
BVRIT HYDERABAD College of Engineering for Women
NodeMCU - An open-source firmware and development kit that helps you to
prototype your IoT product within a few Lua script lines
85
BVRIT HYDERABAD College of
src Engineering for Women
In NodeMCU use GPIO numbers in Arduino Code...Connect long pin of LED/Relay to 5V TTL & short one
to D4
86
BVRIT HYDERABAD College of Engineering for Women
Simple LED Blink using NodeMCU
void setup() {
// initialize digital pin 2 as an output.
pinMode(2, OUTPUT);
}
88
BVRIT HYDERABAD College of Engineering for Women
cntd...
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
89
BVRIT HYDERABAD College of Engineering for Women
Output in ThingSpeak
90
BVRIT HYDERABAD College of Engineering for Women
Explore Embedded - The module goes into programming mode with a single reset switch.
● Fits on a breadboard!
● Single button 'Reset' switch for programming. Uses MOSFET's to put the module in
programming mode.
● All pins of ESP12E taken out
● Separate serial pins breakout compatible with FTDI cable layout.
● On-board LM1117-3.3V regulator
● Works with Arduino IDE for ESP8266
● ESP8266 ESP12E features
○ 802.11 b/g/n protocol
○ Wi-Fi Direct (P2P), soft-AP
○ Integrated TCP/IP protocol stack
○ Integrated TR switch, balun, LNA, power amplifier and matching network
○ Integrated PLL, regulators, and power management units
○ +19.5dBm output power in 802.11b mode
○ Integrated temperature sensor
○ Supports antenna diversity
○ Power down leakage current of < 10uA
○ Integrated low power 32-bit CPU could be used as application processor
○ SDIO 2.0, SPI, UART
○ STBC, 1×1 MIMO, 2×1 MIMO
○ A-MPDU & A-MSDU aggregation & 0.4ïs guard interval
○ Wake up and transmit packets in < 2ms 91
BVRIT HYDERABAD College of Engineering for Women
○ Standby power consumption of < 1.0mW (DTIM3)
Explore Embedded - Connect with
CP2102
93
BVRIT HYDERABAD College of Engineering for Women
Output in Serial Monitor
94
BVRIT HYDERABAD College of Engineering for Women
IoT Protocols
95
BVRIT HYDERABAD College of Engineering for Women
MQTT (formerly MQ Telemetry Transport) is an ISO standard (ISO/IEC PRF 20922) publish-subscribe based "light
weight" messaging protocol for use on top of the TCP/IP protocol. It is designed for connections with remote locations
where a "small code footprint" is required or the network bandwidth is limited. It is ideal for mobile applications because
of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers.
96
BVRIT HYDERABAD College of Engineering for Women
Public MQTT Brokers
http://moxd.io/2015/10/public-mqtt-brokers/
97
BVRIT HYDERABAD College of Engineering for Women
https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm?hl=en 98
BVRIT HYDERABAD College of Engineering for Women
Controlling Relay Switch using MQTT from void loop() {
Cloud/App
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
if (!client.connected()) mqtt_reconnect();
client.loop();
// setup WiFi & MQTT details client.publish("sdmcetcse/light1", "SDMCET Dwd");
const char* ssid = "GovindAP"; delay(5000);
const char* pass = "*************"; }
const char* mqtt_server = "test.mosquitto.org”; // for MQTT callback
int status = WL_IDLE_STATUS; void callback(char* topic, byte* payload, unsigned int length) {
String topic_1 = "sdmcetcse/light1"; // get topic as a string
int builtin_led = 2; String strTopic = String(topic);
WiFiClient wifiClient; // get payload as a string
PubSubClient client(wifiClient); char charPayload[length];
void setup() { for (int i = 0; i < length; i++) charPayload[i] = (char)payload[i];
// setup serial String strPayload = (String(charPayload)).substring(0, length);
Serial.begin(115200); Serial.println(strPayload);
// setup & initialize gpio if (topic_1.equals(strTopic)) {
pinMode (builtin_led, OUTPUT); if (strPayload.equals("off")) {
digitalWrite(builtin_led, HIGH); client.publish("sdmcetcse/light1", "Light-1 OFF");
// setup wifi light_off(builtin_led);
setup_wifi(); } else if (strPayload.equals("on")) {
// setup mqtt client.publish("sdmcetcse/light1", "Light-1 ON");
client.setServer(mqtt_server, 1883); light_on(builtin_led);
client.setCallback(callback); }
} } 99
BVRIT
Link to PubSubClient HYDERABAD
Library College ofCode
Engineering for
Credits: NBN RIOT Women
Workshop, Pune
else {
client.publish("NJMZuDbYxt_err", "mistake in topic error");
}
}
void light_on (int light) {
digitalWrite(light, LOW);
}
void light_off (int light) {
digitalWrite(light, HIGH);
}
void setup_wifi() {
delay(10);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void mqtt_reconnect() {
while (!client.connected()) {
if (client.connect("Sw_Cub1_ESPClient")) {
client.subscribe("sdmcetcse/#");
client.publish("sdmcetcse/light1", "Connected");
delay(100);
} else {
delay(5000);
}
100
} BVRIT HYDERABAD College of Engineering for Women
101
BVRIT HYDERABAD College of Engineering for Women
https://play.google.com/store/apps/details?id=at.tripwire.mqtt.client&hl=en
Connect 3.3 & GND of NodeMCU to TTL Logic...5 volt of TTL to relay switch and D4 of NodeMCU to relay..
102
BVRIT HYDERABAD College of Engineering for Women
Installing Additional Boards on Arduino
[Offline]
● Offline Arduino IDE is required for writing code directly on ESP8266
● Goto “File” ⇒ “Preferences”, paste in “Additional Boards Manager URL”:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
● Go-to “Tools” ⇒ “Board” ⇒ “Boards Manager”
● Search for ESP8266 and select the version (2.1.0 current version) and click
on “Install” button
● Once installed, select “Generic ESP8266 Module” from “Tools” ⇒ “Board”
103
BVRIT HYDERABAD College of Engineering for Women
Uploading code directly to ESP8266
● Connect GPIO0 pin to GND
104
BVRIT HYDERABAD College of Engineering for Women
Built-in LED Blink using ESP8266
/* ESP8266 Blink by Simon Peter Blink the blue LED on the ESP-01 module This example code is in the public domain The blue LED on the ESP-01 module is
connected to GPIO1 (which is also the TXD pin; so we cannot use Serial.print() at the same time) Note that this sketch uses LED_BUILTIN to find the pin with the
internal LED */
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
}
105
BVRIT HYDERABAD College of Engineering for Women
Updating ESP8266 Firmware
107
BVRIT HYDERABAD College of Engineering for Women
GSM Module for Arduino
Features:
● Send/Receive SMS
● Make/Receive Calls
● Place to insert SIM
● On-board 3.5 mm jack to
connect a headphone to answer
calls
● Uses AT commands to configure
and communicate with the
shield
108
BVRIT HYDERABAD College of Engineering for Women
Applications of GSM Module
Image Credits 1 2 3 4 5
● Home Automation
● Vehicle Tracking
● Remote Monitoring and Control
● Agricultural Automation
● Industrial Automation
● GPRS Data Logging
109
BVRIT HYDERABAD College of Engineering for Women
Sending SMS via GSM Module
#include <GSM.h> char txtMsg[200];
#define PINNUMBER "" readSerial(txtMsg);
// initialize the library instance Serial.println("SENDING");
GSM gsmAccess; Serial.println();
GSM_SMS sms; Serial.println("Message:");
void setup() { Serial.println(txtMsg);
// initialize serial communications and wait for port to open: sms.beginSMS(remoteNum);
Serial.begin(9600); sms.print(txtMsg);
while (!Serial) ; // wait for serial port to connect (Leonardo only) sms.endSMS();
Serial.println("SMS Messages Sender"); Serial.println("\nCOMPLETE!\n");
// connection state }
boolean notConnected = true; /*Read input serial*/
// Start GSM shield int readSerial(char result[]) {
// If your SIM has PIN, pass it as a parameter of begin() in quotes int i = 0;
while(notConnected) { while(1) {
if(gsmAccess.begin(PINNUMBER)==GSM_READY) while (Serial.available() > 0) {
notConnected = false; char inChar = Serial.read();
else { if (inChar == '\n') {
Serial.println("Not connected"); result[i] = '\0';
delay(1000); Serial.flush();
} return 0;
} }
Serial.println("GSM initialized"); if(inChar!='\r')
} {
void loop() { result[i] = inChar;
Serial.print("Enter a mobile number: "); i++;
char remoteNum[20]; // telephone number to send sms }
readSerial(remoteNum); }
Serial.println(remoteNum); }
110
BVRIT HYDERABAD College of Engineering for Women
Serial.print("Now, enter SMS content: "); }
Arduino Ethernet Shield
111
BVRIT HYDERABAD College of Engineering for Women
Ethernet Shield Features
● Based on W51000 chip
● It has internal 16K buffer
● Connection speed upto 10/100Mb
● Comes bundled with Arduino Ethernet Library
● Contains on-board micro SD slot (requires use of external SD card library)
You can bridge the internet connection between your laptop with
wifi/hotspot access and ethernet cable (which is plugged to Ethernet shield)
and try code to send sensor value to Thingspeak...
112
BVRIT HYDERABAD College of Engineering for Women
Display DHCP IP Address
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
EthernetClient client;
void setup() {
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;) ;
}
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
}
Serial.println();
}
void loop() {
}
113
BVRIT HYDERABAD College of Engineering for Women
114
BVRIT HYDERABAD College of Engineering for Women
115
BVRIT HYDERABAD College of Engineering for Women
Codenvy.com + Google App Engine
Code
http://9.xd09spz04.appspot.com
The program is developed using codenvy.com IDE and HTML/Java Servlets. This program
sends temperature value from LM35 to Google App Engine using ESP8266
116
BVRIT HYDERABAD College of Engineering for Women
index.html
<!DOCTYPE html>
<html>
<head>
<title>Temp Sensors Demo</title>
</head>
<center>
<h3>
LM35 Analog Temperature values being stored on Google Datastore.
</h3>
<body>
</body>
</center>
</html>
117
BVRIT HYDERABAD College of Engineering for Women
package arduino;
Entity tempObj = new Entity("Sensor_DB", dbKey);
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; tempObj.setProperty("temperature", temp);
import javax.servlet.http.HttpServletRequest; datastore.put(tempObj);
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.google.appengine.api.datastore.*; //if (btn.equals("Refresh"))
Query q = new Query("Sensor_DB") ;
public class TempSenseServelt extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) PreparedQuery pq = datastore.prepare(q);
throws IOException, ServletException { resp.getWriter().println("<center><table>");
resp.setContentType("text/html"); resp.getWriter().println("<th>Temp</th>");
118
BVRIT HYDERABAD College of Engineering for Women
Arduino code to turn on/off pin-13 LED from local - Telnet & Browser - 192.168.4.1/?pin=1
[Ensure you have connected your mobile/laptop to the WiFi Module]
119
BVRIT HYDERABAD College of Engineering for Women
9.xd09spz04.appspot.com
#include<stdlib.h>
const int groundpin = A0;
if(Serial.find("Error")){
const int powerpin = A2;
const int receiver = 0; Serial.println("AT+CIPSTART error");
float tempC; return;
int reading; }
int tempPin = A1;
// prepare GET string
int led=13; int con=0;
void setup() { String getStr = "GET /TempSense?";
Serial.begin(115200); getStr +="temperature=";
pinMode(groundpin, OUTPUT); getStr += String(strTemp);
pinMode(powerpin, OUTPUT);
getStr += " HTTP/1.1\nHost: 9.xd09spz04.appspot.com\n";
pinMode(led, OUTPUT);
digitalWrite(groundpin, LOW); getStr += "Connection: close";
digitalWrite(powerpin, HIGH); getStr += "\r\n\r\n";
analogReference(INTERNAL);
// reset ESP8266
// send data length
//Serial.println("AT+RST");
Serial.println("AT+CWMODE=3"); cmd = "AT+CIPSEND=4,";
delay(500); cmd += String(getStr.length());
Serial.println("AT+CIPMUX=1"); Serial.println(cmd);
delay(500);
}
if(Serial.find(">")){
void loop() { Serial.print(getStr);
reading = analogRead(tempPin); }
tempC = reading / 9.31;
else{
// convert to string
char buf[16]; // alert user
String strTemp = dtostrf(tempC, 5, 2, buf); Serial.println("AT+CIPCLOSE");
Serial.println(tempC); }
// TCP connection
delay(16000);
String cmd = "AT+CIPSTART=4,\"TCP\",\"";
cmd += "9.xd09spz04.appspot.com"; // url }
120
cmd += "\",80";
BVRIT HYDERABAD College of Engineering for Women
Serial.println(cmd);
Step by Step Guide
121
BVRIT HYDERABAD College of Engineering for Women
Interact With the Web in Real-time Using Arduino
, Firebase and Angular.js
122
BVRIT HYDERABAD College of Engineering for Women
123
BVRIT HYDERABAD College of Engineering for Women
http://www.open-electronics.org/how-send-data-from-arduino-to-google-docs-spreadsheet/
BOLT IoT Cloud
http://www.instructables.com/id/Program-your-Arduino-with-a-Android-device/?ALLSTEPS
125
BVRIT HYDERABAD College of Engineering for Women
Architecture of IoT Based Projects
126
BVRIT HYDERABAD College of Engineering for Women
Why integrate Cloud with IoT ?
Various stages of IoT data management in Google Cloud Platform. Details are here.
Building Internet of Things solutions involves solving challenges across a wide range of domains. Cloud Platform brings scale of
infrastructure, networking, and a range of storage and analytics products you can use to make the most of device generated
data. 127
BVRIT HYDERABAD College of Engineering for Women
Complementarity
and Integration of Cloud and IoT
128
BVRIT HYDERABAD College of Engineering for Women
Expected hands-on time: 20 Mins
In this example, the IoT Real-Time Insights service, in the Bluemix, is used to
demonstrate the analysis of mobile data that is being sent to the IBM Watson IoT
Platform Connect.
Software: IBM Bluemix account with IBM Watson IoT Platform and RTI service
IBM IoT Real-Time Insights – Analytics designed for the Internet of Things
Energy from Light, Energy from Motion, Energy from Temperature - Buy Here
https://www.enocean.com/en/products/enocean-link
Source
134
BVRIT HYDERABAD College of Engineering for Women
135
BVRIT HYDERABAD College of Engineering for Women
Raspi Pinout
136
BVRIT HYDERABAD College of Engineering for Women
Source: http://www.farnell.com/datasheets/2020826.pdf
137
BVRIT HYDERABAD College of Engineering for Women
https://www.inet.se/files/pdf/1974044_0.pdf
https://www.inet.se/files/pdf/1974044_0.pdf Source: PubNub
138
BVRIT HYDERABAD College of Engineering for Women
Formatting an SD Card (Source: GitHub)
The following steps are done on your computer.
139
BVRIT HYDERABAD College of Engineering for Women
1. Download the Noobs zip file from raspberrypi.org and extract to a desired location.
2. Open up the SD card drive, and drag-drop the unzipped Noobs contents (not the entire folder!) you just
downloaded, into the SD card. Then eject the SD card.
140
BVRIT HYDERABAD College of Engineering for Women
Installing Raspbian on Raspberry Pi (Source: GitHub)
From now on you are working directly on your Raspberry Pi.
141
BVRIT HYDERABAD College of Engineering for Women
After connecting to a monitor:
1. Your Raspberry Pi will boot, and a window will appear with a list of operating systems that you can install. Select Raspbian by
ticking the box next to Raspbian and click on Install.
2. Raspbian will run through its installation process. Just wait. This takes a while.
3. When the install process has completed, the Raspberry Pi configuration menu (raspi-config) will load. You can exit this menu by
using Tab on your keyboard to move to Finish.
The default login for Raspbian is username pi with the password raspberry.
pi@raspberrypi ~$ startx
142
BVRIT HYDERABAD College of Engineering for Women
Source: https://github.com/pubnub/workshop-raspberrypi
143
BVRIT HYDERABAD College of Engineering for Women
Update and Upgrade Raspbian
First, update your system's package list, by using this command on a terminal:
When you do not have an access to work directly on your Pi, you may need to access to your Pi from another computer.
$ hostname -I
144
BVRIT HYDERABAD College of Engineering for Women
Hands-ON
Pi-Light LED: A "Hello World" of Hardware (Detailed Steps are Here)
145
BVRIT HYDERABAD College of Engineering for Women
# Import the GPIO and time libraries
import RPi.GPIO as GPIO
import time
# Cause the light to blink 7 times and print a message each time.
# To blink the light, we call GPIO.output and pass as parameters the pin number (LIGHT) and the state we want.
# True sets the pin to HIGH (sending a signal), False sets it to LOW.
# To achieve a blink, we set the pin to High, wait for a fraction of a second, then set it to Low.
# Adding keyboard interrupt with try and except so that program terminates when user presses Ctrl+C.
try:
while True:
GPIO.output(LIGHT,True)
time.sleep(0.5)
GPIO.output(LIGHT,False)
time.sleep(0.5)
print("blink")
except KeyboardInterrupt:
GPIO.cleanup()
146
BVRIT HYDERABAD College of Engineering for Women
Source: https://github.com/pubnub/workshop-raspberrypi/blob/master/projects-python/led/led.py
Hands-ON
147
BVRIT HYDERABAD College of Engineering for Women
IoT-fying Your LED
Remote-controlling LED from Web Interface
100.xd09spz04.appspot.com
148
BVRIT HYDERABAD College of Engineering for Women
Source Code - remote-led.py
150
Detailed
BVRIT Steps Are Here
HYDERABAD College of GitHub
Engineering forCode is Here
Women
Monitor DHT Values on Cloud - using
PubNub
https://www.pubnub.com/console
151
BVRIT HYDERABAD College of Engineering for Women
Working with other Sensors
https://github.com/pubnub/workshop-raspberrypi/tree/master/projects-pyt
hon
https://github.com/raspberrypi
152
https://www.pubnub.com/docs/web-javascript/data-streams-publish-and-subscribe
BVRIT HYDERABAD College of Engineering for Women
USB Web Camera
Working with PiCamera
The camera module is a great accessory for the Raspberry Pi, allowing users to take still pictures & record video in full HD.
153
BVRIT HYDERABAD College
Steps to take still of record
pictures and Engineering
a video for Women
http://diyhacking.com/connect-raspberry-pi-to-laptop-display
154
BVRIT HYDERABAD College of Engineering for Women
https://www.raspberrypi.org/blog/piui-control-your-pi-with-your-phone 155
Raspberry PI ZERO: THE $5 COMPUTER
The Raspberry Pi Zero is half the size of a Model A+, with twice the
utility.
156
BVRIT HYDERABAD College of Engineering for Women
Connecting Internet on Raspberry Pi
ZERO
IBM Watson IoT Platform Analytics Real-Time Insights enables you to perform analytics on real-
time data from your IoT devices and gain diagnostic insights.
http://connected-car.mybluemix.net
BVRIT HYDERABADClick
College of Engineering for Women
Here for Recipe 159
Node-RED
A visual tool for wiring the Internet of Things
A tool for wiring together hardware devices, APIs and online services in new and interesting ways
The Watson Developer Cloud is a library of Watson APIs that you can use to create Powered by Watson apps.
From gaining insights from text to analyzing images and video, you can tap into the power of Watson APIs to build cognitive apps
http://node-red-bluemix-starter-mbp-git.mybluemix.net/red/
Although each device might send only a single data point every minute, when you multiply that data by a large number
of devices, you quickly need to apply big data strategies and patterns. Details are here
162
BVRIT HYDERABAD College of Engineering for Women
IoT with Cloud and Big Data
163
BVRIT HYDERABAD College of Engineering for Women
RPi Cam Image Analysis using Visual Recognition method
Raspberry Pi Camera
165
BVRIT HYDERABAD College of Engineering for Women
166
BVRIT HYDERABAD College of Engineering for Women
Image Credits: Google
167
168
BVRIT HYDERABAD College of Engineering for Women
Temboo - Put the IoT to work for
you
169
BVRIT HYDERABAD College of Engineering for Women
Thank you