monitor/control code with the following
temperature/humidity in fahrenheit
control temperature monitoring off a dht11
Fan/vent control with schedule on html and rtc with manual on/off button
Swamp cooler with schedule on html and rtc with manual on/off button
2 different light control one veg one flower with schedule on html and rtc with manual on/off button
Useing rtc,dht,light sensor and rtc
but i keep getting this This site can’t be reached when i try to get into the web page
here my code if anyone can help be nice thank you
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <WebServer.h>
- #include <RTClib.h>
- #include <DHT.h>
- #define DHTPIN 2 // Pin connected to the DHT11 sensor
- #define DHTTYPE DHT11 // DHT sensor type
- #define FAN_PIN 4 // Pin connected to the relay module for fan/vent control
- #define SWAMP_COOLER_PIN 5 // Pin connected to the relay module for swamp cooler control
- #define VEG_LIGHT_PIN 6 // Pin connected to the relay module for veg light control
- #define FLOWER_LIGHT_PIN 7 // Pin connected to the relay module for flower light control
- #define LIGHT_SENSOR_PIN A0 // Pin connected to the light sensor (LDR)
- DHT dht(DHTPIN, DHTTYPE);
- RTC_DS3231 rtc;
- WebServer server(80);
- int fanOnHour = 8; // Fan/vent on hour
- int fanOffHour = 18; // Fan/vent off hour
- int swampCoolerOnHour = 9; // Swamp cooler on hour
- int swampCoolerOffHour = 17; // Swamp cooler off hour
- int vegLightOnHour = 6; // Veg light on hour
- int vegLightOffHour = 18; // Veg light off hour
- int flowerLightOnHour = 8; // Flower light on hour
- int flowerLightOffHour = 20; // Flower light off hour
- void handleRoot() {
- String html = "<html><body>";
- html += "<h1>Greenhouse Control</h1>";
- html += "<h2>Temperature and Humidity</h2>";
- html += "<p>Temperature: ";
- html += String(dht.readTemperature() * 1.8 + 32); // Convert temperature to Fahrenheit
- html += " °F</p>";
- html += "<p>Humidity: ";
- html += String(dht.readHumidity());
- html += " %</p>";
- html += "<h2>Fan/Vent Control</h2>";
- html += "<form action='/fan' method='POST'>";
- html += "Fan/Vent Schedule: <input type='time' name='onTime' value='08:00'> - <input type='time' name='offTime' value='18:00'><br>";
- html += "<input type='submit' value='Set Schedule'>";
- html += "</form>";
- html += "<br>";
- html += "<form action='/fan' method='POST'>";
- html += "<input type='submit' name='fanOn' value='Fan On'>";
- html += "<input type='submit' name='fanOff' value='Fan Off'>";
- html += "</form>";
- html += "<h2>Swamp Cooler Control</h2>";
- html += "<form action='/swampCooler' method='POST'>";
- html += "Swamp Cooler Schedule: <input type='time' name='onTime' value='09:00'> - <input type='time' name='offTime' value='17:00'><br>";
- html += "<input type='submit' value='Set Schedule'>";
- html += "</form>";
- html += "<br>";
- html += "<form action='/swampCooler' method='POST'>";
- html += "<input type='submit' name='swampCoolerOn' value='Swamp Cooler On'>";
- html += "<input type='submit' name='swampCoolerOff' value='Swamp Cooler Off'>";
- html += "</form>";
- html += "<h2>Veg Light Control</h2>";
- html += "<form action='/vegLight' method='POST'>";
- html += "Veg Light Schedule: <input type='time' name='onTime' value='06:00'> - <input type='time' name='offTime' value='18:00'><br>";
- html += "<input type='submit' value='Set Schedule'>";
- html += "</form>";
- html += "<br>";
- html += "<form action='/vegLight' method='POST'>";
- html += "<input type='submit' name='vegLightOn' value='Veg Light On'>";
- html += "<input type='submit' name='vegLightOff' value='Veg Light Off'>";
- html += "</form>";
- html += "<h2>Flower Light Control</h2>";
- html += "<form action='/flowerLight' method='POST'>";
- html += "Flower Light Schedule: <input type='time' name='onTime' value='08:00'> - <input type='time' name='offTime' value='20:00'><br>";
- html += "<input type='submit' value='Set Schedule'>";
- html += "</form>";
- html += "<br>";
- html += "<form action='/flowerLight' method='POST'>";
- html += "<input type='submit' name='flowerLightOn' value='Flower Light On'>";
- html += "<input type='submit' name='flowerLightOff' value='Flower Light Off'>";
- html += "</form>";
- html += "</body></html>";
- server.send(200, "text/html", html);
- }
- void handleFan() {
- if (server.hasArg("onTime") && server.hasArg("offTime")) {
- String onTime = server.arg("onTime");
- String offTime = server.arg("offTime");
- fanOnHour = onTime.substring(0, 2).toInt();
- fanOffHour = offTime.substring(0, 2).toInt();
- server.send(200, "text/plain", "Fan schedule updated");
- } else if (server.hasArg("fanOn")) {
- digitalWrite(FAN_PIN, HIGH);
- server.send(200, "text/plain", "Fan turned on");
- } else if (server.hasArg("fanOff")) {
- digitalWrite(FAN_PIN, LOW);
- server.send(200, "text/plain", "Fan turned off");
- }
- }
- void handleSwampCooler() {
- if (server.hasArg("onTime") && server.hasArg("offTime")) {
- String onTime = server.arg("onTime");
- String offTime = server.arg("offTime");
- swampCoolerOnHour = onTime.substring(0, 2).toInt();
- swampCoolerOffHour = offTime.substring(0, 2).toInt();
- server.send(200, "text/plain", "Swamp cooler schedule updated");
- } else if (server.hasArg("swampCoolerOn")) {
- digitalWrite(SWAMP_COOLER_PIN, HIGH);
- server.send(200, "text/plain", "Swamp cooler turned on");
- } else if (server.hasArg("swampCoolerOff")) {
- digitalWrite(SWAMP_COOLER_PIN, LOW);
- server.send(200, "text/plain", "Swamp cooler turned off");
- }
- }
- void handleVegLight() {
- if (server.hasArg("onTime") && server.hasArg("offTime")) {
- String onTime = server.arg("onTime");
- String offTime = server.arg("offTime");
- vegLightOnHour = onTime.substring(0, 2).toInt();
- vegLightOffHour = offTime.substring(0, 2).toInt();
- server.send(200, "text/plain", "Veg light schedule updated");
- } else if (server.hasArg("vegLightOn")) {
- digitalWrite(VEG_LIGHT_PIN, HIGH);
- server.send(200, "text/plain", "Veg light turned on");
- } else if (server.hasArg("vegLightOff")) {
- digitalWrite(VEG_LIGHT_PIN, LOW);
- server.send(200, "text/plain", "Veg light turned off");
- }
- }
- void handleFlowerLight() {
- if (server.hasArg("onTime") && server.hasArg("offTime")) {
- String onTime = server.arg("onTime");
- String offTime = server.arg("offTime");
- flowerLightOnHour = onTime.substring(0, 2).toInt();
- flowerLightOffHour = offTime.substring(0, 2).toInt();
- server.send(200, "text/plain", "Flower light schedule updated");
- } else if (server.hasArg("flowerLightOn")) {
- digitalWrite(FLOWER_LIGHT_PIN, HIGH);
- server.send(200, "text/plain", "Flower light turned on");
- } else if (server.hasArg("flowerLightOff")) {
- digitalWrite(FLOWER_LIGHT_PIN, LOW);
- server.send(200, "text/plain", "Flower light turned off");
- }
- }
- void setup() {
- pinMode(FAN_PIN, OUTPUT);
- pinMode(SWAMP_COOLER_PIN, OUTPUT);
- pinMode(VEG_LIGHT_PIN, OUTPUT);
- pinMode(FLOWER_LIGHT_PIN, OUTPUT);
- dht.begin();
- rtc.begin();
- WiFi.begin("ASUS", "AlexRuder1997"); // Replace with your WiFi credentials
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("WiFi connected");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- server.on("/", handleRoot);
- server.on("/fan", handleFan);
- server.on("/swampCooler", handleSwampCooler);
- server.on("/vegLight", handleVegLight);
- server.on("/flowerLight", handleFlowerLight);
- server.begin();
- Serial.println("Server started");
- }
- void loop() {
- server.handleClient();
- // Check if it's time to turn on/off the fan
- DateTime now = rtc.now();
- int currentHour = now.hour();
- if (currentHour >= fanOnHour && currentHour < fanOffHour) {
- digitalWrite(FAN_PIN, HIGH);
- } else {
- digitalWrite(FAN_PIN, LOW);
- }
- // Check if it's time to turn on/off the swamp cooler
- if (currentHour >= swampCoolerOnHour && currentHour < swampCoolerOffHour) {
- digitalWrite(SWAMP_COOLER_PIN, HIGH);
- } else {
- digitalWrite(SWAMP_COOLER_PIN, LOW);
- }
- // Check if it's time to turn on/off the veg light
- if (currentHour >= vegLightOnHour && currentHour < vegLightOffHour) {
- digitalWrite(VEG_LIGHT_PIN, HIGH);
- } else {
- digitalWrite(VEG_LIGHT_PIN, LOW);
- }
- // Check if it's time to turn on/off the flower light
- if (currentHour >= flowerLightOnHour && currentHour < flowerLightOffHour) {
- digitalWrite(FLOWER_LIGHT_PIN, HIGH);
- } else {
- digitalWrite(FLOWER_LIGHT_PIN, LOW);
- }
- }