0% found this document useful (0 votes)
4 views

Implementation of Iot

The document outlines a course on the Fundamentals of the Internet of Things (IoT) focusing on the implementation of Raspberry Pi and Arduino. It covers various aspects of IoT, including the role of sensors, microcontrollers, and practical applications like fan engagement in sports and health tracking. Additionally, it provides coding examples and simulations for using sensors like LM35 and LDR in IoT projects.

Uploaded by

nsml.keerthi2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Implementation of Iot

The document outlines a course on the Fundamentals of the Internet of Things (IoT) focusing on the implementation of Raspberry Pi and Arduino. It covers various aspects of IoT, including the role of sensors, microcontrollers, and practical applications like fan engagement in sports and health tracking. Additionally, it provides coding examples and simulations for using sensors like LM35 and LDR in IoT projects.

Uploaded by

nsml.keerthi2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 170

FUNDAMENTALS OF INTERNET OF THINGS

By
Mr S K Hiremath
Asst Professor
Department of Computer Science and Engineering

BVRIT HYDERABAD College of Engineering for Women


Name of the Course Fundamentals of Internet of Things
Course Code EC600OE
Year & Semester B.Tech III Year Ii Sem
Section CSE – B
Name of the Faculty Mr S K Hiremath
Lecture Hour | Date 25 | March 2021
Name of the Topic IMPLEMENTATION OF RASPBERRY PI
Course Outcome(s) Know the Installations of Internet of Things using Raspberry Pi.

BVRIT HYDERABAD College of Engineering for Women


Internet of Things
Hands-On Workshop

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)

... fan engagement, audience engagement, training (Dangal !), fitness... 6


BVRIT HYDERABAD College of Engineering for Women
Intel Curie
Managing Fan Lifecycle

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

The ATmega328 is a single-chip microcontroller created by Atmel in the megaAVR family. 13


BVRIT HYDERABAD College of Engineering for Women
Arduino Uno Specifications

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

input range). The options are:

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)

Parameters type: which type of reference to use (DEFAULT, INTERNAL, INTERNAL1V1,

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

● Temperature Sensitive Appliances


36
BVRIT HYDERABAD College of Engineering for Women
LM35 Analog Temperature Sensor
ConnectionsAlways connect LM35 on Arduino Board directly

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)

Analog pins might have access to an on-board Analog-to-Digital Converter


(ADC) circuit.
When we read the value of a digital I/O pin in code, the value must be either
HIGH or LOW, where an analog input pin at any given moment could be any
value in a range.
The range depends on the resolution of ADC. For example an 8-bit ADC can
produce digital values from 0 to 255, while a 10-bit ADC can yield a wider
range of values, from 0 to 1023. More values manes higher resolution and
thus a more faithful digital representation of any given analog signal.

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)

● Temperature Sensitive Appliances


48
BVRIT HYDERABAD College of Engineering for Women
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to // Compute heat index
// Must send in temp in Fahrenheit!
void setup() { float hi = dht.computeHeatIndex(f, h);
Serial.begin(9600);
Serial.println("DHTxx test!"); Serial.print("Humidity: ");
dht.begin(); Serial.print(h);
} Serial.print(" %\t");
Serial.print("Temperature: ");
void loop() { Serial.print(t);
// Wait a few seconds between measurements. Serial.print(" *C ");
delay(2000); Serial.print(f);
Serial.print(" *F\t");
// Reading temperature or humidity Serial.print("Heat index: ");
//takes about 250 milliseconds! Serial.print(hi);
// Sensor readings may also be up to Serial.println(" *F");
//2 seconds 'old' (its a very slow sensor) }
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return; 49
} BVRIT HYDERABAD College of Engineering for Women
DHT Full Device
#include "DHT.h"
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); //Serial.print("Humidity: ");
int luxPin = A5; //Serial.print(h);
int relay_pin = 13; //Serial.print(" %\t");
int cloud_in;
float tempC; //Serial.print("Temperature: ");
int intensity; Serial.print(t);
const int tempPin = A1; Serial.print("-");
const int groundPin = 14;
Serial.print(h);
const int powerPin = 16;
void setup() { Serial.print("-");
Serial.begin(9600); //Serial.print(" *C ");
pinMode(relay_pin, OUTPUT); //Serial.print(f);
dht.begin();
} //Serial.print(" *F\t");
void loop() { //Serial.print("Heat index: ");
intensity = analogRead(luxPin); //Serial.print(hi);
// Reading temperature or humidity takes about 250 milliseconds! //Serial.println(" *F\t");
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity(); //Serial.println("Intensity: ");
// Read temperature as Celsius Serial.println(intensity/200);
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true); if(Serial.available() > 0) {
cloud_in = Serial.read();
// Check if any reads failed and exit early (to try again). if(cloud_in == '0') {
if (isnan(h) || isnan(t) || isnan(f)) { digitalWrite(relay_pin, LOW);
Serial.println("Failed to read from DHT sensor!");
return; }
} if(cloud_in == '1') {
digitalWrite(relay_pin, HIGH);
}
}

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

Code is available in Arduino IDE’s


Examples 54
BVRIT HYDERABAD College of Engineering for Women
HC - SR04 Ultrasonic Range Sensor

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;
}

long microsecondsToCentimeters(long microseconds)


{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 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 }

// pinMode(3, OUTPUT); // yellow led 61


BVRIT HYDERABAD College of Engineering for Women
Controlling DC Motor from Arduino using
LM293D ● This module is a medium powered motor driver perfect for driving
DC motors and Stepper motors.
● It uses the popular Motor Driver Board H-bridge motor driver IC.
● It can drive 4 DC motors in one direction, or drive 2 DC motors in
both the directions with speed control.
● The driver greatly simplifies and increases the ease with which you
may control motors, relays, etc from microcontrollers.
● It can drive motors up to 12 V with a total DC current of up to
600mA.

Specifications:

● Operating Voltage: 7 V to 12V DC.


● 4 channel output (can drive 2 DC motors
bidirectionally).
● 600mA output current capability per channel.
● PTR connectors for easy connections.

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".

● Integrated TCP/IP Protocol Stack


● Integrated TR switch, balun, LNA, power amplifier
and matching network
● Integrated PLL, regulators &power management
units 77
BVRIT HYDERABAD College of Engineering for Women
ESP8266 Wifi Serial
● Module
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.4s guard interval
● Wake up and transmit packets in < 2ms
● Standby power consumption of < 1.0mW (DTIM 3) 78
BVRIT HYDERABAD College of Engineering for Women
On-device processing
After data is collected from a sensor, the device can provide data processing
functionality before sending the data to the cloud to enable more information to be
transmitted in a smaller data footprint. Details are here
Processing includes things like:

● Converting data to another format


● Packaging data in a way that's secure and combines the

data into a practical batch


● Validating data to ensure it meets a set of rules
● Sorting data to create a preferred sequence
● Enhancing data to decorate the core value with additional

related information
● Summarizing data to reduce the volume and eliminate

unneeded or unwanted detail


● Combining data into aggregate values

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);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Try Connecting External LED


87
BVRIT HYDERABAD College of Engineering for Women
NodeMCU + ThingSpeak
/* * This sketch sends data via HTTP GET requests to data.sparkfun.com service. * *
Serial.println("");
You need to get streamId and privateKey at data.sparkfun.com and paste them *
Serial.println("WiFi connected");
below. Or just customize this script to talk to other HTTP servers.* */
Serial.println("IP address: ");
#include <ESP8266WiFi.h>
Serial.println(WiFi.localIP());
const char* ssid = "das";
}
const char* password = "TCSTCSTCS";
const char* host = "api.thingspeak.com";
int value = 20;
//const char* streamId = "....................";
void loop() {
const char* privateKey = "FERH0WIO017KTZ3F";
delay(5000);
++value;
void setup() {
Serial.print("connecting to ");
Serial.begin(115200);
Serial.println(host);
delay(10);
// Use WiFiClient class to create TCP connections
WiFiClient client;
// We start by connecting to a WiFi network
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println();
Serial.println("connection failed");
Serial.println();
return;
Serial.print("Connecting to ");
}
Serial.println(ssid);
// We now create a URI for the request
String url = "/update?key=";
WiFi.begin(ssid, password);
url += privateKey;
url += "&field1=";
while (WiFi.status() != WL_CONNECTED) {
url += value;
delay(500);
Serial.print("Requesting URL: ");
Serial.print(".");
Serial.println(url);
}

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

Hard press RESET switch to reprogram the module 92


BVRIT HYDERABAD College of Engineering for Women
Same code as NodeMCU

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

● Connect GPIO2 pin to 3.3V and disconnect

● Connect RESET pin to GND ⇒ 3.3V ⇒ GND and disconnect

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

Click here for STEPS 106


BVRIT HYDERABAD College of Engineering for Women
NodeMCU Code on ESP8266
Code same as NodeMCU except below change:
● int builtin_led = 2; ⇒ use LED_BUILTIN option available in
ESP8266WiFi.h

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>

<form action="/TempSense" method="GET">


<input type="Submit" value="Refresh" name="btn">
</form>

</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>");

String temp = req.getParameter("temperature"); for (Entity result : pq.asIterable()) {


temp = result.getProperty("temperature").toString();
DatastoreService datastore = resp.getWriter().println("<tr><H1>");
DatastoreServiceFactory.getDatastoreService(); resp.getWriter().println("<td>" + temp + "</td></td>");
resp.getWriter().println("</H1></tr>");
if (temp == null) }
temp = "999"; resp.getWriter().println("</table></center>");

Key dbKey = KeyFactory.createKey("Sensor_DB", temp); }


}

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]

#include<stdlib.h> void loop() {


int led=13; if(Serial.available()) {
delay(500);
void setup() { if(Serial.find("+IPD,")) {
Serial.begin(115200); delay(500);
pinMode(led, OUTPUT);
Serial.println("AT+CIPMUX=1"); /* this is required */ Serial.find("pin=");
delay(500); /* delay is required */ int status = Serial.read()-48;
Serial.println("AT+CIPSERVER=1,1336"); if(status == 1) {
/* incase of connection refused, press RESET button */
} digitalWrite(led, HIGH);
Serial.println("LED is ON");
} else {
digitalWrite(led, LOW);
Serial.println("LED is OFF");
}
}
}
}

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

Arduino + IBM BlueMix


, PHP & MySQL
Configuration, Setup, Devel
opment & Deployment

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

Quick Starter Guide


Buy from Amazon
124
BVRIT HYDERABAD College of Engineering for Women
http://forum.boltiot.com
ArduinoDroid
Android IDE for Arduino
https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinocommander

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

Mobile Data Analytics Using IBM IoT Real-Time Insights


.when the mobile device begin sending events, the rules will analyze the data in real time and take action when a
threshold is broken

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

Hardware : Smart phone connected to the Internet

Click here for recipe

IBM IoT Real-Time Insights – Analytics designed for the Internet of Things

BVRIT HYDERABAD College of Engineering for Women 129


How to Register Devices in IBM Watson IoT Platform

Click here for recipe

BVRIT HYDERABAD College of Engineering for Women 130


Battery Less Sensors
EnOcean’s energy harvesting wireless sensor technology collects energy out of air. The energy existing in our environment,
for example kinetic motion, pressure, light, differences in temperature, is converted into energy for wireless
communication.

Energy from Light, Energy from Motion, Energy from Temperature - Buy Here
https://www.enocean.com/en/products/enocean-link

Integrate EnOcean devices with Watson IoT platform


BVRIT
Product HYDERABAD
Details Are Here College of Engineering for Women 131
LiFi (Wireless data from every light) is a wireless optical networking technology that uses Light-Emitting Diodes
(LEDs) for data transmission. LiFi is designed to use LED light bulbs similar to those currently in use in many
energy-conscious homes and offices.
Researchers at the University of Oxford have reached a new milestone in networking by using light fidelity (Li-Fi) to
achieve bi-directional speeds of 224 gigabits per second (Gbps)

Source

BVRIT HYDERABAD College of EngineeringSource


for Women 132
Source

BVRIT HYDERABAD College of Engineering for Women 133


Amazon.in

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.

1. Download SD Formatter 4.0 and install on your computer.


2. Insert it in SD card reader in the computer. If you need, use a MicroSD adapter (photo).
3. Run the SD Card Formatter.

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.

1. Insert the formatted SD card in Pi.


2. Plug in your USB keyboard, USB mouse, and HDMI monitor cables.
3. Plug in your Wi-Fi adapter.
4. Plug a USB power, and turn your Pi on.

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.

When you see a prompt, start the GUI.

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:

sudo apt-get update

Next, upgrade all your installed packages to the latest versions:

sudo apt-get upgrade

When you do not have an access to work directly on your Pi, you may need to access to your Pi from another computer.

Getting Pi's IP Address

First, open LXTerminal:

Obtain an IP address of your Pi:

$ 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

# Set the pin designation type.


# In this case, we use BCM- the GPIO number- rather than the pin number itself.
GPIO.setmode (GPIO.BCM)

# So that you don't need to manage non-descriptive numbers,


# set "LIGHT" to 4 so that our code can easily reference the correct pin.
LIGHT = 4

# Because GPIO pins can act as either digital inputs or outputs,


# we need to designate which way we want to use a given pin.
# This allows us to use functions in the GPIO library in order to properly send and receive signals.
GPIO.setup(LIGHT,GPIO.OUT)

# 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

“Hello World” with PubNub Python APIs -


Detailed steps are here
o World with PubNub Python APIs

147
BVRIT HYDERABAD College of Engineering for Women
IoT-fying Your LED
Remote-controlling LED from Web Interface
100.xd09spz04.appspot.com

GitHub Source Code


https://www.pubnub.com/console

148
BVRIT HYDERABAD College of Engineering for Women
Source Code - remote-led.py

import RPi.GPIO as GPIO


import time
OUTPUT
import sys >>> {u'led': 2}
from pubnub import Pubnub
GPIO.setmode (GPIO.BCM) off-led
LED_PIN = 23
GPIO.setup(LED_PIN,GPIO.OUT)
{u'led': 1}
STATUS = 'ON' on-led
{u'led': 2}
pubnub = Pubnub(publish_key='pub-c-ef38b8f7-26ee-4ea7-9ed0-f2cc6b384f95', subscribe_key='sub-c-79cd1830-2ef0-11e6-9327-02ee2ddab7fe')
channel = 'weblednew'
GPIO.output(LED_PIN, True)
def _callback(m, channel):
off-led
print(m) {u'led': 1}
if m["led"] == 1:
GPIO.output(LED_PIN, True) on-led
print('on-led')
STATUS = 'ON'
{u'led': 1}
else: on-led
GPIO.output(LED_PIN, False)
print('off-led') {u'led': 2}
STATUS = 'OFF'
off-led
def _error(m): {u'led': 1}
print(m)
on-led
pubnub.subscribe(channels=channel, callback=_callback, error=_error)
#pubnub.publish(channel='weblednew', message=STATUS, error=_error) 149
BVRIT HYDERABAD College of Engineering for Women
DHT Sensor with the Raspberry Pi
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11

# Example using a Raspberry Pi with DHT sensor


# connected to GPIO23.
pin = 23

# Try to grab a sensor reading. Use the read_retry


method which will retry up
# to 15 times to get a sensor reading (waiting 2
seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor,
pin)
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}
%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')

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.

● Single-core CPU - 1GHz ARM11 core (40% faster than


Raspberry Pi 1)
● Mini HDMI and USB On-The-Go ports
● Composite video and reset headers
● A Broadcom BCM2835 application processor
● 512MB of LPDDR2 SDRAM
● A micro-SD card slot
● A mini-HDMI socket for 1080p60 video output
● Micro-USB sockets for data and power
● An unpopulated 40-pin GPIO header
Identical pinout to Model A+/B+/2B
● An unpopulated composite video header
● Our smallest ever form factor, at 65mm x 30mm x 5mm

156
BVRIT HYDERABAD College of Engineering for Women
Connecting Internet on Raspberry Pi
ZERO

1. Click here for Details 2. Connect an ESP8266 to your RaspberryPi

3. Share Internet to the Raspberry Pi ZERO 157


BVRIT HYDERABAD College of Engineering for Women
Vehicle telematics analytics using IoT Real-Time Insights

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.

BVRIT HYDERABAD College of Engineering for Women


A sample Watson IoT Context Mapping and Driver Behavior application that sends simulated car probe data and issues analysis request 158
Vehicle telematics analytics using IoT Real-Time 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

BVRIT HYDERABAD College of Engineering for Women 160


IBM Watson Developer Cloud
Bring cognitive technology to your app

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/

BVRIT HYDERABAD College of Engineering for Women


https://github.com/watson-developer-cloud 161
IoT Sensor data and Big Data ?
Data collected by the device is called telemetry. This is the eyes-and-ears data that IoT devices provide to applications.
Telemetry is read-only data about the environment, usually collected through sensors.

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

IoT and Cloud based projects


IoT with Agriculture
Smart Workplace

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

Click here for the steps


BVRIT HYDERABAD College of Engineering for Women 164
Raspberry Pi 3 Model B (RASPBERRYPI-MODB-1GB) with in-built WiFI
and Bluetooth

Raspberry Pi Camera

Working with PiCamera

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

BVRIT HYDERABAD College of Engineering for Women

You might also like