Iot File
Iot File
Practical – 3
1. Arduino Uno
2. Red Led
3. Jumper Wire
4. Breadboard
➢ Code:
void setup ()
{
pinMode (LED_BUILTIN, OUTPUT);
}
void loop ()
{
digitalWrite (LED_BUILTIN,
HIGH);delay (3000); // Wait for
3000 millisecond(s) digitalWrite
(LED_BUILTIN, LOW);
delay (1000); // Wait for 1000 millisecond(s)
}
➢ Circuit:
➢ Circuit Diagram:
1. Arduino Uno
2. Red Led
3. Jumper Wire
4. Breadboard
5. 10 KΩ & 100Ω Resistor
➢ Circuit Diagram:
➢ Code:
void setup(){
pinMode (ledPin, OUTPUT);
void loop () {
// Read the state of the push button
int buttonState = digitalRead(buttonPin);
} else {
digitalWrite (ledPin, LOW); // Turn LED off
}
}
➢ Circuit:
Practical:-4
Aim:
To interface a DHT11 sensor with Arduino and write a program to print temperature and
humidity readings on LCD displays.
➢ Components:
Arduino Uno
Jumper Wire
Breadboard
DTH 11 Sensor
➢ Circuit Diagram:
➢ Code:
void setup() {
Serial.begin(9600); // Start serial communication
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait 2 seconds between measurements
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
➢ Output:
Practical 5
Aim:To implement an application which senses temperature and humidity. If it is above the
predefined threshold value, then the application should glow the LED for notification.
➢ Components Required:
• Arduino Uno
• Jumper Wires
• Breadboard
• DHT11 Sensor
• LED
➢ Circuit Diagram:
➢ Code:
#include "DHT.h" // Include DHT library
#define DHTPIN 7 // Pin connected to DHT11 sensor
#define DHTTYPE DHT11 // Define DHT type
int led = 13; // LED connected to pin 13
DHT dht(DHTPIN, DHTTYPE); // Create DHT object
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(led, OUTPUT); // Set LED as output
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait a few seconds between measurements
// Read humidity and temperature
float humi = dht.readHumidity();
float tempC = dht.readTemperature();
float tempF = dht.readTemperature(true);
// Check for reading errors
if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
Serial.println("Failed to read from DHT sensor!");
UTU/CGPIT/B.TECH/CE/SEM-7/B-1/Internet of Things (IT6002)
Enrollment No.: 202203103510031 Monalisa Padhy
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("% | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
// Check temperature threshold
if (tempC > 29.00) {
digitalWrite(led, HIGH); // Turn LED ON if temperature > 29°C
} else {
digitalWrite(led, LOW); // Turn LED OFF otherwise
}
}
}
Output:
Practical 6
Aim:To implement an application which senses smoke with senses smoke with the help of
smoke detector & an alarm using Arduino Uno.
➢ Components Required:
• Arduino Uno
• MQ2 Gas Sensor
• 5V LED
• 100 ohm resistor
• Jumper wires
➢ Circuit Diagram:
➢ Code:
void setup() {
pinMode(MQ135Pin, INPUT); // Set MQ135 pin as input
pinMode(BuzzerPin, OUTPUT); // Set Buzzer pin as output
Serial.begin(9600); // Start serial communication
}
void loop() {
sensorValue = analogRead(MQ135Pin); // Read gas level from sensor
Serial.print("Gas Sensor Value: ");
Serial.println(sensorValue);
➢ Output:
Practical 7
Aim:To implement the following applications on Arduino board: Measure water level using
Arduino Uno.
➢ Components Required:
• Arduino Uno
• Water level sensor
• Jumper Wire
• Breadboard
➢ Circuit Diagram:
➢ Code:
void setup() {
// Declare LED pins as outputs
pinMode(2, OUTPUT); // LED 1
pinMode(3, OUTPUT); // LED 2
void loop() {
sensorValue = analogRead(analogInPin); // Read analog input
Serial.print("Sensor = ");
Serial.println(sensorValue);
delay(2);
➢ Output:
Practical 8
Aim:To develop an application to send and receive data with NodeMCU using HTTP requests.
➢ Components Required:
• DHT22
• Jumper wire
• Breadboard
• Node MCU
➢ Diagram:
➢ Code:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
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());
void loop() {
// Send an HTTP POST request depending on timerDelay
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
In the loop() is where you actually make the HTTP GET request every 5 seconds with
sample data:
Output:
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
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());
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
// If you need an HTTP request with a content type: application/json, use the
following:
//http.addHeader("Content-Type", "application/json");
//int httpResponseCode =
http.POST("{\"api_key\":\"tPmAT5Ab3j7F9\",\"sensor\":\"BME280\",\"value1\":\"
24.25\",\"value2\":\"49.54\",\"value3\":\"1005.14\"}");
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
Output:
Those values are also sent to 3 Gauges and are displayed in Node-RED Dashboard:
Practical 9
Aim:To develop an application that measures the room temperature and post the temperature
value on Thingspeak cloud platform.
➢ Components Required:
• Arduino Uno
• DHT22
• Jumper wire
• Breadboard
• LCD Display
➢ Circuit Diagram:
➢ Code:
#include <LiquidCrystal.h>
#include <DHT.h>
// Initialize the LCD (RS, EN, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTPIN 7 // Pin connected to DHT11 sensor
#define DHTTYPE DHT11 // Define sensor type
DHT dht(DHTPIN, DHTTYPE); // Create DHT object
void setup() {
lcd.begin(16, 2); // Initialize 16x2 LCD
lcd.print("DHT11 Sensor");
if (isnan(humidity) || isnan(temperature)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sensor Error!");
return;
}
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print("%");
Practical 10
Aim:
To develop an application for measuring the distance using ultrasonic sensors and post distance
value on Thingspeak cloud platform.
➢ Components Required:
• Arduino Uno
• Ultrasonic Sensors
• Wi-Fi Module
• Jumper Wire
➢ Circuit Diagram:
➢ Code:
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(trigPin, OUTPUT); // Set trigger pin as output
pinMode(echoPin, INPUT); // Set echo pin as input
}
void loop() {
// Clear the trigger
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Calculate distance
cm = (duration / 2) / 29.1; // Convert to centimeters
inches = (duration / 2) / 74; // Convert to inches
➢ Output:
Practical 11
Aim:To develop an application that measures the moisture of soil and post the sensed data
over Google Firebase cloud platform.
➢ Components Required:
• Nodemcu (ESP8266)
• Soil Moisture Sensor Module (with analog output)
• Jumper Wires
• Breadboard
• USB Cable
➢ Circuit Diagram:
➢ Code:
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.h>
void setup()
{
Serial.begin(115200);
dht.begin(); //reads dht sensor data
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP()); //prints local IP address
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to
the firebase
void loop()
{
float h = dht.readHumidity(); // Read Humidity
float t = dht.readTemperature(); // Read temperature
➢ Output:
Practical 12
Aim:To develop an application for controlling LED with a switch using Raspberry Pi.
➢ Components Required:
• Raspberry pi
• Blynk App
• LED
• Resistor (250 ohm)
• Jumper Wires
• Breadboard
➢ Circuit Diagram:
➢ Code:
import RPi.GPIO as GPIO
import BlynkLib
import time
BLYNK_AUTH = 'YourAuthToken'
# Setup GPIO
led = 17 # GPIO17 pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(led, GPIO.OUT)
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):
if int(value[0]) == 1:
GPIO.output(led, GPIO.HIGH)
print("LED ON")
else:
GPIO.output(led, GPIO.LOW)
print("LED OFF")
while True:
blynk.run()
time.sleep(0.1)
➢ Output: