Advertisement
Ogomegbunam

Poultry temperature regulator 1

Feb 16th, 2024 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | Source Code | 0 0
  1. #include <SimpleDHT.h>
  2.  
  3. int pinDHT22 = 2;
  4. SimpleDHT22 dht22(pinDHT22);
  5.  
  6. # define cooler 3
  7. # define heater 4
  8.  
  9. int T1;
  10. int T2;
  11. int H1 = 50;
  12. int H2 = 70;
  13.  
  14. #include <SoftwareSerial.h>
  15. SoftwareSerial B(8,9);
  16.  
  17. void setup() {
  18. // put your setup code here, to run once:
  19. Serial.begin(115200);
  20. B.begin(9600);
  21. pinMode(cooler,OUTPUT);
  22. pinMode(heater,OUTPUT);
  23. }
  24.  
  25. void loop() {
  26. // put your main code here, to run repeatedly:
  27. float temperature = 0;
  28. float humidity = 0;
  29. int err = SimpleDHTErrSuccess;
  30. if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
  31. Serial.print("Read DHT22 failed, err="); Serial.print(SimpleDHTErrCode(err));
  32. Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(2000);
  33. return;
  34. }
  35.  
  36. Serial.print("Sample OK: ");
  37. Serial.print((float)temperature); Serial.print(" *C, ");
  38. Serial.print((float)humidity); Serial.println(" RH%");
  39.  
  40. // read the input on analog pin 0:
  41. int sensorValue = analogRead(A0);
  42. // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  43. int voltage = sensorValue * (5.0 / 1023.0);
  44. // print out the value you read:
  45. Serial.println(voltage);
  46.  
  47. if (voltage == 0){
  48. T1 = 32;
  49. T2 = 35;
  50. }
  51.  
  52. if (voltage == 1){
  53. T1 = 29;
  54. T2 = 32;
  55. }
  56.  
  57. if (voltage == 2){
  58. T1 = 26;
  59. T2 = 29;
  60. }
  61.  
  62. if (voltage == 3){
  63. T1 = 23;
  64. T2 = 26;
  65. }
  66.  
  67. if (voltage == 4){
  68. T1 = 20;
  69. T2 = 23;
  70. }
  71.  
  72.  
  73. Serial.print("New temperature range");
  74. Serial.print(T2);
  75. Serial.println(T1);
  76. B.print((float)temperature);
  77. B.print(",");
  78. B.print((float)humidity);
  79. B.print(",");
  80. B.print(T2);
  81. B.print(",");
  82. B.print(T1);
  83. B.print(",");
  84. B.print(voltage);
  85. B.print(",");
  86. B.print((millis() / 1000));
  87. B.print(";");
  88.  
  89. // TEMPERATURE CONTROL
  90. if ((float)temperature > T2){
  91. // digitalWrite (cooler,HIGH);
  92. digitalWrite (heater,LOW);
  93. }
  94.  
  95. if ((float)temperature < T1){
  96. digitalWrite (heater,HIGH);
  97. // digitalWrite (cooler,LOW);
  98. }
  99. if ((float)humidity < H1){
  100. // digitalWrite (heater,HIGH);
  101. digitalWrite (cooler,LOW);
  102. }
  103. if ((float)humidity < H2){
  104. // digitalWrite (heater,HIGH);
  105. digitalWrite (cooler,LOW);
  106. }
  107.  
  108. delay(2000);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement