You are on page 1of 31

ANNA UNIVERSITY - CHENNAI

JAYA ENGINEERING COLLEGE


Thiruninravur -602 024
Approved by AICTE, Accredited by NAAC, Affiliated to Anna University
(An ISO 9001:2000 Certified Institution)
DEPARTMENT OF COMPUTER APPLICATIONS
PRACTICAL RECORD

MC4312 INTERNET OF THINGS LABORATORY

REG.NO :

NAME :

SEMESTER / YEAR:
ANNA UNIVERSITY-CHENNAI
JAYA ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER APPLICATIONS

BONAFIDE CERTIFICATE

REG.NO:_________________________ NAME: ______________________________

SEMESTER: ______________________ YEAR: ______________________________

This is certified to be the bonafide record of work done by the student in the
MC4312 INTERNET OF THINGS LABORATORY of Jaya Engineering
College during the academic year 2023-2024

HEAD OF THE DEPARTMENT STAFF-IN-CHARGE

Submitted for the University Examination held on _____________________

INTERNAL EXAMINER EXTERNAL EXAMINER


JAYA ENGINEERING COLLEGE
THIRUNINRAVUR

MASTER OF COMPUTER APPLICATIONS

Vision To nurture Versatile and Skilled Techies with Moral Values

To Infuse ethical, social and leadership qualities through innovative activities.


Mission To bridge the gap between industry and academia through alumni support.
To mould students with formal theoretical and practical knowledge.

PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)


Graduates will be able to:

I. Apply their computing skills to analyze, design and develop innovative software products to meet
the industry needs and excel as software professionals.
II. Pursue lifelong learning and do research in the computing field based on solid technical
foundations.
III. Communicate and function effectively in teams in multidisciplinary fields within the global,
societal and environmental context.
IV. Exhibit professional integrity, ethics and an understanding of responsibility to contribute
technical solutions for the sustainable development of society.

PROGRAM OUTCOMES (POs)


1.An ability to independently carry out research/investigation and development work to solve
practical problems
2. An ability to write and present a substantial technical report/document
3. Students should be able to demonstrate a degree of mastery over the area as per the specialization
of the program. The mastery should be at a level higher than the requirements in the appropriate
bachelor program
4. Able to select suitable data models, appropriate architecture, and platform to implement a system
with good performance.
5. Able to design and integrate various system based components to provide user interactive
solutions for various challenges.
6. Able to develop applications for real time environments using existing and upcoming
technologies.

PROGRAM SPECIFIC OBJECTIVES (PSO)


PSO 1: Able to select suitable data model, appropriate architecture, platform to implement a
system with good performance.
PSO 2: Able to design and integrate various system based components to provide user
interactive solutions for various challenges.
Course Code MC4312
Course Name INTERNET OF THINGS LABORATORY
Course Objectives
o To design applications to interact with sensors
o To design and develop IoT application Arduino/Raspberry pi for real world scenario.
o To enable communication between IoT and cloud platforms
o To develop applications using Django Framework

Course Outcomes
CO1: To understand the various IoT protocols
CO2: Test and experiment different sensors for application development
CO3: To develop applications using Arduino/Raspberry Pi/ Equivalent boards.
CO4: To develop applications that would read the sensor data and post it in Cloud
CO5: Develop IOT applications with different platforms and frameworks.

Name : Dept. & Year:

Register No. Subject:


INDEX

PO’S &
S. CO’S
DATE NAME OF THE EXPERIMENT P.No PSO’S MARK SIGN
No MAPPED
MAPPED
To study various IoT protocols –
1 05-10-23 6LowPAN, IPv4/IPv6, Wifi, 1 CO1 PO2
Bluetooth, MQTT.
IoT Application Development
2A 10-10-23 Using sensors and actuators - 3 CO2 PO3
temperature sensor
IoT Application Development
2B 12-10-23 Using sensors and actuators - light 5 CO2 PO3
sensor
IoT Application Development
2C 17-10-23 Using sensors and actuators - 7 CO2 PO3
infrared sensor
To study Raspberry Pi
development board and to
3 19-10-23 9 CO3 PO3
implement LED blinking
applications.
To develop an application to send
4 26-10-23 and receive data with Arduino 11 CO3 PO1,PO3
using HTTP request
To develop an application that
measures the room temperature
5 31-10-23 14 CO4 PO1,PO3
and posts the temperature value on
the cloud platform.
To develop an application that
measures the moisture of soil and
6 02-11-23 16 CO4 PO1,PO3
post the sensed data over Google
Firebase cloud platform.
To develop an application for
measuring the distance using
7 07-11-23 ultrasonic sensor and post distance 18 CO4 PO1,PO3
value on Google Cloud IoT
platform
Develop a simple application PO1,PO4
8 09-11-23 20 CO5
based on sensors , PO6
Develop IoT applications using
PO1,PO5
9 14-11-23 Django Framework and Firebase/ 22 CO5
, PO6
Bluemix platform.
Develop a commercial IoT
10 16-11-23 24 CO5 PO1,PO6
application
Exercise no: 1 Study various IoT protocols – 6LowPAN, IPv4/IPv6, Wi-
Date: 05-10-23 Fi, Bluetooth, and MQTT

6LowPAN Protocol:
6LoWPAN is an IPv6 protocol, and It’s extended from is IPv6 over Low Power Personal Area Network.
As the name itself explains the meaning of this protocol is that this protocol works on Wireless Personal
Area Network i.e., WPAN.

WPAN is a Personal Area Network (PAN) where the interconnected devices are centered around a
person’s workspace and connected through a wireless medium. You can read more about WPAN at
WPAN. 6LoWPAN allows communication using the IPv6 protocol. IPv6 is Internet Protocol Version 6
is a network layer protocol that allows communication to take place over the network. It is faster and more
reliable and provides a large number of addresses.

IPv4 Protocol:
IPv4 is a version 4 of IP. It is a current version and the most commonly used IP address. It is a 32-bit
address written in four numbers separated by 'dot', i.e., periods. This address is unique for each device.

For example, 66.94.29.13

The above example represents the IP address in which each group of numbers separated by periods is
called an Octet. Each number in an octet is in the range from 0-255. This address can produce
4,294,967,296 possible unique addresses.

1
IPv6 Protocol:
Internet Protocol version 6 (IPV 6) is the replacement for version 4 (IPV 4). The phenomenal development
of the Internet has begun to push IP to its limits. It provides a large address space, and it contains a simple
header as compared to IPv4.

Wi-Fi Protocol:
IEEE 802.11 wireless LANs use a media access control protocol called Carrier Sense Multiple Access
with Collision Avoidance (CSMA/CA). While the name is similar to Ethernet's Carrier Sense Multiple
Access with Collision Detection (CSMA/CD), the operating concept is totally different.

WiFi systems are the half duplex shared media configurations, where all stations transmit and receive on
the same radio channel. The fundamental problem of a radio system is that a station cannot hear while it
is sending, and hence it is impossible to detect a collision. Because of this, the developers of the 802.11
specifications came up with a collision avoidance mechanism called the Distributed Control Function
(DCF).

Bluetooth Protocol:
Bluetooth network technology connects mobile devices wirelessly over a short-range to form a personal
area network (PAN). The Bluetooth architecture has its own independent model with a stack of protocols,
instead of following the standard OSI model or TCP/IP model.

The protocols in the Bluetooth standard can be loosely grouped into the physical layer, data link layer,
middleware layer, and application layer

MQTT Protocol:
MQTT stands for Message Queuing Telemetry Transport. MQTT is a machine to machine internet of
things connectivity protocol. It is an extremely lightweight and publish-subscribe messaging transport
protocol. This protocol is useful for the connection with the remote location where the bandwidth is a
premium. These characteristics make it useful in various situations, including constant environment such
as for communication machine to machine and internet of things contexts. It is publish and subscribe
system where we can publish and receive the messages as a client. It makes it easy for communication
between multiple devices. It is a simple messaging protocol designed for the constrained devices and with
low bandwidth, so it's a perfect solution for the internet of things applications.

2
Exercise no: 2A
IoT Application Development Using Temperature Sensor
Date: 10-10-23

Aim:
Develop an IoT Application Temperature Sensor

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Import the DHT library from library management
Step 3: Code the program to work the sensor to find the temperature and humidity
Step 4: Connect the Arduino and sensor with the help of circuit diagram correctly
Step 5: Connect the Arduino chip to the computer
Step 6: Compile and upload the code to the chip. Sketch>>Upload.
Step 7: Run the code and record the readings from serial monitor.

Program:
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F(" Humidity: "));
Serial.print(h);
Serial.print("\n");
}

3
Circuit:

Draw the connecting points in the Arduino UNO


Output:

Result:
The above program executed successfully, Hence output verified.

4
Exercise no: 2B
IoT Application Development Using Infrared Sensor
Date: 12-10-23

Aim:
Develop an IoT Application Using Infrared sensor

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Connect the Arduino and sensor with the help of circuit diagram correctly
Step 3: Connect the Arduino chip to the computer
Step 4: Code the program to work the IR-sensor to detect any type of obstacle/object front of the sensor
Step 5: Compile and upload the code to the chip. Sketch>>Upload.
Step 6: Run the code and record the readings from serial monitor.
Step 7: If sensor detects the object the LED light blinks.

Program:
void setup()
{
pinMode(13,OUTPUT);
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(2)== LOW)
{
digitalWrite(13,HIGH);

delay(10);
}
else
{

digitalWrite(13,LOW);

delay(10);
}
}

5
Circuit:

Output:

With Object Without Object

Result:
The above program executed successfully, Hence output verified.

6
Exercise no: 2C
IoT Application Development Using Light Sensor
Date: 17-10-23

Aim:
Develop an IoT Application Using Light sensor

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Connect the Arduino and sensor with the help of circuit diagram correctly
Step 3: Connect the Arduino chip to the computer
Step 4: Code the program to work the LDR-sensor to detect Day and Night
Step 5: Compile and upload the code to the chip. Sketch>>Upload.
Step 6: Run the code and record the readings from serial monitor.
Step 7: If sensor detects the Darkness the LED light blinks. If sensor detects the Light the LED light offs
Program:
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop()
{
int ldr = analogRead(ldrPin);

if (ldr <= 30) {


digitalWrite(ledPin, HIGH);
Serial.print("Its Night Time, Turn on the LED : ");
Serial.println(ldr);
}
else {
digitalWrite(ledPin, LOW);
Serial.print("Its daytime, Turn off the LED : ");
Serial.println(ldr);

7
}
Serial.println(ldr);
}

Circuit:

Output:

Result:
The above program executed successfully, hence verified.

8
Exercise no: 3 Implement LED Blinking application
Date: 19-10-23 using Raspberry Pi Board
.Aim:

Write a program to implement LED Blinking application using Raspberry Pi board

Procedure:

Step 1: Open Arduino IDE and create new file. File>>New.


Step 2: Connect the Raspberry Pi board to the monitor
Step 3: Connect the led in output pin 8 and connect the resistance in breadboard
Step 4: Run the Raspberry Pi OS
Step 5: Import the GPIO library and Sleep function in Time Library
Step 6: Set the GPIO Board mode
Step 7: Set the initial value to low power off
Step 8: Compile and upload the code to the chip. Sketch>>Upload.
Step 7: Run the output in looping statement to Led Blink for 1 sec
Step 8: Record the readings from serial monitor.
Program:

import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library


from time import sleep # Import the sleep function from the time module

GPIO.setmode(GPIO.BOARD) # Use physical pin numbering


GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin
# Set initial value to low (off)

while True: # Run forever


GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second

9
Circuit:

Output:

LED OFF LED ON

Result:

The above program executed successfully, hence verified.

10
Exercise no: 4 Develop an application to send and receive data with
Date: 26-10-23 Arduino using HTTP request

Aim:
Write a program to develop an application to send and receive data with Arduino using HTTP request

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Import ESP8266 HTTPClient and wifi libraries from library management.
Step 3: Code the program to send and receive data using HTTP request.
Step 4: Connect the chip board to the computer.
Step 5: Verify the Wifi connection given.
Step 6: Compile and upload the code to the chip. Sketch>>Upload.
Step 7: Run the code and record the readings from serial monitor.

Program:
(HTTP Get Request)
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

const char* ssid ="username";


const char* password = "password";

unsigned long lastTime = 0;


unsigned long timerDelay = 5000;

void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds, it will take 5 seconds before publishing the first reading.");
}

11
void loop()
{

if(WiFi.status()== WL_CONNECTED) //Check WiFi connection status


{
WiFiClient client;
HTTPClient http; // or WiFiClientSecure for HTTPS
http.begin(client, "http://arduinojson.org/example.json"); // Send request
http.GET();
Serial.print(http.getString()); // Print the response
http.end();
}
else
{
Serial.print("Error code: ");
}

(HTTP Post Request)


#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char *WIFI_SSID = "name";


const char *WIFI_PASSWORD = "password";
const char *URL = "http://httpbin.org/post";

WiFiClient client;
HTTPClient httpClient;

void setup()
{
Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("Connected");
}
void loop()
{
String data = "name=john&age=20&course=MCA";
httpClient.begin(client, URL);
httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpClient.POST(data);

12
String content = httpClient.getString();
httpClient.end();
Serial.println(content);
delay(5000);
}

Output:

HTTP Get Request

HTTP Post Request

13
Exercise no: 05 IoT Application Development measure the room temp. &
Date: 31-10-23 post the temp. value on cloud

Aim:
Develop an IoT Application that measure the room temperature & post the temperature value on cloud

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Import the DHT library and ESP8266Wifi library from the library management
Step 3: Create an account on the cloud to view the result.
Step 4: Code the program with the available details for wifi connection also the cloud account details.
Step 5: Connect the DHT sensor to the computer.
Step 6: Compile and upload the code to the chip. Sketch>>Upload.
Step 7: Run the code and record the readings from serial monitor and the cloud platform.

Program:
#include <DHT.h>
#include<ESP8266WiFi.h>
String apiKey = "<API Key>";
const char *ssid = "<Wifi name>";
const char *pass = "<Password>";
const char* server = "api.thingspeak.com";

DHT dht(D4, DHT11);


WiFiClient client;

void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {


delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop() {
float t = dht.readTemperature();
14
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

if (client.connect(server, 80)) {
String postStr = apiKey;
postStr += "&field1=";
postStr += String(t);
postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");


client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.print("Temperature: ");
Serial.print(t);
Serial.print("\t");
}
client.stop();
delay(10);
}

Output:

Result:
The above program executed successfully, hence verified.

15
Exercise no: 06
Develop an IoT Application that measure soil moisture
Date: 02-11-23

Aim:
Develop an IoT Application that measure soil moisture

Procedure:
Step 1: Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Connect the sensor to the Arduino board and it to the computer.
Step 3: Define Arduino pin that connects to AOUT pin of moisture sensor
Step 4: Code the program to measure and to display the soil moisture.
Step 5: Compile and upload the code to the chip. Sketch>>Upload.
Step 6: Run the code and record the readings from the serial monitor.

Program:
#define AOUT_PIN A0 // Arduino pin that connects to AOUT pin of moisture sensor
void setup() {
Serial.begin(9600);
}

void loop() {
int value = analogRead(AOUT_PIN); // read the analog value from sensor

Serial.print("Soil Moisture(in percentage) = ");


Serial.println(value);
Serial.println("%");

delay(500);
}

Circuit:

16
Output:

Result:
The above program executed successfully, hence verified.

17
Exercise no: 07 Develop an IoT Application for measure the distance
Date: 07-11-23 using ultrasonic sensor and post in cloud

Aim:
Develop an IoT Application for measure the distance using ultrasonic sensor and post in cloud

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: The HC-SR04 sensor attach to the Breadboard
Step 3: The sensor Vcc is connected to the NodeMCU +3.3v
Step 4: The sensor GND is connected to the NodeMCU GND
Step 5: The sensor Trigger Pin is connected to the NodeMCU Digital I/O D4
Step 6: The sensor Echo Pin is connected to the NodeMCU Digital I/O D3
Step 7: Compile and upload the code to the chip. Sketch>>Upload.
Step 8: Run the code and record the readings from serial monitor.
Step 9: Check the cloud platform for result.

Program:
String apiKey = "<API Key>";
const char *ssid = "<Wifi name>";
const char *pass = "<Password>";
const char* server = "api.thingspeak.com";
const int trigPin = 2; //D4
const int echoPin = 0; //D3

long duration;
int distance;
WiFiClient client;

void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {


delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
18
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
delay(2000);
}

Circuit:

Output:

Result:

The above program executed successfully, hence verified.

19
Exercise no: 08
Develop a simple application based on sensor
Date: 09-11-23

Aim:
Develop a simple application based on sensor

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Connect the Arduino and sensor with the help of circuit diagram correctly
Step 3: Connect the Arduino chip to the computer
Step 4: Code the program to work the Sound-sensor to detect sound
Step 5: Compile and upload the code to the chip. Sketch>>Upload.
Step 6: Run the code and record the readings from serial monitor.
Step 7: If sensor detects the High sound the value increases. If sensor hear the Low sound value drops

Program:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop(){
int val;
val=analogRead(0);
Serial.print("Sound=");
Serial.println(val,DEC);
lcd.setCursor(0, 0);
lcd.print("Sound=");
lcd.print(val);
lcd.print(" ");
delay(1000);
}

20
Circuit:

Output:

Result:
The above program executed successfully, hence verified.

21
Exercise no: 09 Develop IOT application using Django Frameworks and
Date: 14-11-23 firebase platform

Aim:
Develop an LED blinking IOT application using Django Frameworks and firebase platform

Procedure:
Step 1: Set up a physical circuit consisting of a microcontroller (such as an Arduino), a LED, and other
necessary components (such as a resistor).
Step 2: Write code for the microcontroller to control the LED and send data to Firebase.
Step 3: Set up a Firebase project and create a Realtime Database to store the data from the
microcontroller.
Step 4: Set up a Django project and create an IoT application in it.
Step 5: Use the Firebase Python SDK to integrate with the Firebase Realtime Database and retrieve data
from it in your Django application.
Step 6: Use Django's views and templates to create a user interface to display the status of the LED (e.g.
on or off) and control it.
Step 7: Deploy your Django application on a web server.
Step 8: Test your LED blinking application by sending commands from your Django application to the
microcontroller and observing the LED's behavior.

Program:
Code on an ESP8266 microcontroller (such as the NodeMCU) to control a LED and send data to Firebase
import machine
import time
import urequests
import json

led = machine.Pin(2, machine.Pin.OUT) # LED connected to pin 2


firebase_url = "https://YOUR-FIREBASE-PROJECT.firebaseio.com/led_status.json"

def send_data_to_firebase(status):
data = {"status": status}
headers = {"Content-Type": "application/json"}
try:
response = urequests.patch(firebase_url, data=json.dumps(data), headers=headers)
if response.status_code == 200:
return True
else:
return False
except Exception as e:
return False
22
def toggle_led():
while True:
led.value(not led.value())
status = "on" if led.value() else "off"
result = send_data_to_firebase(status)
if result:
print("LED status sent to Firebase: ", status)
else:
print("Failed to send LED status to Firebase")
time.sleep(1)

toggle_led()

Create views and templates in Django to display the status of the LED and control it:
# views.py
from django.shortcuts import render
import requests

def index(request):
response = requests.get("https://YOUR-FIREBASE-PROJECT.firebaseio.com/led_status.json").json()
led_status = response["status"]
return render(request, "index.html", {"led_status": led_status})

def toggle_led(request):
led_status = "on" if request.GET.get("led_status") == "off" else "off"
requests.patch("https://YOUR-FIREBASE-PROJECT.firebaseio.com/led_status.json",
json={"status": led_status})
return render(request, "index.html", {"led_status": led_status})

index.html
<!-- templates/index.html -->
<h1>LED Control</h1>
<p>LED Status: {{ led_status }}</p>
<form action="{% url 'toggle_led' %}" method="get">
<input type="hidden" name="led_status" value="{{ led_status }}">
<button type="submit">Toggle LED</button>
</form>

Result:
The above program executed successfully, hence verified.

23
Exercise no: 10
Develop a commercial IOT application
Date: 16-11-23

Aim:
Develop a commercial IOT application

Procedure:
Step 1: Open Arduino IDE and create new file. File>>New.
Step 2: Create an account on cloud platform.
Step 3: Import ESP8266Wifi libraries from library management.
Step 4: Connect the LM35 sensor to the node mcu board and to the computer.
Step 5: Code the program to sense the temperature and provide the cloud account details
Step 6: Compile and upload the code to the chip. Sketch>>Upload.
Step 7: Run the code and record the readings from serial monitor.
Step 8: Check the results in the cloud platform also.

Program:
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const int LM35 = A0;

//----------- Enter you Wi-Fi Details---------//


char ssid[] = "*****"; //SSID
char pass[] = "******"; // Password
//-------------------------------------------//

WiFiClient client;

unsigned long myChannelNumber = 1974498; // Channel ID here


const int FieldNumber = 1;
const char * myWriteAPIKey = "0E04MYA62R3KSLRU"; // Your Write API Key here

void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
24
}
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
int ADC;
float temp;
ADC = analogRead(LM35); /* Read Temperature */
temp = (ADC * 3); /* Convert adc value to equivalent voltage */
temp = (temp / 10); /* LM35 gives output of 10mv/°C */
Serial.print("LM35 temperature = ");
Serial.print(temp);
delay(1000);
ThingSpeak.writeField(myChannelNumber, FieldNumber, temp, myWriteAPIKey);
delay(1000);
}

Circuit:

25
Output:

Result:
The above program executed successfully, hence verified.

26

You might also like