Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_PCD8544.h>
- #include "DHT.h"
- #define pmpBtn 3
- #define ledBtn 1
- #define DHTPIN D2
- #define DHTTYPE DHT11
- #define Sensor A0
- #define LDR_pin A0
- #define SMS_GND D1
- #define SMS_VCC D0
- #define LDR_VCC D8
- int Hs = 0;
- float t = 0, h =0, ldr = 0;
- unsigned long prec = 0;
- const long tmp = 2000;
- Adafruit_PCD8544 display = Adafruit_PCD8544(D3, D4, D5, D7, D6);
- DHT dht(DHTPIN, DHTTYPE);
- int soilMoist;
- void setup(){
- Serial.begin(115200);
- dht.begin();
- display.begin();
- display.setContrast(36);
- display.setTextWrap(false);
- display.clearDisplay();
- pinMode(SMS_VCC,OUTPUT);
- pinMode(SMS_GND,OUTPUT);
- pinMode(LDR_VCC,OUTPUT);
- pinMode(pmpBtn,OUTPUT);
- pinMode(ledBtn,OUTPUT);
- }
- void loop(){
- unsigned long act = millis();
- if (act - prec >= tmp) {
- prec = act;
- ReadSensor();
- CapDisplay();
- }
- }
- void CapDisplay(){
- display.clearDisplay();
- display.setTextSize(1);
- display.drawLine(0, 0, display.width(), 0, BLACK);
- display.setCursor(0, 2);
- //display.setTextColor(WHITE, BLACK); // 'inverted' text
- display.print("192.168.1.17"); // just a title
- display.drawLine(0, 10, display.width(), 10, BLACK);
- //display.setTextColor(BLACK);
- display.setCursor(0, 13);display.print("T: C H: %");
- display.setCursor(64, 13);display.print((int)h);
- display.setCursor(15, 13);display.print((int)t);
- display.setCursor(0, 22);display.print("Hum-Sol:");
- display.setCursor(65, 22);display.print(Hs);
- display.setCursor(78, 22);display.print("%");
- display.setCursor(0, 30);display.print("Lumier : lm");
- display.setCursor(58, 30);display.print((int)ldr);
- display.setCursor(0, 38);display.print("Pm:off Led:off");
- display.display();
- }
- void ReadSensor(){
- Read_DHT11(); // tmperature + humidité
- getanaValue(); // LDR + humidité de sol
- }
- void Read_DHT11(){
- delay(2000);
- h = dht.readHumidity();
- t = dht.readTemperature();
- if (isnan(h) || isnan(t) ) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- }
- void getanaValue(){
- digitalWrite(pmpBtn,HIGH);
- // Lire HS
- digitalWrite(SMS_VCC,LOW);
- digitalWrite(SMS_GND,HIGH);
- delay(500);
- Hs=analogRead(Sensor);
- digitalWrite(SMS_VCC,HIGH);
- digitalWrite(SMS_GND,LOW);
- delay(500);
- digitalWrite(SMS_VCC,LOW);
- digitalWrite(SMS_GND,LOW);
- Hs = map(Hs, 1023, 0, 0, 100);
- // Lire Ldr
- digitalWrite(LDR_VCC,HIGH);
- delay(100);
- for(int i = 0; i < 10; i++)
- {
- ldr += analogRead(Sensor);
- delay(50);
- }
- ldr = ldr/10;
- ldr = map(ldr, 1023, 0, 100, 0);
- digitalWrite(LDR_VCC,LOW);
- digitalWrite(pmpBtn,LOW);
- }
Add Comment
Please, Sign In to add comment