You will llikely get even crazier when you really try to maintain a temperature of an oven. I have actually done what you are trying, but using a SSR to control the power. The first problem is the initial heating of the oven. The temperature will overshoot your set temperature because the temperature sensor is not directly attached to the heating element. Heated air must circulate from the heater to the sensor and in that time, the heating element is just heating away. So you overshoot and turn off.
Same thing happens, but now you have turned off the element and are waiting for the convection air to tell the sensor the air is cooler, so turn back on. But the oven air has cooled below the set point and we continue the race between the sensor and the heating element.
Did you write your code in stages?
If so you should have some code that JUST reads the buttons to prove you have a proper connection.
Use the Serial Monitor to show that the buttons are working.
bool bPress = false;
bool YesHeating = false;
int start_lastButtonState = 0;
void setup() {
//Define the pins
pinMode (start_pin, INPUT);
pinMode (estop_pin, INPUT);
start_buttonState = digitalRead(start_pin);
lcd.init(); //Start the LC communication
lcd.backlight(); //Turn on backlight for LCD
}
void loop()
{
void zeroCross();
void checkUp();
void checkDown();
currentMillis = millis(); //Save the value of time before the loop
// Push the start button to activate heating but NOT start the timer yet
if (start_buttonState != start_lastButtonState) // compare the buttonState to its previous state
{
if (start_buttonState == LOW) // if the state has changed, increase the counter
{
bPress = true; // if the current state is HIGH then the button went from off to on:
YesHeating = true;
}
}
start_lastButtonState = start_buttonState; // save the current state as the last state, for next time through the loop
if ( YesHeating == HIGH)
{
heating_active = true; // Activate heating
timer_started = false; // Ensure the timer doesn't start until setpoint is reached
}
Have you fixed this yet? You need to use if (digitalRead(zero_cross) == HIGH) to read and test the detector output.
if (zero_cross == HIGH) { //We make an AND with the state register, We verify if pin D8 is HIGH???
In order to get this project working, first get all the parts working, each by themselves.
Make sure you can read the switches, read the zero crossing detector output and turn the heater on and off, with short, individual programs, before putting the pieces together.