Plant Watering
This commit is contained in:
BIN
Smart Home/Smart Plant Watering/3D Models/Smashing Jaagub.stl
Normal file
BIN
Smart Home/Smart Plant Watering/3D Models/Smashing Jaagub.stl
Normal file
Binary file not shown.
BIN
Smart Home/Smart Plant Watering/Circuit.png
Normal file
BIN
Smart Home/Smart Plant Watering/Circuit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,110 @@
|
|||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
|
|
||||||
|
#include <Ticker.h>
|
||||||
|
|
||||||
|
//Static IP address configuration
|
||||||
|
IPAddress staticIP(192, 168, 1, 170);
|
||||||
|
IPAddress gateway(192, 168, 1, 1);
|
||||||
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
|
IPAddress dns(192, 168, 1, 1);
|
||||||
|
IPAddress dns2(8, 8, 8, 8);
|
||||||
|
|
||||||
|
const char *deviceName = "MakeItSmart_Plant_Watering";
|
||||||
|
const char *ssid = "**********Your_SSID************";
|
||||||
|
const char *password = "********Your Password**********";
|
||||||
|
|
||||||
|
ESP8266WebServer httpServer(80);
|
||||||
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
|
#define mosfet 12
|
||||||
|
#define relay 14
|
||||||
|
|
||||||
|
const int analogInPin = A0;
|
||||||
|
|
||||||
|
Ticker timer;
|
||||||
|
bool state = false;
|
||||||
|
int humidity = 0;
|
||||||
|
|
||||||
|
Ticker relay_timer;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
pinMode(relay, OUTPUT);
|
||||||
|
pinMode(mosfet, OUTPUT);
|
||||||
|
|
||||||
|
//analogWriteRange(1024);
|
||||||
|
|
||||||
|
timer.attach_ms(1000, readSensorValue);
|
||||||
|
|
||||||
|
connectToWifi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
analogWrite(mosfet, state ? 130 : 0);
|
||||||
|
digitalWrite(relay, state ? HIGH : LOW);
|
||||||
|
|
||||||
|
httpServer.handleClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------Operational functions-----------------------------------------
|
||||||
|
void connectToWifi() {
|
||||||
|
WiFi.hostname(deviceName);
|
||||||
|
WiFi.config(staticIP, gateway, subnet, dns, dns2);
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
while (WiFi.status() != WL_CONNECTED && counter < 20) {
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WiFi.status() != WL_CONNECTED) ESP.restart();
|
||||||
|
|
||||||
|
httpUpdater.setup(&httpServer);
|
||||||
|
httpServer.on("/get_device_type", get_device_type);
|
||||||
|
httpServer.on("/get_humidity", get_humidity);
|
||||||
|
httpServer.on("/get_state", get_state);
|
||||||
|
httpServer.on("/waterize", waterize);
|
||||||
|
|
||||||
|
httpServer.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void readSensorValue() {
|
||||||
|
humidity = (int)((1024 - analogRead(analogInPin)) / 10.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopWaterizing() {
|
||||||
|
if (relay_timer.active()) relay_timer.detach();
|
||||||
|
state = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------Http functions-----------------------------------------
|
||||||
|
void get_device_type() {
|
||||||
|
httpServer.send(200, "text/plain", "Plant Watering");
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_humidity() {
|
||||||
|
httpServer.send(200, "text/plain", String(humidity));
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_state() {
|
||||||
|
httpServer.send(200, "text/plain", String(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void waterize() {
|
||||||
|
state = httpServer.arg("value").toInt() == 1;
|
||||||
|
if (state) {
|
||||||
|
int duration = httpServer.arg("duration").toInt();
|
||||||
|
if (!relay_timer.active()) relay_timer.attach_ms(duration > 0 ? duration : 3000, stopWaterizing);
|
||||||
|
} else {
|
||||||
|
if (relay_timer.active()) relay_timer.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer.send(200, "text/plain", "Ok");
|
||||||
|
}
|
||||||
1
Smart Home/Smart Plant Watering/Youtube Video.txt
Normal file
1
Smart Home/Smart Plant Watering/Youtube Video.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://youtu.be/yxsz6cjm-5I
|
||||||
@@ -17,8 +17,8 @@ IPAddress dns(192, 168, 1, 1);
|
|||||||
IPAddress dns2(8, 8, 8, 8);
|
IPAddress dns2(8, 8, 8, 8);
|
||||||
|
|
||||||
const char *deviceName = "MakeItSmart_Roller_Blind";
|
const char *deviceName = "MakeItSmart_Roller_Blind";
|
||||||
const char *ssid = "Your SSID";
|
const char *ssid = "**********Your_SSID************";
|
||||||
const char *password = "Your Password";
|
const char *password = "********Your Password**********";
|
||||||
|
|
||||||
ESP8266WebServer httpServer(80);
|
ESP8266WebServer httpServer(80);
|
||||||
ESP8266HTTPUpdateServer httpUpdater;
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|||||||
99
Smart Home/Smart Switch/Smart_Switch/Smart_Switch.ino
Normal file
99
Smart Home/Smart Switch/Smart_Switch/Smart_Switch.ino
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
|
#define LED D5
|
||||||
|
|
||||||
|
ESP8266WebServer httpServer(80);
|
||||||
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
|
bool state = false;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
unsigned long lastSensorRead = 0;
|
||||||
|
unsigned long sensorReadDelay = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
analogWriteRange(255);
|
||||||
|
|
||||||
|
pinMode(LED, OUTPUT);
|
||||||
|
|
||||||
|
bool success = SPIFFS.begin();
|
||||||
|
if (!success) Serial.println("Error mounting the file system");
|
||||||
|
|
||||||
|
connectToWifi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if ((millis() - lastSensorRead) > sensorReadDelay) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(LED, state ? HIGH : LOW);
|
||||||
|
|
||||||
|
httpServer.handleClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void connectToWifi() {
|
||||||
|
Serial.print("Connecting");
|
||||||
|
|
||||||
|
IPAddress staticIP(192, 168, 1, 150);
|
||||||
|
IPAddress gateway(192, 168, 1, 1);
|
||||||
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
|
IPAddress dns(192, 168, 1, 1);
|
||||||
|
IPAddress dns2(8, 8, 8, 8);
|
||||||
|
|
||||||
|
const char* deviceName = "MakeItSmart_Smart_Thermometer";
|
||||||
|
const char *ssid = "**********Your_SSID************";
|
||||||
|
const char *password = "********Your Password**********";
|
||||||
|
|
||||||
|
WiFi.hostname(deviceName);
|
||||||
|
WiFi.config(staticIP, gateway, subnet, dns, dns2);
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_AP_STA);
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
while (WiFi.status() != WL_CONNECTED && counter++ < 20) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
if (WiFi.status() != WL_CONNECTED) ESP.restart();
|
||||||
|
|
||||||
|
Serial.print("IP:");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
httpUpdater.setup(&httpServer);
|
||||||
|
httpServer.on("/get_state", get_state);
|
||||||
|
httpServer.on("/toggle", toggle);
|
||||||
|
httpServer.on("/get_device_type", get_device_type);
|
||||||
|
httpServer.begin();
|
||||||
|
|
||||||
|
Serial.print("IP:");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
delay(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------Http Functions---------------------------------------------------------------
|
||||||
|
|
||||||
|
void get_state() {
|
||||||
|
httpServer.send(200, "text/plain", /*"hum : " +*/ String(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggle() {
|
||||||
|
state = !state;
|
||||||
|
httpServer.send(200, "text/plain", /*"temp : " +*/ String(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_device_type() {
|
||||||
|
httpServer.send(200, "text/plain", "Switch");
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
|
#include "DHT.h"
|
||||||
|
|
||||||
|
#define DHTTYPE DHT11
|
||||||
|
#define DHTpin 14
|
||||||
|
|
||||||
|
ESP8266WebServer httpServer(80);
|
||||||
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
|
DHT dht(DHTpin, DHTTYPE);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
float humidity = 0;
|
||||||
|
float temperature = 0;
|
||||||
|
|
||||||
|
unsigned long lastSensorRead = 0;
|
||||||
|
unsigned long sensorReadDelay = 1000;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
analogWriteRange(255);
|
||||||
|
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
|
bool success = SPIFFS.begin();
|
||||||
|
if (!success) Serial.println("Error mounting the file system");
|
||||||
|
|
||||||
|
connectToWifi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if ((millis() - lastSensorRead) > sensorReadDelay) {
|
||||||
|
lastSensorRead = millis();
|
||||||
|
|
||||||
|
float tmp = dht.readTemperature();
|
||||||
|
if (tmp != temperature) updateTemperature(tmp);
|
||||||
|
|
||||||
|
float hmd = dht.readHumidity();
|
||||||
|
if (hmd != humidity) updateHumidity(hmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer.handleClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void connectToWifi() {
|
||||||
|
Serial.print("Connecting");
|
||||||
|
|
||||||
|
IPAddress staticIP(192, 168, 1, 160);
|
||||||
|
IPAddress gateway(192, 168, 1, 1);
|
||||||
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
|
IPAddress dns(192, 168, 1, 1);
|
||||||
|
IPAddress dns2(8, 8, 8, 8);
|
||||||
|
|
||||||
|
const char* deviceName = "MakeItSmart_Smart_Thermometer";
|
||||||
|
const char *ssid = "**********Your_SSID************";
|
||||||
|
const char *password = "********Your Password**********";
|
||||||
|
|
||||||
|
WiFi.hostname(deviceName);
|
||||||
|
WiFi.config(staticIP, gateway, subnet, dns, dns2);
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_AP_STA);
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
while (WiFi.status() != WL_CONNECTED && counter++ < 20) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
if (WiFi.status() != WL_CONNECTED) ESP.restart();
|
||||||
|
|
||||||
|
Serial.print("IP:");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
httpUpdater.setup(&httpServer);
|
||||||
|
httpServer.on("/getHumidity", getHumidity);
|
||||||
|
httpServer.on("/getTemperature", getTemperature);
|
||||||
|
httpServer.on("/get_device_type", get_device_type);
|
||||||
|
httpServer.begin();
|
||||||
|
|
||||||
|
Serial.print("IP:");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
delay(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateTemperature(float value) {
|
||||||
|
temperature = value ;
|
||||||
|
//temperature = random(-20, 80); //value ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateHumidity(float value) {
|
||||||
|
humidity = value;
|
||||||
|
//humidity = random(0, 100); //value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------Http Functions---------------------------------------------------------------
|
||||||
|
|
||||||
|
void getHumidity(){
|
||||||
|
httpServer.send(200, "text/plain", /*"hum : " +*/ String(humidity));
|
||||||
|
}
|
||||||
|
|
||||||
|
void getTemperature(){
|
||||||
|
httpServer.send(200, "text/plain", /*"temp : " +*/ String(temperature));
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_device_type(){
|
||||||
|
httpServer.send(200, "text/plain", "Thermometer");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user