- //AmirHosseinAbbasi
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ldr A0
- #define heater 4
- #define fan 5
- #define ONE_WIRE_BUS 2
- OneWire oneWire(ONE_WIRE_BUS);
- 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);
- }
- int i = 0;
- void loop() {
- if(i == 0){
- int a = random(7,11);
- i = 1;
- }
- int dn = analogRead(ldr);
- sensors.requestTemperatures();
- float temp = sensors.getTempCByIndex(0);
- if (temp != DEVICE_DISCONNECTED_C)
- {
- Serial.print("Temperature is: ");
- Serial.println(temp);
- if(temp <= 20){
- digitalWrite(heater, HIGH);
- digitalWrite(fan, LOW);
- }
- if(temp >= 28){
- digitalWrite(heater, LOW);
- digitalWrite(fan, HIGH);
- }
- if(temp < 28 && temp > 20){
- digitalWrite(heater, LOW);
- digitalWrite(fan, LOW);
- }
- if(dn < 400){
- digitalWrite(a,HIGH);
- i =1;
- }
- if(dn >= 400){
- i =0;
- digitalWrite(7,LOW);
- digitalWrite(8,LOW);
- digitalWrite(9,LOW);
- digitalWrite(10,LOW);
- }
- }
- else
- {
- Serial.println("Error to reading data");
- }
- }
Recent Pastes