Unwanted Flashing Light

When the egg incubator door is open I want a light to come on but as it is currently programmed the light flashes. Any idea why? The light part is around line 275 to 304

The screen also tries to half go back to the main menu every time the light flashes. It must be connected somehow.

The code is to long to post in here so it is attached.

EGG_INCUBATOR_By_SLIMFARMER.ino (24.2 KB)

Can you provide a diagram of how your hardware is connected?

aarg:
Can you provide a diagram of how your hardware is connected?

If you look at the pin outs you can see what would be connected to each pin. That's rather irrelevant really. The flaw will be in the code.

Here is your problem:

  if (digitalRead (BUT6) == LOW)  // Button for light
  {
    digitalWrite(Light, LOW);  // Relay on for light
    delay (3000);
  }
  else
  {
    digitalWrite(Light, HIGH);  // Relay off for light
  }

ToddL1962:
Here is your problem:

  if (digitalRead (BUT6) == LOW)  // Button for light

{
    digitalWrite(Light, LOW);  // Relay on for light
    delay (3000);
  }
  else
  {
    digitalWrite(Light, HIGH);  // Relay off for light
  }

Care to explain?

Pretty simple. You check to see if the door is open and turn the light on if it is. Later in the code you check the light button BUT6 and if it is not pressed you turn the light off. Therefore, the light blinks.

ToddL1962:
Pretty simple. You check to see if the door is open and turn the light on if it is. Later in the code you check the light button BUT6 and if it is not pressed you turn the light off. Therefore, the light blinks.

Okay so what if i make it so if the button is pressed and the door is closed then turn on the light by button. That way if the door is open it won't be affected by the button code.

Just move that code into the door closed check you already have like this:

  if (doorstatus == HIGH) // Door CLOSED
  {
    if (digitalRead (BUT6) == LOW)  // Button for light
    {
      digitalWrite(Light, LOW);  // Relay on for light
      delay (3000);
    }
    else
    {
      digitalWrite(Light, HIGH);  // Relay off for light
    }
    digitalWrite(motorpin, HIGH);
    b = 0;
  }

ToddL1962:
Just move that code into the door closed check you already have like this:

  if (doorstatus == HIGH) // Door CLOSED

{
    if (digitalRead (BUT6) == LOW)  // Button for light
    {
      digitalWrite(Light, LOW);  // Relay on for light
      delay (3000);
    }
    else
    {
      digitalWrite(Light, HIGH);  // Relay off for light
    }
    digitalWrite(motorpin, HIGH);
    b = 0;
  }

Perfect thanks it works. Also if I wanted to have it show the intro whenever the door is closed is that possible? I tried this morning and failed many times. It kept getting stuck in an intro loop

Anita_Bath:
Perfect thanks it works. Also if I wanted to have it show the intro whenever the door is closed is that possible? I tried this morning and failed many times. It kept getting stuck in an intro loop

What you want to do is detect the door "has opened" not that it "is open". You need to detect the state change of the door. That way you only show the intro once and not over and over again. Here is a great state change detection example.

StateChangeDetection

ToddL1962:
What you want to do is detect the door "has opened" not that it "is open". You need to detect the state change of the door. That way you only show the intro once and not over and over again. Here is a great state change detection example.

StateChangeDetection

I was using momentary button toggle code so I was on the right track and had the door state reading out to the serial print. I could see it changing. However I couldn't get it to see the state and actually show the intro...