TEXT 264
Thermostat abdi 2 Guest on 22nd December 2023 07:15:24 PM
  1. //Mohsen_abdi
  2.  
  3. #include <OneWire.h>
  4. #include<DallasTemperature.h>
  5.  
  6. #define output 2
  7. #define heter 4
  8. #define fan 5
  9. #define LDR A0
  10.  
  11. OneWire oneWire(output);
  12. DallasTemperature sensors(&oneWire);
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.   sensors.begin();
  17.   pinMode(heter,OUTPUT);
  18.   pinMode(fan,OUTPUT);
  19.   pinMode(7,OUTPUT);
  20.   pinMode(8,OUTPUT);
  21.   pinMode(9,OUTPUT);
  22.   pinMode(10,OUTPUT);
  23.  
  24. }
  25.  
  26. void loop() {
  27.   sensors.requestTemperatures();
  28.   float temp = sensors.getTempCByIndex(0);
  29.   int random = random(7,10);
  30.   if (temp != DEVICE_DISCONNECTED_C)
  31.   { 
  32.     while(analogRead(LDR) < 400){
  33.       digitalWrite(random, 1);
  34.      
  35.       if(temp <= 20){
  36.         digitalWrite(fan, 0);
  37.         digitalWrite(heter, 1);
  38.       }
  39.       if(temp >= 40){
  40.         digitalWrite(fan, 1);
  41.         digitalWrite(heter, 0);
  42.       }
  43.       if(temp < 40 && temp > 20){
  44.         digitalWrite(fan, 0);
  45.         digitalWrite(heter, 0);
  46.       }
  47.     }
  48.    while(analogRead(LDR) >= 400){
  49.       digitalWrite(7, 0);
  50.       digitalWrite(8, 0);
  51.       digitalWrite(9, 0);
  52.       digitalWrite(10, 0);
  53.    
  54.       if(temp <= 20){
  55.         digitalWrite(fan, 0);
  56.         digitalWrite(heter, 1);
  57.       }
  58.       if(temp >= 40){
  59.         digitalWrite(fan, 1);
  60.         digitalWrite(heter, 0);
  61.       }
  62.       if(temp < 40 && temp > 20){
  63.         digitalWrite(fan, 0);
  64.         digitalWrite(heter, 0);
  65.       }
  66.   }
  67.   else
  68.   {
  69.     Serial.println("Data Error");
  70.   }
  71. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.