CPP 231
Ds18b20 najaf Guest on 22nd December 2023 10:02:31 AM
  1. //amir najaf nejad
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4.  
  5. #define output 2
  6. #define heater 4
  7. #define fan 5
  8. #define LDR A0
  9.  
  10. OneWire oneWire(output);
  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.  
  25. void loop() {
  26.   sensors.requestTemperatures();
  27.   float temp = sensors.getTempCByIndex(0);
  28.   if (temp != DEVICE_DISCONNECTED_C)
  29.   {
  30.     Serial.print("Temperature: ");
  31.     Serial.println(temp);
  32.     delay(1000);
  33.     if(temp <= 20){
  34.       digitalWrite(heater,HIGH);
  35.     }
  36.     if(temp >= 40){
  37.       digitalWrite(fan,HIGH);
  38.     }
  39.   }
  40.   else
  41.   {
  42.     Serial.println("Error to reading data");
  43.   }
  44.   int ran = random(7,10);
  45.   if(analogRead(LDR) < 400){
  46.     digitalWrite(ran,HIGH);
  47.   }
  48.  
  49. }

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.