CPP 246
Eyvazian Guest on 22nd December 2023 07:32:45 PM
  1. #include <OneWire.h>
  2. #include<DallasTemperature.h>
  3. #define fan 5
  4. #define LDR A0
  5. #define out 2
  6. #define heater 4
  7. OneWire oneWire(out);
  8. DallasTemperature sensors(&oneWire);
  9. void setup() {
  10.   Serial.begin(9600);
  11.   sensors.begin();
  12.   pinMode(heater,OUTPUT);
  13.   pinMode(fan,OUTPUT);
  14.   pinMode(7,OUTPUT);
  15.   pinMode(8,OUTPUT);
  16.   pinMode(9,OUTPUT);
  17.   pinMode(10,OUTPUT);}
  18. void loop() {
  19.   sensors.requestTemperatures();
  20.   float temp = sensors.getTempCByIndex(0);
  21.   if (temp != DEVICE_DISCONNECTED_C){
  22.     int random = random(7,10);
  23.     while(analogRead(LDR) < 400){
  24.       digitalWrite(random, 1);
  25.      
  26.       if(temp < 20){
  27.         digitalWrite(fan, 0);
  28.         digitalWrite(heater, 1);}
  29.   if(temp < 40 && temp > 20){
  30.         digitalWrite(fan, 0);
  31.         digitalWrite(heater, 0);}
  32.   if(temp >= 40){
  33.         digitalWrite(fan, 1);
  34.         digitalWrite(heater, 0);}}
  35.   while(analogRead(LDR) >= 400){
  36.       digitalWrite(7, 0);
  37.       digitalWrite(8, 0);
  38.       digitalWrite(9, 0);
  39.       digitalWrite(10, 0);
  40.   if(temp < 20){
  41.         digitalWrite(fan, 0);
  42.         digitalWrite(heater, 1);}
  43.   if(temp < 40 && temp > 20){
  44.         digitalWrite(fan, 0);
  45.         digitalWrite(heater, 0);}
  46.   if(temp >= 40){
  47.         digitalWrite(fan, 1);
  48.         digitalWrite(heater, 0);}}else{Serial.println("Data Error");}
  49. }
  50. //eyvazian

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.