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 Ti;
- int Hi;
- int H1 = 60;
- 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(Ti);
- Serial.print((float)humidity); Serial.println(" RH%"); Serial.print(Hi);
- //Temperature and humidity Match
- int Ti = ((float)temperature - 1);
- int Hi = ((float)humidity - 10);
- // 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 = 33;
- T2 = 35;
- }
- if (voltage == 1){
- T1 = 31;
- T2 = 33;
- }
- if (voltage == 2){
- T1 = 29;
- T2 = 31;
- }
- if (voltage == 3){
- T1 = 27;
- T2 = 29;
- }
- if (voltage == 4){
- T1 = 25;
- T2 = 27;
- }
- if (voltage == 5){
- T1 = 25;
- T2 = 27;
- }
- Serial.print("New temperature range");
- Serial.print(T2);
- Serial.println(T1);
- B.print(Ti);
- B.print(",");
- B.print(Hi);
- 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 (Ti > T2){
- digitalWrite (cooler,LOW);
- digitalWrite (heater,HIGH);
- }
- if (Ti < T1){
- digitalWrite (heater,LOW);
- digitalWrite (cooler,HIGH);
- }
- if (Hi < H1){
- // digitalWrite (heater,HIGH);
- digitalWrite (cooler,HIGH);
- }
- if (Hi > H2){
- // digitalWrite (heater,HIGH);
- digitalWrite (cooler,LOW);
- }
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement