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

WiFi-Controlled Robot with Temperature Alert

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)
10 views9 pages

WiFi-Controlled Robot with Temperature Alert

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()

[Link](115200);

[Link]();

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

[Link]();

[Link]("Connecting to ");

[Link](ssid);

[Link](ssid, password);

while ([Link]() != WL_CONNECTED)

delay(50);

[Link](".");

[Link]("");

[Link]("WiFi connected");

// Start the server

[Link]();

[Link]("Server started");

// Print the IP address

[Link]("Use this URL to connect: ");

[Link]("[Link]

[Link]([Link]());

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 = [Link](); // Read temperature in Celsius

if (isnan(temperature)) {

[Link]("Failed to read temperature from the sensor!");

return;

WiFiClient client = [Link]();

if(!client)

return;

[Link]("new client");

while(![Link]())

delay(0.5);

String request = [Link]('\r');

[Link](request);

[Link]();

if([Link]("/F")>0)

goAhead();

if([Link]("/R")>0)

goRight();

delay(500);

stopRobot();

}
if([Link]("/L")>0)

goLeft();

delay(500);

stopRobot();

if([Link]("/B")>0)

goBack();

if([Link]("/S")>0)

stopRobot();

[Link]("<!DOCTYPE html>");

[Link]("<html lang=\"en\">");

[Link]("<head>");

[Link](" <meta charset=\"UTF-8\">");

[Link](" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");

[Link](" <meta name=\"viewport\" content=\"width=device-width, initial


scale=1.0\">");

[Link](" <title>Document</title>");

[Link](" <style>");

[Link](" body");

[Link](" {");

[Link](" background-color: rgb(58, 133, 133);");

[Link](" border: 15px solid #000;");

[Link](" height: 100vh;");

[Link](" display: flex;");

[Link](" flex-direction: column;");


[Link](" justify-content: center;");

[Link](" align-items: center;");

[Link](" }");

[Link](".tab");

[Link](" {");

[Link](" display: inline-block;");

[Link](" padding: 10px 20px;");

[Link](" background-color: hsl(32, 76%, 67%);");

[Link](" font-family: 'Times New Roman', Times, serif;");

[Link](" color: black;");

[Link](" font-size: 35px;");

[Link](" cursor: pointer;");

[Link](" margin-left: 153px;");

[Link](" margin-bottom: 10px;");

[Link](" width: 150px;");

[Link](" height: 70px;");

[Link](" border-radius: 30px;");

[Link](" margin-top: 50px;");

[Link](" }");

[Link](".tab1");

[Link](" {");

[Link](" display: inline-block;");

[Link](" padding: 10px 20px;");

[Link](" background-color:hsl(32, 76%, 67%);");

[Link](" font-family: 'Times New Roman', Times, serif;");

[Link](" color: black;");

[Link](" font-size: 35px;");

[Link](" cursor: pointer;");

[Link](" margin-bottom: 10px;");

[Link](" width: 150px;");[Link](" height: 70px;");

[Link](" border-radius: 30px;");


[Link](" margin-top: 20px;");

[Link](" }");

[Link](" .tab2");

[Link](" {");

[Link](" display: inline-block;");

[Link](" padding: 10px 20px;");

[Link](" background-color:hsl(32, 76%, 67%);");

[Link](" font-family: 'Times New Roman', Times, serif;");

[Link](" color: black;");

[Link](" font-size: 35px;");

[Link](" cursor: pointer;");

[Link](" width: 150px;");

[Link](" height: 70px;");

[Link](" border-radius: 30px;");

[Link](" margin-top: 15px;");

[Link](" margin-left: 153px;");

[Link](" }");

[Link](".write{");

[Link](" margin: 0 0 0px 10px;");

[Link](" font-size: 65px;");

[Link](" font-family: fantasy;");

[Link](" color: white;");

[Link](" text-shadow: -2px -2px 0 #000,2px -2px 0 #000, -2px 2px 0 #000,2px 2px 0
#000;");

[Link]("}");

[Link](" </style>");

[Link]("</head>");

[Link]("<body>");

[Link]("<p class=\"write\">NOOBOOT</p>");

[Link]("<div class=\"cont\">");

[Link]("<a href=\"/F\"\"><button class=\"tab\">&uarr;</button></a><br>");


[Link]("<a href=\"/L\"\"><button class=\"tab1\">&larr;</button></a>");

[Link]("<a href=\"/S\"\"><button class=\"tab1\">🛑</button></a>");

[Link]("<a href=\"/R\"\"><button class=\"tab1\">&rarr;</button></a><br>");

[Link]("<a href=\"/B\"\"><button class=\"tab2\">&darr;</button></a><br>");

[Link]("</div>");

[Link]("<a href=\"/buzz\"\"><button class=\"tab1\">🔔</button></a><br>");

[Link]("</body>");

[Link]("</html>");

delay(1);

[Link]("Client Disconnected");

[Link]("");

[Link]("Temperature: ");

[Link](temperature);

[Link](" °C");

if (temperature > ALERT_TEMPERATURE && !alerted) {

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

[Link]("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