added water level sensor
This commit is contained in:
parent
f5fdc0cd4e
commit
1644c0346c
2 changed files with 1394 additions and 260 deletions
|
@ -7,8 +7,18 @@
|
|||
* D0 - MOSFET Fan
|
||||
* D1, D2 - I2C
|
||||
* D3 - DHT11
|
||||
* D4 - MOSFET Pump
|
||||
* D4 - water level Vcc
|
||||
* 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 "DHT.h"
|
||||
|
||||
uint8_t PINfan = D0;
|
||||
uint8_t PINdht = D3;
|
||||
uint8_t PINfan = 3;
|
||||
uint8_t PINpump = 4;
|
||||
uint8_t PINled = 5;
|
||||
uint8_t PINwater = D4;
|
||||
uint8_t PINled = D5;
|
||||
uint8_t PINpump = D6;
|
||||
uint8_t PINAwater = A0;
|
||||
|
||||
#define WIRE Wire
|
||||
#define DHTTYPE DHT11
|
||||
|
||||
|
||||
|
||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||
// 'CanGrow_Logo', 128x32px
|
||||
const unsigned char bmpCanGrow_Logo [] PROGMEM = {
|
||||
|
@ -72,7 +82,6 @@ const unsigned char* bmpallArray[1] = {
|
|||
bmpCanGrow_Logo
|
||||
};
|
||||
|
||||
|
||||
// I2C moisture sensor measurements
|
||||
// soil moisture value
|
||||
int chirpMoisture;
|
||||
|
@ -108,26 +117,47 @@ unsigned int readI2CRegister16bit(int addr, int reg) {
|
|||
}
|
||||
|
||||
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();
|
||||
// initialise Serial output
|
||||
Serial.begin(115200);
|
||||
// reset chirp
|
||||
writeI2CRegister8bit(0x20, 6); //reset
|
||||
// initialise I2C display
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
|
||||
|
||||
pinMode(PINdht, INPUT);
|
||||
// initialise DHT11
|
||||
dht.begin();
|
||||
|
||||
display.clearDisplay();
|
||||
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.display();
|
||||
delay(2500);
|
||||
|
||||
// clear display
|
||||
display.clearDisplay();
|
||||
display.display();
|
||||
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -173,8 +203,17 @@ void loop() {
|
|||
display.print(dht.readTemperature());
|
||||
display.print(", ");
|
||||
display.print(dht.readHumidity());
|
||||
//display.println(readI2CRegister16bit(0x20, 0));
|
||||
display.println(readI2CRegister16bit(0x20, 0));
|
||||
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
Loading…
Reference in a new issue