Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleDHT.h>
- int pinDHT22 = 2;
- SimpleDHT22 dht22(pinDHT22);
- # define cooler 3
- # define heater 4
- int T1;
- int T2;
- int H1 = 50;
- int H2 = 70;
- #include <SoftwareSerial.h>
- SoftwareSerial B(8,9);
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- B.begin(9600);
- pinMode(cooler,OUTPUT);
- pinMode(heater,OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- float temperature = 0;
- float humidity = 0;
- int err = SimpleDHTErrSuccess;
- if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
- Serial.print("Read DHT22 failed, err="); Serial.print(SimpleDHTErrCode(err));
- Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(2000);
- return;
- }
- Serial.print("Sample OK: ");
- Serial.print((float)temperature); Serial.print(" *C, ");
- Serial.print((float)humidity); Serial.println(" RH%");
- // read the input on analog pin 0:
- int sensorValue = analogRead(A0);
- // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
- int voltage = sensorValue * (5.0 / 1023.0);
- // print out the value you read:
- Serial.println(voltage);
- if (voltage == 0){
- T1 = 32;
- T2 = 35;
- }
- if (voltage == 1){
- T1 = 29;
- T2 = 32;
- }
- if (voltage == 2){
- T1 = 26;
- T2 = 29;
- }
- if (voltage == 3){
- T1 = 23;
- T2 = 26;
- }
- if (voltage == 4){
- T1 = 20;
- T2 = 23;
- }
- Serial.print("New temperature range");
- Serial.print(T2);
- Serial.println(T1);
- B.print((float)temperature);
- B.print(",");
- B.print((float)humidity);
- B.print(",");
- B.print(T2);
- B.print(",");
- B.print(T1);
- B.print(",");
- B.print(voltage);
- B.print(",");
- B.print((millis() / 1000));
- B.print(";");
- // TEMPERATURE CONTROL
- if ((float)temperature > T2){
- // digitalWrite (cooler,HIGH);
- digitalWrite (heater,LOW);
- }
- if ((float)temperature < T1){
- digitalWrite (heater,HIGH);
- // digitalWrite (cooler,LOW);
- }
- if ((float)humidity < H1){
- // digitalWrite (heater,HIGH);
- digitalWrite (cooler,LOW);
- }
- if ((float)humidity < H2){
- // digitalWrite (heater,HIGH);
- digitalWrite (cooler,LOW);
- }
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement