added water level sensor

This commit is contained in:
Marcus 2024-03-31 04:41:50 +02:00
parent f5fdc0cd4e
commit 1644c0346c
2 changed files with 1394 additions and 260 deletions

View file

@ -7,8 +7,18 @@
* D0 - MOSFET Fan * D0 - MOSFET Fan
* D1, D2 - I2C * D1, D2 - I2C
* D3 - DHT11 * D3 - DHT11
* D4 - MOSFET Pump * D4 - water level Vcc
* D5 - MOSFET Grow LED, PWM * D5 - MOSFET Grow LED, PWM
* D6 - MOSFET Pump
* A0 - water level
*
*
* Water level
* ===========
*
* 0 - 199 : CRITICAL
* 200 - 399 : WARNING
* >400 : OK
* *
*/ */
@ -19,16 +29,16 @@
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include "DHT.h" #include "DHT.h"
uint8_t PINfan = D0;
uint8_t PINdht = D3; uint8_t PINdht = D3;
uint8_t PINfan = 3; uint8_t PINwater = D4;
uint8_t PINpump = 4; uint8_t PINled = D5;
uint8_t PINled = 5; uint8_t PINpump = D6;
uint8_t PINAwater = A0;
#define WIRE Wire #define WIRE Wire
#define DHTTYPE DHT11 #define DHTTYPE DHT11
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE); Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
// 'CanGrow_Logo', 128x32px // 'CanGrow_Logo', 128x32px
const unsigned char bmpCanGrow_Logo [] PROGMEM = { const unsigned char bmpCanGrow_Logo [] PROGMEM = {
@ -72,7 +82,6 @@ const unsigned char* bmpallArray[1] = {
bmpCanGrow_Logo bmpCanGrow_Logo
}; };
// I2C moisture sensor measurements // I2C moisture sensor measurements
// soil moisture value // soil moisture value
int chirpMoisture; int chirpMoisture;
@ -108,26 +117,47 @@ unsigned int readI2CRegister16bit(int addr, int reg) {
} }
void setup() { void setup() {
// setup pins
pinMode(PINfan, OUTPUT);
pinMode(PINdht, INPUT);
pinMode(PINwater, OUTPUT);
pinMode(PINled, OUTPUT);
pinMode(PINpump, OUTPUT);
// set all OUTPUT to low
digitalWrite(PINfan, LOW);
digitalWrite(PINwater, LOW);
digitalWrite(PINled, LOW);
digitalWrite(PINpump, LOW);
// initialise Wire for I2C
Wire.begin(); Wire.begin();
// initialise Serial output
Serial.begin(115200); Serial.begin(115200);
// reset chirp
writeI2CRegister8bit(0x20, 6); //reset writeI2CRegister8bit(0x20, 6); //reset
// initialise I2C display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
pinMode(PINdht, INPUT); // initialise DHT11
dht.begin(); dht.begin();
display.clearDisplay(); display.clearDisplay();
display.display(); display.display();
// set display settings
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
// display Logo
display.drawBitmap(0, 0, bmpCanGrow_Logo, 128, 32, WHITE); display.drawBitmap(0, 0, bmpCanGrow_Logo, 128, 32, WHITE);
display.display(); display.display();
delay(2500); delay(2500);
// clear display
display.clearDisplay(); display.clearDisplay();
display.display(); display.display();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
} }
void loop() { void loop() {
@ -173,8 +203,17 @@ void loop() {
display.print(dht.readTemperature()); display.print(dht.readTemperature());
display.print(", "); display.print(", ");
display.print(dht.readHumidity()); display.print(dht.readHumidity());
//display.println(readI2CRegister16bit(0x20, 0)); display.println(readI2CRegister16bit(0x20, 0));
display.display(); display.display();
delay(500);
digitalWrite(PINwater, HIGH);
delay(200);
display.print("Water: ");
display.println(analogRead(PINAwater));
digitalWrite(PINwater, LOW);
display.display();
} }

File diff suppressed because it is too large Load diff