Help with inputs and mills() timers

Hello all, I am a newbie this is only my 3rd sketch. I try doing the research but I have a TBI and am just not as quick on the uptake as I used to be. Basically I am controlling a night light, a fan with external thermostat and a relay to override the thermostat. If it is low light and the LASER sensor is broken I want the light to come on for 10 mins. If it is above 80° (external thermostat) and the Laser sensor is broken it will turn on a fan. If it is below 80° and a button is pressed it will fire a relay that will override the thermostat for 10 mins. This sketch compiles but does not work, I need help fixing it. I have tried working with mills() timers with no luck. I have added to the sketch’s comments where I would like to add mills() timers. You will also notice the reference to LASER Mosfets in the sketch comments, I can’t figure out how to do multiple things with a single input so help here too if possible. It’s not like I haven’t tried, this is the 10th attempt at this sketch, I just can’t get it. THANKS FOR YOUR HELP, Mike…

Garage_light_WITH__NIGHT_LIGHT___FAN_OVERRIDE_LDR_WORKING.ino.ino (2.7 KB)

I find it very hard to make sense of long paragraphs. This style is much clearer (for me at least)

Basically I am controlling a night light, a fan with external thermostat and a relay to override the thermostat.

If it is low light and the LASER sensor is broken I want the light to come on for 10 mins.

If it is above 80° (external thermostat) and the Laser sensor is broken it will turn on a fan.

If it is below 80° and a button is pressed it will fire a relay that will override the thermostat for 10 mins.

I have had a quick look at your code. It is very poorly formatted so I can't quickly make any sense of it. Use the Auto-Format option in the Arduino IDE and post the tidied up version.

The demo several things at a time illustrates how to use millis() for timing.

...R

Robin, Thanks for the advise on how to post code questions. Here is the auto formatted sketch:

Garage_light_WITH__NIGHT_LIGHT___FAN_OVERRIDE_LDR_WORKING.ino.i.ino (2.18 KB)

and the LASER sensor is broken

If the laser sensor is broken, it's not much good, is it? 8)

  pinMode(ledAPin, OUTPUT); pinMode(ledBPin, OUTPUT); pinMode(ledCPin, OUTPUT); pinMode(ledDPin, OUTPUT);
  pinMode(buttonApin, INPUT); pinMode(buttonBpin, INPUT_PULLUP); pinMode(buttonCpin, INPUT_PULLUP);

That was how far I got. ONE STATEMENT PER LINE!

The variable names should indicate something about what they're used for. So that:

digitalWrite(ledBPin, HIGH); //OUT TO EXTERNAL LIGHT TIMER RELAY

becomes

digitalWrite(lightRelay, HIGH);

...and all caps is SCREAMING, even in code.

If the comments take the lines out to 199 characters long, consider giving them their own line.

I really can't read your code the way it is. It's just too much effort. If I was paid to do it I would.

Also, your aim of introducing millis() timing, will require a complete redesign of the entire program anyway. So nothing is lost.

Have a look at how the code is laid out in planning and implementing a program.

Put the "action" code into short functions (with meaningful names) which you can test and then forget about.

Then you can focus on the logic of the problem.

...R

Thank all you for your help. The sketch is working now. Here is a copy of the finished sketch. If anyone sees anything else to improve it let me know…Thanks again, Mike Now

Garage_light_WITH__NIGHT_LIGHT___FAN_OVERRIDE_LDR_WORKING.ino (2.12 KB)