- #include <OneWire.h>
- #include <DallasTemperature.h>
- //parsa_shams_ali_zadeh
- #define fan 5
- #define LDR A0
- #define hiter 4
- #define output 2
- OneWire oneWire(output);
- DallasTemperature sensors(&oneWire);
- void setup() {
- Serial.begin(9600);
- sensors.begin();
- pinMode(hiter,OUTPUT);
- pinMode(fan,OUTPUT);
- pinMode(7,OUTPUT);
- pinMode(8,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(10,OUTPUT);}
- void loop() {
- sensors.requestTemperatures();
- int W = analogRead(LDR);
- if(flag == 0){ int a = random(7,10);
- flag = 1 ;}
- float temp = sensors.getTempCByIndex(0);
- if (temp != DEVICE_DISCONNECTED_C){
- Serial.print("Temperature: ");
- Serial.println(temp);
- if (temp < 16 ) {digitalWrite(hiter , HIGH);
- digitalWrite( fan , LOW);}
- if (temp >= 16 && <= 28 ) {digitalWrite(hiter , LOW);
- digitalWrite( fan , LOW);}
- if (temp >28 ) {digitalWrite(hiter , LOW);
- digitalWrite( fan , HIGH);}
- if(W < 400){
- digitalWrite(a,HIGH);
- flag = 1 ;
- }
- if(W >= 400){
- flag = 0 ;
- digitalWrite(7,LOW);
- digitalWrite(8,LOW);
- digitalWrite(9,LOW);
- digitalWrite(10,LOW);
- }
- }
Recent Pastes