- //amir najaf nejad
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define output 2
- #define heater 4
- #define fan 5
- #define LDR A0
- OneWire oneWire(output);
- 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)
- {
- Serial.print("Temperature: ");
- Serial.println(temp);
- delay(1000);
- if(temp <= 20){
- digitalWrite(heater,HIGH);
- }
- if(temp >= 40){
- digitalWrite(fan,HIGH);
- }
- }
- else
- {
- Serial.println("Error to reading data");
- }
- int ran = random(7,10);
- if(analogRead(LDR) < 400){
- digitalWrite(ran,HIGH);
- }
- }
Recent Pastes