- #include <OneWire.h>
- #include<DallasTemperature.h>
- #define fan 5
- #define LDR A0
- #define out 2
- #define heater 4
- OneWire oneWire(out);
- DallasTemperature sensors(&oneWire);
- void setup() {
- Serial.begin(9600);
- sensors.begin();
- pinMode(heater,OUTPUT);
- pinMode(fan,OUTPUT);
- pinMode(7,OUTPUT);
- pinMode(8,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(10,OUTPUT);}
- void loop() {
- sensors.requestTemperatures();
- float temp = sensors.getTempCByIndex(0);
- if (temp != DEVICE_DISCONNECTED_C){
- int random = random(7,10);
- while(analogRead(LDR) < 400){
- digitalWrite(random, 1);
- if(temp < 20){
- digitalWrite(fan, 0);
- digitalWrite(heater, 1);}
- if(temp < 40 && temp > 20){
- digitalWrite(fan, 0);
- digitalWrite(heater, 0);}
- if(temp >= 40){
- digitalWrite(fan, 1);
- digitalWrite(heater, 0);}}
- while(analogRead(LDR) >= 400){
- digitalWrite(7, 0);
- digitalWrite(8, 0);
- digitalWrite(9, 0);
- digitalWrite(10, 0);
- if(temp < 20){
- digitalWrite(fan, 0);
- digitalWrite(heater, 1);}
- if(temp < 40 && temp > 20){
- digitalWrite(fan, 0);
- digitalWrite(heater, 0);}
- if(temp >= 40){
- digitalWrite(fan, 1);
- digitalWrite(heater, 0);}}else{Serial.println("Data Error");}
- }
- //eyvazian
Recent Pastes