//Quality sensors available (https://atlas-scientific.com/)
// display/UI
//https://github.com/ImpulseAdventure/GUIslice/wiki/GUIslice-Builder
//https://www.lcd-module.com/products-lcd-oled-tft-hmi-display-industrial-medicine/unitftdesignr-tool.html
//ambient temp/humidity
#include "DHTesp.h"
#define DHTPIN 15
#define DHTTYPE DHTesp::DHT22 // DHT 22 (AM2302), AM2321
DHTesp dhtSensor;
//water temp
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#define SENSOR_WATER_TEMP_PIN 10
//filter pressure
//https://www.amazon.com/dp/B0CRQTNY9F/ref=sspa_dk_detail_0?pd_rd_i=B0CRQXGMWD&pd_rd_w=0OYhL&content-id=amzn1.sym.8c2f9165-8e93-42a1-8313-73d3809141a2&pf_rd_p=8c2f9165-8e93-42a1-8313-73d3809141a2&pf_rd_r=NKSFNPM8CT47TV6Q4RKW&pd_rd_wg=73LJq&pd_rd_r=d50d0132-ecaa-4878-ad4c-e78d690656e1&s=industrial&sp_csd=d2lkZ2V0TmFtZT1zcF9kZXRhaWw&th=1
//~$15
#define SENSOR_FILTER_PRESSURE_PIN 18
//water PH
//https://www.amazon.com/gp/product/B09H1MJS4S/ref=ewc_pr_img_2?smid=A38CU2XC1RY0BO&psc=1
//https://atlas-scientific.com/kits/surveyor-analog-ph-kit/
//~$70
#define SENSOR_WATER_PH_PIN 19
//Water level
//ultrasonic https://a.co/d/50jGknG
//https://wiki.dfrobot.com/_A02YYUW_Waterproof_Ultrasonic_Sensor_SKU_SEN0311
//https://learn.adafruit.com/ultrasonic-sonar-distance-sensors/python-circuitpython
//Heater Control
//Pump Control
//AWS IOT
//https://docs.arduino.cc/tutorials/opta/getting-started-with-aws-iot-core/
//https://learn.adafruit.com/pyportal-iot-plant-monitor-with-aws-iot-and-circuitpython/create-your-settings-toml-file
//
//Sensors
#define SENSOR_AMBIENT_HUMIDITY 1
#define SENSOR_AMBIENT_TEMP 2
#define SENSOR_FILTER_PRESSURE 3
#define SENSOR_WATER_LEVEL 4
#define SENSOR_WATER_ORP 5
#define SENSOR_WATER_PH 6
#define SENSOR_WATER_TEMP 7
//Globals
float gAmbientTemperature = 0.0; //Deg F
float gAmbientHumidity = 0.0; //%
float gWaterTemperature = 0.0; //Deg F
float gFilterPressure = 0.0; //psi
float gWaterPH = 0.0; //PH
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!" );
analogReadResolution(10);
int start = millis();
//SetupDisplay(); //for now just use serial
SetupAmbientSensor();
SetupWaterTempSensor();
SetupFilterPressure();
SetupWaterPHSensor();
//SetupWaterLevelSensor(); //Remote Sensor
//SetupWaterORPSensor();
//SetupLocalWebServer();
//SetupCloudLogging();
Serial.print("Setup Time: ");
Serial.println(millis()-start);
}
void loop() {
// put your main code here, to run repeatedly:
int start = millis();
UpdateAmbientSensor();
UpdateWaterTempSensor();
UpdateFilterPressure();
UpdateWaterPHSensor();
//UpdateWaterLevelSensor(); //Remote Sensor
//UpdateWaterORPSensor();
//UpdateLocalWebServer();
//UpdateCloudLogging();
// UpdateDisplay();
Serial.print("Loop Time: ");
Serial.println(millis()-start);
delay(5000); // delay loop
}
void SetupAmbientSensor(){
dhtSensor.setup(DHTPIN, DHTTYPE);
}
void SetupCloudLogging(){
Serial.println("SetupCloudLogging Not Implemented");
}
void SetupDisplay(){
Serial.println("SetupDisplay Not Implemented");
}
void SetupFilterPressure(){
pinMode(SENSOR_FILTER_PRESSURE_PIN,INPUT);
}
void SetupLocalWebServer(){
Serial.println("SetupLocalWebServerNot Implemented");
}
void SetupWaterTempSensor(){
pinMode(SENSOR_WATER_TEMP_PIN,INPUT);
}
void SetupWaterPHSensor(){
}
void SetupWaterLevelSensor(){
Serial.println("SetupWaterLevelSensor Not Implemented");
}; //Remote Sensor
void SetupWaterORPSensor(){
Serial.println("SetupWaterORPSensor Not Implemented");
}
void UpdateAmbientSensor(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(data.temperature) || isnan(data.humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//read in C, store in F
gAmbientTemperature = (data.temperature * 1.8) + 32;
gAmbientHumidity = data.humidity;
Serial.println("Ambient Temperature: " + String(gAmbientTemperature, 1) + "°F");
Serial.println("Ambient Humidity: " + String(gAmbientHumidity, 1) + "%");
}
void UpdateCloudLogging(){
Serial.println("UpdateCloudLogging Not Implemented");
}
void UpdateDisplay(){
Serial.println("UpdateDisplay Not Implemented");
}
void UpdateFilterPressure(){
// Read the analog value from the potentiometer
int pressureValue = analogRead(SENSOR_FILTER_PRESSURE_PIN);
// Check if any reads failed and exit early (to try again).
if (isnan(pressureValue)) {
Serial.println(F("Failed to read from pressure sensor!"));
return;
}
// Convert the analog value to a pressure reading (simplified example)
// Map the analog value to a pressure range (0-100 psi)
gFilterPressure = mapf(pressureValue, 0, 1023, 0.0, 100.0);
// Send the simulated pressure reading to the serial monitor
Serial.print("Filter Pressure (psi): ");
Serial.println(gFilterPressure);
}
void UpdateLocalWebServer(){
Serial.println("UpdateLocalWebServer Not Implemented");
}
void UpdateWaterTempSensor(){
int analogValue = analogRead(SENSOR_WATER_TEMP_PIN);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
gWaterTemperature = (celsius * 1.8) + 32;
Serial.println("Water Temperature: " + String(gWaterTemperature, 1) + "°F");
}
void UpdateWaterPHSensor(){
// Map analog reading to pH range 0-14
int analogValue = analogRead(SENSOR_WATER_PH_PIN);
gWaterPH = mapf(analogValue, 0, 1023, 0.0, 14.0);
Serial.println("Water PH: " + String(gWaterPH, 1));
}
void UpdateWaterLevelSensor(){//Remote Sensor
Serial.println("UpdateWaterLevelSensor Not Implemented");
}
void UpdateWaterORPSensor(){
Serial.println("UpdateWaterORPSensor Not Implemented");
}
float mapf(long x, float in_min, float in_max, float out_min, float out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}Ambient Temp Humidity
Pool Water Temp Thermister
Presure sensor
PH sensor