Guest User

Untitled

a guest
Jun 25th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_PCD8544.h>
  4. #include "DHT.h"
  5.  
  6. #define pmpBtn 3
  7. #define ledBtn 1
  8. #define DHTPIN D2
  9. #define DHTTYPE DHT11
  10. #define Sensor A0
  11. #define LDR_pin A0
  12. #define SMS_GND D1
  13. #define SMS_VCC D0
  14. #define LDR_VCC D8
  15.  
  16. int Hs = 0;
  17. float t = 0, h =0, ldr = 0;
  18. unsigned long prec = 0;
  19. const long tmp = 2000;
  20.  
  21. Adafruit_PCD8544 display = Adafruit_PCD8544(D3, D4, D5, D7, D6);
  22.  
  23. DHT dht(DHTPIN, DHTTYPE);
  24. int soilMoist;
  25.  
  26. void setup(){
  27. Serial.begin(115200);
  28. dht.begin();
  29. display.begin();
  30. display.setContrast(36);
  31. display.setTextWrap(false);
  32. display.clearDisplay();
  33.  
  34. pinMode(SMS_VCC,OUTPUT);
  35. pinMode(SMS_GND,OUTPUT);
  36. pinMode(LDR_VCC,OUTPUT);
  37. pinMode(pmpBtn,OUTPUT);
  38. pinMode(ledBtn,OUTPUT);
  39. }
  40.  
  41. void loop(){
  42. unsigned long act = millis();
  43.  
  44. if (act - prec >= tmp) {
  45. prec = act;
  46. ReadSensor();
  47. CapDisplay();
  48. }
  49.  
  50. }
  51.  
  52. void CapDisplay(){
  53. display.clearDisplay();
  54. display.setTextSize(1);
  55. display.drawLine(0, 0, display.width(), 0, BLACK);
  56. display.setCursor(0, 2);
  57. //display.setTextColor(WHITE, BLACK); // 'inverted' text
  58. display.print("192.168.1.17"); // just a title
  59. display.drawLine(0, 10, display.width(), 10, BLACK);
  60. //display.setTextColor(BLACK);
  61. display.setCursor(0, 13);display.print("T: C H: %");
  62. display.setCursor(64, 13);display.print((int)h);
  63. display.setCursor(15, 13);display.print((int)t);
  64. display.setCursor(0, 22);display.print("Hum-Sol:");
  65. display.setCursor(65, 22);display.print(Hs);
  66. display.setCursor(78, 22);display.print("%");
  67. display.setCursor(0, 30);display.print("Lumier : lm");
  68. display.setCursor(58, 30);display.print((int)ldr);
  69. display.setCursor(0, 38);display.print("Pm:off Led:off");
  70. display.display();
  71. }
  72.  
  73. void ReadSensor(){
  74. Read_DHT11(); // tmperature + humidité
  75. getanaValue(); // LDR + humidité de sol
  76. }
  77.  
  78. void Read_DHT11(){
  79. delay(2000);
  80.  
  81. h = dht.readHumidity();
  82. t = dht.readTemperature();
  83. if (isnan(h) || isnan(t) ) {
  84. Serial.println("Failed to read from DHT sensor!");
  85. return;
  86. }
  87. }
  88.  
  89. void getanaValue(){
  90. digitalWrite(pmpBtn,HIGH);
  91. // Lire HS
  92.  
  93. digitalWrite(SMS_VCC,LOW);
  94. digitalWrite(SMS_GND,HIGH);
  95. delay(500);
  96. Hs=analogRead(Sensor);
  97.  
  98. digitalWrite(SMS_VCC,HIGH);
  99. digitalWrite(SMS_GND,LOW);
  100. delay(500);
  101. digitalWrite(SMS_VCC,LOW);
  102. digitalWrite(SMS_GND,LOW);
  103.  
  104. Hs = map(Hs, 1023, 0, 0, 100);
  105.  
  106. // Lire Ldr
  107. digitalWrite(LDR_VCC,HIGH);
  108. delay(100);
  109. for(int i = 0; i < 10; i++)
  110. {
  111. ldr += analogRead(Sensor);
  112. delay(50);
  113. }
  114.  
  115. ldr = ldr/10;
  116. ldr = map(ldr, 1023, 0, 100, 0);
  117. digitalWrite(LDR_VCC,LOW);
  118. digitalWrite(pmpBtn,LOW);
  119. }
Add Comment
Please, Sign In to add comment