You are on page 1of 36

Internet of Things Lab (IOT)

Laboratory Practical File

Submitted To-: Submitted By-:


Dr. Purnendu Pandey Nimish Latiyan (Lms-:25)
Jayant Kapila (Lms-:17)
Tanya Agarwal (Lms-:1)

P a g e 1 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
INDEX
EXP. Name of Experiment Page
No. No.
1 A. To study about Arduino UNO and their functions. 3-11
B. Driving / Blink the simple LED and RGB LED using Arduino Board.
C. To blink an LED as PWM or brightness control of the LED.
D. To make an RGB LED display as rainbow colours/ Spectrum colour.
2 A. Introduction about Arduino cheat sheet. 12-13
B. To study about Custom Function.

3 A. To study about operator, continuous, control structure and print the Hello World on 14-16
your monitor.
B. Introduction of LCD 20X4 and 16x2. And send the Hello world on the LCD.

4 A. To draw a program. 17-18


 To blink the light the LED, use the push buttons switch.
 To blink the light the LED, use the Photo Resistor.

5 A. To turn on /off LED using the Touch Sensor. 19-20


6 A. To measure the moisture of soil using soil & moisture sensor. 21-23

7 A. To turn on/off the LED using DHT 11 Sensor. 24


B. Measure the temp and humidity using DHT-11.

8 A. To study and demonstrate the pairing of arduino board with Blue tooth module 25-26
HC-05.

9 Measure the temperature and humidity values using DHT11 sensor with the help of 27-36
Node MCU module and then send these values to Thing Speak channel.

P a g e 2 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-1
Objective – Part-A) To study about Arduino Uno and their functions.
Apparatus Required- Arduino Uno, LED, Arduino cable etc.

Arduino Overview –

The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz
ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. It
contains everything needed to support the microcontroller; simply connect it to a computer with a
USB cable or power it with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver
chip.
Revision 3 of the board has the following new features:
1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins
placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided
from the board. In future, shields will be compatible both with the board that use the AVR, which
operate with 5V and with the Arduino Due that operate with 3.3V. The second one is a not
connected pin,that is reserved for future purposes.
Stronger RESET circuit.
Atmega 16U2 replace the 8U2.
"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Uno
and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is the latest

P a g e 3 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
in a series of USB Arduino boards, and the reference model for the Arduino platform; for a
comparison with previous versions, see the index of Arduino boards.

Summary Microcontroller ATmega328


Operating Voltage 5V
Input Voltage 7-12V
Input Voltage 6-20V
Digital I/O Pins 14 (of which 6providePWMoutput)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz
Power-The Arduino Uno can be powered via the USB connection or with an external power
supply. The power source is selected automatically. External (non-USB) power can come either
from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging
2.1mm centre-positive plug into the board's power jack. The recommended range is 7 - 12 volts.

The power pins are as follows:

VIN. The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts from the USB connection or other regulated power source). You can supply
voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.

5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied
with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of
the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can
damage your board. We don't advise it.

3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.

GND. Ground pins.

Memory-The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library).

Input and Output-Each of the 14 digital pins on the Uno can be used as an input or output, using
pin Mode(), digital Write(), and digital Read() functions. They operate at 5 volts. Each pin can
provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by
default) of 20-50 k ohms. In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins
are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.

P a g e 4 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value. See the attach Interrupt () function for details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analog write () function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using
the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the
LED is on, when the pin is LOW, it's off.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution
(i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible
to change the upper end of their range using the AREF pin and the analog Reference () function.
Additionally, some pins have specialized functionality:

TWI: A4 / SDA pin and A5 /SCL pin. Support TWI communication using the Wire library.

AREF. Reference voltage for the analog inputs. Used with analog Reference ().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to
shields which block the one on the board.

Communication -The Arduino Uno has a number of facilities for communicating with a
computer, another Arduino, or other microcontrollers. The ATmega328 provides UART TTL
(5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX). An
ATmega16U2 on the board channels this serial communication over USB and appears as a virtual
com port to software on the computer. The '16U2 firmware uses the standard USB COM drivers,
and no external driver is needed. However, on Windows, a .inf file is required. The Arduino
software includes a serial monitor which allows simple textual data to be sent to and from the
Arduino board. The RX and TX LEDs on the board will flash when data is being transmitted via
the USB-to-serial chip and USB connection to the computer (but not for serial communication on
pins 0 and 1). A Software Serial library allows for serial communication on any of the Uno's
digital pins. The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino
software includes a Wire library to simplify use of the I2C bus; see the documentation for details.
For SPI communication, use the SPI library.

Programming -The Arduino Uno can be programmed with the Arduino software (download).
Select "Arduino Uno from the Tools > Board menu (according to the microcontroller on your
board). For details, see the reference and tutorials.

The ATmega328 on the Arduino Uno comes pre burned with a bootloader that allows you to
upload new code to it without the use of an external hardware programmer. It communicates
using the original STK500 protocol (reference, C header files). You can also bypass the
bootloader and program the microcontroller through the ICSP (In-Circuit Serial Programming)
header.
P a g e 5 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Part-B) Driving / Blink the simple LED and RGB LED using Arduino Board.
Apparatus Required-- Arduino Uno, LED, Arduino cable, resistance 100 ohm etc.

Setup ( )-

•Inside setup function you want to include instructions that do exactly that ie setup the
Arduino with the setting that your circuit requires before the execution of the sketch starts.
• Setup () method is used to make Arduino know what it used to know before it start
executing the code in the Loop () method.
• The only thing we are doing here is to instruct the Arduino to configure LED port which is
in PIN No. 13 to be an output.
PWM-(Pulse Width Modulation)-

• The Fading example demonstrates the use of analog output (PWM) to fade an LED.
• 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. This
on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus the time that the signal spends
off. The duration of "on time" is called the pulse width. To get varying analog values, you
change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an
LED for example, the result is as if the signal is a steady voltage between 0 and 5v
controlling the brightness of the LED.

a) Blink a LED-
Program-

P a g e 6 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Circuit Diagram-

b) Programming For – Control the brightness control of a simple LED.

P a g e 7 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
c) Programming for RGB LED-
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
}
Circuit Diagram-

d) Programming for Rainbow Color/ Spectrum Color using RGB LED.

const int RED_PIN = 13;


const int GREEN_PIN = 12;
const int BLUE_PIN = 11;

// This variable controls how fast we loop through the colors.


// (Try changing this to make the fading faster or slower.)

P a g e 8 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
int DISPLAY_TIME = 20; // In milliseconds
void setup()
{
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop()
{
showSpectrum();
}
void mainColors()
{
// Off (all LEDs off):
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
delay(1000);
// Red (turn just the red LED on):
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
delay(1000);
// Green (turn just the green LED on):
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
delay(1000);
// Blue (turn just the blue LED on):
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(1000);
// Yellow (turn red and green on):
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
delay(1000);
// Cyan (turn green and blue on):
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
delay(1000);
// Purple (turn red and blue on):
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(1000);

// White (turn all the LEDs on):


digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
P a g e 9 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
digitalWrite(BLUE_PIN, HIGH);
delay(1000);
}
// For the for() loop below, these are the three statements:

// 1. x = 0; Before starting, make x = 0.

// 2. x < 768; While x is less than 768, run the


// following code.

// 3. x++ Putting "++" after a variable means


// "add one to it". (You can also use "x = x + 1")
void showSpectrum()
{
int x; // define an integer variable called "x"

for (x = 0; x < 768; x++)

// Each time we loop (with a new value of x), do the following:

{
showRGB(x); // Call RGBspectrum() with our new x
delay(DISPLAY_TIME); // Delay for 10 ms (1/100th of a second)
}
}
// showRGB()

// This function translates a number between 0 and 767 into a


// specific color on the RGB LED. If you have this number count
// through the whole range (0 to 767), the LED will smoothly
// change color through the entire spectrum.

// The "base" numbers are:


// 0 = pure red
// 255 = pure green
// 511 = pure blue
// 767 = pure red (again)

// Numbers between the above colors will create blends. For


// example, 640 is midway between 512 (pure blue) and 767
// (pure red). It will give you a 50/50 mix of blue and red,
// resulting in purple.

// If you count up from 0 to 767 and pass that number to this


// function, the LED will smoothly fade between all the colors.
// (Because it starts and ends on pure red, you can start over
// at 0 without any break in the spectrum).
void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;
if (color <= 255) // zone 1
P a g e 10 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
{
redIntensity = 255 - color; // red goes from on to off
greenIntensity = color; // green goes from off to on
blueIntensity = 0; // blue is always off
}
else if (color <= 511) // zone 2
{
redIntensity = 0; // red is always off
greenIntensity = 255 - (color - 256); // green on to off
blueIntensity = (color - 256); // blue off to on
}
else // color >= 512 // zone 3
{
redIntensity = (color - 512); // red off to on
greenIntensity = 0; // green is always off
blueIntensity = 255 - (color - 512); // blue on to off
}

// Now that the brightness values have been set, command the LED
// to those values

analogWrite(RED_PIN, redIntensity);
analogWrite(BLUE_PIN, blueIntensity);
analogWrite(GREEN_PIN, greenIntensity);
}

Circuit Diagram-

P a g e 11 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-2

Aim- a) Introduction about Cheat sheet of Arduino Bard.


b) Study about Custom Functions.
Apparatus Required- Arduino Uno, LED, Buzzer, Arduino cable etc.
a) Programming-

Output on serial Monitor.

P a g e 12 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
b) For work practice-

c) For work practice-

P a g e 13 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-3
Aim- a) To study about operator, continuous, control structure and print the Hello
World on your monitor.
B) Introduction of LCD 20X4 and 16x2. And send the Hello world on the LCD.
Apparatus Required- Arduino Uno, LCD, arduino cable, Bread Board, Connecting
wires etc.
Programming-

Output on Serial Moniter-

P a g e 14 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Part-2

Pin Configuration of LCD 16X2.

P a g e 15 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Programming-

Circuit Diagram--

P a g e 16 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-4

Aim- To draw a program.

 To blink the light the LED, use the push buttons switch.
 To blink the light the LED, use the Photo Resistor.

Apparatus Required- Arduino Uno, LED, Arduino cable, button or Switch,


10K ohm Resistor etc.

The example given below uses push button to light the LED, please use the
push buttons for any other scenario

P a g e 17 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
 A Photo resistor is simply a resistor in which resistance changes in
accordance to its exposure to light.

The program given below reads and prints the analog value from the
environment. The value increases or decreases as and when the light intensity
decrease or increases.

P a g e 18 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-5

Aim- To turn on /off LED using the Touch Sensor.

Apparatus Required- Arduino Uno, LED, Arduino cable, Touch Sensor, etc.

Programming -

Use Touch Sensor or any other digital Sensor to On-off LED.

P a g e 19 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
P a g e 20 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-6

Aim- To measure the moisture of soil using soil & moisture sensor.

Apparatus Required- Arduino Uno, Bread Board, LED, Arduino cable, soil
moisture sensor, connective wire, etc.

Circuit Diagram -

Sensor’s Image-

P a g e 21 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
A typical Soil Moisture Sensor consist of two components. A two legged Lead, that goes into the soil or
anywhere else where water content has to be measured. This has two header pins which connect to an
Amplifier/ A-D circuit which is in turn connected to the Arduino.

The Amplifier has a Vin, Gnd, Analog and Digital Data Pins. This means that you can get the values in both
Analog and Digital forms.

Most soil moisture sensors are designed to estimate soil volumetric water content based on the dielectric
constant (soil bulk permittivity) of the soil. The dielectric constant can be thought of as the soil's ability to
transmit electricity. The dielectric constant of soil increases as the water content of the soil increases.
This response is due to the fact that the dielectric constant of water is much larger than the other soil
components, including air. Thus, measurement of the dielectric constant gives a predictable estimation of
water content.

P a g e 22 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Connections-
Connect the two pins from the Sensor to the two pins on the Amplifier circuit via hook up wires.
Connect the Vcc from the Amplifier to the 3.3V pin on the Arduino and the Gnd pin to the Gnd
pin on the Arduino. Now connect the Analog Data Pin to the A0 pin on the Arduino (Since I'm
interested in Analog Data).

Activity-

Divide the values of Soil Moisture sensors into 2 range.


Range-1 when the moisture in soil is less.
Range-2 when the moisture in soil is high.
When Value falls in Range-1, the LED should glow, showing there is less moisture in field.
When Value falls in Range-2, the LED should stop glowing, showing there is less moisture in
field.

P a g e 23 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-7

Aim- 1. To turn on/off the LED using DHT 11 Sensor.


2. Measure the temp and humidity using DHT-11.
Apparatus Required- Arduino Uno, Bread Board, LED, , Resistor 10k ohm, Arduino cable,
Temperature and humidity sensor /DHT sensor, connective wire, etc.
Sensor pin diagram-

Connections- Put resistor between pin 1 from left of sensor and pin 2 from left (i.e
between 5v and pin 2 of sensor i.e data pin)), Pin 3 from left will not be used and Pin 4 is
Ground.

Note-
Download the DHTLib file and paste it in “C:\IntelArduino\libraries”
http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

P a g e 24 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-8

Aim- To study and demonstrate the pairing of arduino board with Blue tooth
module HC-05.
Apperatus Required- Arduino Board, Blue tooth device, Bread board, installed
arduino blurtooth controller app.in your cellphone, connecting wires etc.

Coding-

Pairing of Bluetooth module with computer.

The equivalent of connecting a cable from a USB device to the computer for a
Bluetooth device is to pair it. Pairing involves getting the computer to find an
active nearby Bluetooth device and to connect to it. In most cases, a key needs to be
used to authenticate the computer to the device and establish the connection. Once
you have connected the circuit, plug the Arduino to the computer via USB in order
to provide power to the Bluetooth module. You should see the the surface red LED
on the module blinking fast. In this image, I captured the LED while it was off. On
the computer side, bring up the Bluetooth devices dialog box, exactly the way you
do when you pair a phone, headset, or other Bluetooth devices. On the Mac, that
looks like this:
P a g e 25 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
The LED on the breadboard should now light up. To turn it of, type anything other
that the “H” character. In this demo, you learn about sending data through a
Bluetooth serial connection from the computer to the Arduino. What about the
Opposite, that is, to receive data via Bluetooth from the Arduino to the computer?

P a g e 26 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Experiment No-9
Aim- Measure the temperature and humidity values using DHT11 sensor with
the help of Node MCU module and then send these values to Thing Speak
channel.
Apparatus Required- Node MCU esp8266, DHT-11 Sensor, Bread board, latest version of
Arduino IDE. Install the ESP8266 package in your PC, Connecting wire etc.

• Open Arduino IDE go to File---- Preference

Next, use the Board manager to install the ESP8266 package.

P a g e 27 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
When you've restarted, select Adafruit HUZZAH ESP8266 from the Tools->Board dropdown

80 MHz as the CPU frequency (you can try 160 MHz overclock later)
115200 baud upload speed is a good place to start - later on you can try higher speeds but 115200
is a good safe place to start. You can move down to lower speeds if you are having upload issues,
or speed it up if your setup is stable, for faster uploads!

115200 baud upload speed is a good place to start - later on you can try higher speeds but 115200
is a good safe place to start. You can move down to lower speeds if you are having upload issues,
or speed it up if your setup is stable, for faster uploads!

P a g e 28 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Go to Tools section of IDE

Posting DHT11 Values to ThingSpeak Using Nodemcu


The primary element of ThingSpeak activity is the channel, which contains data fields, location
fields, and a status field. After you create a ThingSpeak channel, you can write data to the
channel, process and view the data with MATLAB code, and react to the data with tweets and
other alerts.
The typical ThingSpeak workflow lets you:
1) Create a Channel and
2) collect data Analyze and
3) Visualize the data Act on the data using any of several Apps

P a g e 29 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Activity- Measure the temperature and humidity values using DHT11 sensor with the help of
Nodemcu module and then send these values to ThingSpeak channel.
Follow the following steps to configure:
Sign In into ThingSpeak account, by using ThingSpeak account or using MathWorks account.
Click on My Channels.
On the channel page, click on New Channel.

As we are using DHT11 sensor to measure the temperature and humidity values, we will name
our channel as Measurements (You can choose any other desired name). Provide some
description though it’s not mandatory.
Update Field-1 with Temperature and Field-2 with Humidity (Number of fields can be updated as
per your project requirement).
You can select some other settings as well and after that you can save your channel.
After saving the channel you will see 5 tabs, Private View, Public View, Channel Setting, API
Keys, Data Import/Export
You can modify the Title, X-Axis, Y-Axis, scales of Field-1 and Field-2 for Private View and
Public View of the Channel.
Now time to update the Nodemcu code written in Arduino IDE, copy the Channel ID and Write
API Key from API Keys tab and update it in Arduino IDE program.

P a g e 30 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
P a g e 31 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Download the ThingSpeak library for Arduino:
http://embeddedlaboratory.blogspot.in/2016/10/posting-dht11-values-to-thingspeak.html
For more Information please check:
http://embeddedlaboratory.blogspot.in/2016/10/posting-dht11-values-to-thingspeak.html
https://roboindia.com/tutorials/nodeMCU-dht11-thingspeak-data-upload
Build your project and flash the Nodemcu with the updated code, and after that you will see the
temperature and humidity graphs on the ThingSpeak channel, as shown in the below images.

P a g e 32 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
Coding-
#include <DHT.h>

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#include <ThingSpeak.h>

#define DHTPIN 0

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "honor";

const char* password = "supersecret";

WiFiClient client;

unsigned long myChannelNumber = 377256;

const char * myWriteAPIKey = "JAZM2T8LC40UR299";

uint8_t temperature, humidity;

void setup()

Serial.begin(115200);

dht.begin();

delay(10);

// Connect to WiFi network

Serial.println();

Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)

delay(500);

Serial.print(".");

P a g e 33 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
}

Serial.println("");

Serial.println("WiFi connected");

// Print the IP address

Serial.println(WiFi.localIP());

ThingSpeak.begin(client);

void loop()

static boolean data_state = false;

temperature = dht.readTemperature();

humidity = dht.readHumidity();

Serial.print("Temperature Value is :");

Serial.print(temperature);

Serial.println("C");

Serial.print("Humidity Value is :");

Serial.print(humidity);

Serial.println("%");

// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you


to store up to 8 different

// pieces of information in a channel. Here, we write to field 1.

if( data_state )

ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);

data_state = false;

else

ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey);

data_state = true;

P a g e 34 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
}

delay(30000); // ThingSpeak will only accept updates every 15 seconds.

Steps-

1)first register the channel ID and then log in ID from think speak site.

2.than put your wifi id and mention password and API Key in the program at
given place.as per given below detail.

P a g e 35 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.
P a g e 36 | 36

BML Munjal University (Gurgaon), CSE Dept., IOT Lab. 6th Sem.

You might also like