Good evening,
I am that consists of a temp sensor, a fan, a lightbulb (as a heater) and lights (that turn on and off with a set time.
I tried making the lights turn on and off by using 2 counters one names"tensec" and one named "tenmin". i have an issue cause the counters are not incrementing. can anyone tell me what is wrong with my code?
Also during testing, I changed the delay from ten seconds to 1 second but the serial monitor still printed every 10 seconds did this ever happen to you?
Thanks
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
float humi;
float tempC;
float tempF;
int fan = 5;
int heat =8;
int light =11;
int htct =0;
int clct=0;
int tensec;
int tenmin;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
pinMode(heat, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(light, OUTPUT);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
// Fetch the temperature in degrees Celsius for device index:
float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
tempcont();
sm();
delay(1000);
tensec = tensec++;
// condition to change the air inside the container every time the tensec counter reaches 60 (every 10 minutes)
if(tensec = 60){
airchange();
tensec=0;
tenmin = tenmin++;
}
if(tenmin <= 120){
digitalWrite(light , HIGH);
}
if(tenmin >=121 && tenmin < 144){
digitalWrite(light , LOW);
}
if(tenmin = 144){
tenmin=0;
}
}
// subroutine that monitors the tempreture and acts acocordingly
void tempcont(){
if(tempC >= 25){
lwtemp();
}
if(tempC <= 18){
//hitemp();
}
}
//subroutine that prints on the serial monitor
void sm(){
if (isnan(tempC)) {
Serial.println("Failed to read from temp sensor!");
} else {
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(" | ");
Serial.print("heat:");
Serial.print(htct);
Serial.print(" cooling:");
Serial.println(clct);
Serial.println(tenmin);
Serial.println(tensec);
}
}
// subroutine that lowers the tempreture by turining on the fan
void lwtemp(){
digitalWrite(fan ,HIGH);
delay(8000);
digitalWrite(fan ,LOW);
clct++;
}
//subroutine that turns up the heat bu turining on a lightbulb and the fan
void hitemp(){
digitalWrite(heat ,HIGH);
digitalWrite(fan ,HIGH);
delay(8000);
digitalWrite(heat ,LOW);
digitalWrite(fan ,LOW);
htct++;
}
// subroutine that changes the air by turining on the fan for 6 seconds
void airchange(){
digitalWrite(fan ,HIGH);
delay(6000);
digitalWrite(fan ,LOW);
}