0% found this document useful (0 votes)
37 views9 pages

Code

The document describes code for a temperature monitoring system using a DHT sensor and WiFi module to control a robot and trigger an alert. It connects to WiFi, takes temperature readings, controls the robot motors based on URL requests, and triggers a buzzer if the temperature exceeds a threshold.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views9 pages

Code

The document describes code for a temperature monitoring system using a DHT sensor and WiFi module to control a robot and trigger an alert. It connects to WiFi, takes temperature readings, controls the robot motors based on URL requests, and triggers a buzzer if the temperature exceeds a threshold.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <DHT.

h>

#define DHT_PIN D1 // Use any GPIO pin (D1-D8) for data connection to the DHT sensor

#define DHT_TYPE DHT22 // Change to DHT11 if using DHT11 sensor

#define BUZZER_PIN D2 // Use any GPIO pin (D1-D8) for the buzzer connection

#define ALERT_TEMPERATURE 60 // Temperature threshold for triggering the alert

int IN_1 = 16;

int IN_2 = 5;

int IN_3 = 4;

int IN_4 = 0;

const char* ssid = "one";

const char* password = "qwerty123";

DHT dht(DHT_PIN, DHT_TYPE);

bool alerted = false;

WiFiServer server(80);

void setup()

Serial.begin(115200);

dht.begin();

pinMode(BUZZER_PIN, OUTPUT);

digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer at the beginning

delay(10);

pinMode(IN_1, OUTPUT);

pinMode(IN_2, OUTPUT);

pinMode(IN_3, OUTPUT);

pinMode(IN_4, OUTPUT);
// Connect to WiFi network

Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)

delay(50);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

// Start the server

server.begin();

Serial.println("Server started");

// Print the IP address

Serial.print("Use this URL to connect: ");

Serial.print("http://");

Serial.print(WiFi.localIP());

void goAhead()

digitalWrite(IN_1, LOW);

digitalWrite(IN_2, HIGH);

digitalWrite(IN_3, HIGH);

digitalWrite(IN_4, LOW);

void goBack()

{
digitalWrite(IN_1, HIGH);

digitalWrite(IN_2, LOW);

digitalWrite(IN_3, LOW);

digitalWrite(IN_4, HIGH);

void goRight()

digitalWrite(IN_1, HIGH);

digitalWrite(IN_2, LOW);

digitalWrite(IN_3, HIGH);

digitalWrite(IN_4, LOW);

void goLeft()

digitalWrite(IN_1, LOW);

digitalWrite(IN_2, HIGH);

digitalWrite(IN_3, LOW);

digitalWrite(IN_4, HIGH);

void stopRobot()

digitalWrite(IN_1, LOW);

digitalWrite(IN_2, LOW);

digitalWrite(IN_3, LOW);

digitalWrite(IN_4, LOW);

void loop()
{

delay(2000); // Wait for 2 seconds before taking the next temperature reading

float temperature = dht.readTemperature(); // Read temperature in Celsius

if (isnan(temperature)) {

Serial.println("Failed to read temperature from the sensor!");

return;

WiFiClient client = server.available();

if(!client)

return;

Serial.println("new client");

while(!client.available())

delay(0.5);

String request = client.readStringUntil('\r');

Serial.println(request);

client.flush();

if(request.indexOf("/F")>0)

goAhead();

if(request.indexOf("/R")>0)

goRight();

delay(500);

stopRobot();

}
if(request.indexOf("/L")>0)

goLeft();

delay(500);

stopRobot();

if(request.indexOf("/B")>0)

goBack();

if(request.indexOf("/S")>0)

stopRobot();

client.println("<!DOCTYPE html>");

client.println("<html lang=\"en\">");

client.println("<head>");

client.println(" <meta charset=\"UTF-8\">");

client.println(" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");

client.println(" <meta name=\"viewport\" content=\"width=device-width, initial


scale=1.0\">");

client.println(" <title>Document</title>");

client.println(" <style>");

client.println(" body");

client.println(" {");

client.println(" background-color: rgb(58, 133, 133);");

client.println(" border: 15px solid #000;");

client.println(" height: 100vh;");

client.println(" display: flex;");

client.println(" flex-direction: column;");


client.println(" justify-content: center;");

client.println(" align-items: center;");

client.println(" }");

client.println(".tab");

client.println(" {");

client.println(" display: inline-block;");

client.println(" padding: 10px 20px;");

client.println(" background-color: hsl(32, 76%, 67%);");

client.println(" font-family: 'Times New Roman', Times, serif;");

client.println(" color: black;");

client.println(" font-size: 35px;");

client.println(" cursor: pointer;");

client.println(" margin-left: 153px;");

client.println(" margin-bottom: 10px;");

client.println(" width: 150px;");

client.println(" height: 70px;");

client.println(" border-radius: 30px;");

client.println(" margin-top: 50px;");

client.println(" }");

client.println(".tab1");

client.println(" {");

client.println(" display: inline-block;");

client.println(" padding: 10px 20px;");

client.println(" background-color:hsl(32, 76%, 67%);");

client.println(" font-family: 'Times New Roman', Times, serif;");

client.println(" color: black;");

client.println(" font-size: 35px;");

client.println(" cursor: pointer;");

client.println(" margin-bottom: 10px;");

client.println(" width: 150px;");client.println(" height: 70px;");

client.println(" border-radius: 30px;");


client.println(" margin-top: 20px;");

client.println(" }");

client.println(" .tab2");

client.println(" {");

client.println(" display: inline-block;");

client.println(" padding: 10px 20px;");

client.println(" background-color:hsl(32, 76%, 67%);");

client.println(" font-family: 'Times New Roman', Times, serif;");

client.println(" color: black;");

client.println(" font-size: 35px;");

client.println(" cursor: pointer;");

client.println(" width: 150px;");

client.println(" height: 70px;");

client.println(" border-radius: 30px;");

client.println(" margin-top: 15px;");

client.println(" margin-left: 153px;");

client.println(" }");

client.println(".write{");

client.println(" margin: 0 0 0px 10px;");

client.println(" font-size: 65px;");

client.println(" font-family: fantasy;");

client.println(" color: white;");

client.println(" text-shadow: -2px -2px 0 #000,2px -2px 0 #000, -2px 2px 0 #000,2px 2px 0
#000;");

client.println("}");

client.println(" </style>");

client.println("</head>");

client.println("<body>");

client.println("<p class=\"write\">NOOBOOT</p>");

client.println("<div class=\"cont\">");

client.println("<a href=\"/F\"\"><button class=\"tab\">&uarr;</button></a><br>");


client.println("<a href=\"/L\"\"><button class=\"tab1\">&larr;</button></a>");

client.println("<a href=\"/S\"\"><button class=\"tab1\">🛑</button></a>");

client.println("<a href=\"/R\"\"><button class=\"tab1\">&rarr;</button></a><br>");

client.println("<a href=\"/B\"\"><button class=\"tab2\">&darr;</button></a><br>");

client.println("</div>");

client.println("<a href=\"/buzz\"\"><button class=\"tab1\">🔔</button></a><br>");

client.println("</body>");

client.println("</html>");

delay(1);

Serial.println("Client Disconnected");

Serial.println("");

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println(" °C");

if (temperature > ALERT_TEMPERATURE && !alerted) {

// If temperature exceeds the threshold and the alert hasn't been triggered yet

Serial.println("Temperature exceeds the threshold. Alerting!");

soundAlert();

alerted = true; // Set the flag to avoid continuous alerts until the temperature drops below the
threshold.

} else if (temperature <= ALERT_TEMPERATURE) {

// If temperature drops back below the threshold, reset the alert flag

alerted = false;

digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer

void soundAlert()

{
digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer

delay(1000); // Sound the buzzer for 1 second

digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer

You might also like