Arduino

Arduino

Dnipro MTO

#define pin_volt_line A0 // also could be used as int pin_volt_line = A0

#define heater_pin 8

#define max_cnt 1

 

int count_of_cycles = 0; // variable for amount of cycles of the compressor

int volt_from_line = 0; // information which we get from the resistor(0-1023)

float voltage_info = 0; // additional information about voltage on the resistor

 

void setup() {

 Serial.begin(9600);// enabling serial port

 pinMode(pin_volt_line, INPUT); // configuring pin as an input, to read the data from

 pinMode(heater_pin, OUTPUT); // configuring pin as an output, for relay

 digitalWrite(heater_pin, HIGH); // set high level voltage onto pin "heater_pin"

}

 

void loop() {

 volt_from_line = analogRead(pin_volt_line);// reading information from the line

 voltage_info = volt_from_line * (5.0 / 1023); // additional information about voltage on the line

 Serial.println(voltage_info);

 

 if (volt_from_line < 23) { // the compressor is off

   count_of_cycles++;

   Serial.println("The amount of cycles: ");

   Serial.println(count_of_cycles);// outputing information into Serial Monitor

   Serial.println("\n");

   while (1) {

     volt_from_line = analogRead(pin_volt_line); // reads information from the resistor

     if (count_of_cycles == max_cnt) { //if condition is true then put heater on

       digitalWrite(heater_pin, LOW); // when zero on the pin -> relay is ON

       delay(150000);// changing value in argument causes changing of time which fan would work

       digitalWrite(heater_pin, HIGH); // when zero on the pin -> relay is OFF

       count_of_cycles = 0;

 

     }

 

     if (volt_from_line > 800) // if voltage from resistor comes high(i.e. compressor is on) then break into main loop

       break;

 

     delay(60000);

   }

 }

 

 

 delay(1000);

}

Report Page