TEXT 257
Abbasi taklif Guest on 22nd December 2023 06:00:42 PM
  1. //AmirHosseinAbbasi
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4.  
  5. #define ldr A0
  6. #define heater 4
  7. #define fan 5
  8. #define ONE_WIRE_BUS 2
  9.  
  10. OneWire oneWire(ONE_WIRE_BUS);
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. void setup() {
  14.   Serial.begin(9600);
  15.   sensors.begin();
  16.   pinMode(heater,OUTPUT);
  17.   pinMode(fan,OUTPUT);
  18.   pinMode(7,OUTPUT);
  19.   pinMode(8,OUTPUT);
  20.   pinMode(9,OUTPUT);
  21.   pinMode(10,OUTPUT);
  22.  
  23. }
  24. int i = 0;
  25. void loop() {
  26.   if(i == 0){
  27.   int a = random(7,11);
  28.   i = 1;
  29.   }
  30.   int dn = analogRead(ldr);
  31.   sensors.requestTemperatures();
  32.   float temp = sensors.getTempCByIndex(0);
  33.     if (temp != DEVICE_DISCONNECTED_C)
  34.   {
  35.   Serial.print("Temperature is: ");
  36.   Serial.println(temp);
  37.     if(temp <= 20){
  38.       digitalWrite(heater, HIGH);
  39.       digitalWrite(fan, LOW);
  40.     }
  41.     if(temp >= 28){
  42.       digitalWrite(heater, LOW);
  43.       digitalWrite(fan, HIGH);
  44.     }
  45.     if(temp < 28 && temp > 20){
  46.       digitalWrite(heater, LOW);
  47.       digitalWrite(fan, LOW);
  48.     }
  49.     if(dn < 400){
  50.       digitalWrite(a,HIGH);
  51.       i =1;
  52.     }
  53.     if(dn >= 400){
  54.       i =0;
  55.       digitalWrite(7,LOW);
  56.       digitalWrite(8,LOW);
  57.       digitalWrite(9,LOW);
  58.       digitalWrite(10,LOW);
  59.     }
  60.   }
  61.   else
  62.   {
  63.     Serial.println("Error to reading data");
  64.   }
  65.  
  66. }

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.