Title - Solution To All Types of IoT Based Monitoring Systems
Title - Solution To All Types of IoT Based Monitoring Systems
Contents:
● IoT based Cloud Server (Thingspeak.com)
● Inserting and Reading Data from Thingspeak
● Circuit Diagram of Real Time Monitoring System
● Programming
● Web Interface
● Conclusion
IoT based Cloud Server (Thingspeak.com)
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>
#include <DHT.h>
// WiFi credentials
const char* ssid = "salehin";
const char* password = "1122334455";
// ThingSpeak credentials
unsigned long myChannelNumber = 2640391;
const char* myWriteAPIKey = "XYNT30MAQLSC5ZXM";
// Define pins
#define DHTPIN1 D2
#define DHTPIN2 D3
#define PIRPIN D4
#define LEDPIN D5
#define BUZZERPIN D6
#define MQPIN A0 // MQ sensor connected to analog pin A0
#define DHTTYPE DHT22
// Thresholds
float temperatureThreshold = 35.0;
int smokeThreshold = 200; // Adjust this value based on your MQ sensor's calibration
WiFiClient client;
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
// Initialize ThingSpeak
ThingSpeak.begin(client);
}
void loop() {
// Read temperature and humidity
float temp1 = dht1.readTemperature();
float temp2 = dht2.readTemperature();
float humidity1 = dht1.readHumidity();
float humidity2 = dht2.readHumidity();
int smokeValue = analogRead(MQPIN);
int motion = 0;
digitalWrite(LEDPIN, LOW);
Web Interface
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Real Time Data Center Monitoring</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Entry ID</th>
<th>Temperature</th>
<th>Humidity</th>
<th>Smoke (Td = 200)</th>
<th>Motion</th>
</tr>
</thead>
<tbody id="data-table">
<!-- Data will be inserted here -->
</tbody>
</table>
<script>
const channelID = "2640391";
const apiKey = "XYNT30MAQLSC5ZXM";
const refreshInterval = 15000; // 15 seconds
function fetchData() {
const url =
`https://api.thingspeak.com/channels/${channelID}/feeds.json?api_key=${apiKey}&results
=5`;
fetch(url)
.then(response => response.json())
.then(data => {
const feeds = data.feeds;
const table = document.getElementById("data-table");
feeds.forEach(feed => {
const row = document.createElement("tr");
table.appendChild(row);
});
})
.catch(error => console.error('Error fetching data:', error));
}
</body>
</html>
Conclusion