CPP 234
Parsa_shams3 Guest on 24th December 2023 01:18:04 PM
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. //parsa_shams_ali_zadeh
  4. #define fan 5
  5. #define LDR A0
  6. #define hiter 4
  7. #define output 2
  8. OneWire oneWire(output);
  9. DallasTemperature sensors(&oneWire);
  10. void setup() {
  11.   Serial.begin(9600);
  12.   sensors.begin();
  13.   pinMode(hiter,OUTPUT);
  14.   pinMode(fan,OUTPUT);
  15.   pinMode(7,OUTPUT);
  16.   pinMode(8,OUTPUT);
  17.   pinMode(9,OUTPUT);
  18.   pinMode(10,OUTPUT);}
  19. void loop() {
  20.   sensors.requestTemperatures();
  21.   int W = analogRead(LDR);
  22.   if(flag == 0){ int a = random(7,10);
  23.                digitalWrite(a,HIGH);}
  24.   float temp = sensors.getTempCByIndex(0);
  25.   if (temp != DEVICE_DISCONNECTED_C){
  26.     Serial.print("Temperature: ");
  27.     Serial.println(temp);
  28.     if (temp < 16 ) {digitalWrite(hiter , HIGH);
  29.                               digitalWrite( fan , LOW);}
  30.     if (temp >= 16 && <= 28 ) {digitalWrite(hiter , LOW);
  31.                                  digitalWrite( fan , LOW);}
  32.     if (temp >28  ) {digitalWrite(hiter , LOW);
  33.                       digitalWrite( fan , HIGH);}
  34.   if(W < 400){
  35.       digitalWrite(a,HIGH);
  36.       flag = 1 ;
  37.     }
  38.     if(W >= 400){
  39.       flag = 0 ;
  40.       digitalWrite(7,LOW);
  41.       digitalWrite(8,LOW);
  42.       digitalWrite(9,LOW);
  43.       digitalWrite(10,LOW);
  44.     }
  45.   }

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.