Power on 1 hour delay

Evening peeps.

I'm fairly new to Arduino and only messing around with the most basic of programmes. I'm mainly hardware based in my experience so would usually find an 'analogue' based approach.

I'm hoping someone could help me with a programme whereby ...

Upon power up a pin (say pin 1) is pulled high

After 1 hour, that same pin (say pin 2) is pulled low

The micro waits until a different pin is pulled low to restart the timer.

I know it's probably fairly simple where it looks to see if the hour has elapsed AND if pin 2 has been pressed or something like that but like I said I'm a total noob with programming with zero spare time to watch tutorials so some help would be forever appreciated.

Thanks in advance,
Bobz

Try again. If the pin is Pin 1, that same pin can't be Pin 2. I recommend using Pin 2 as the output pin.

Perhaps Pin 3?

So you want Pin 2 to go HIGH when your sketch starts or when Pin 3 is LOW? One hour after the latter of the time the sketch started and the time Pin 3 was last LOW, Pin 2 should go LOW?

Sincere apologies. I'm writing this after a 14 hour shift so I did make mistakes which I will rectify now.

I'm impressed with the super fast response! Thank you!

Pin 2 = output to relay

Pin 3 = input from button

Cause and effect is as follows.....

Power on starts a 1 hour timer and pulls pin 2 low for the duration of the timer.

Once timer runs out, pin 2 goes high and micro seemingly becomes idol

When pin 3 is pulled low, the 1 hour timer is restarted and pin 2 is pulled low for the duration of the timer.

Thanks again

Not sure if it will help to get some context in the project this programme is for.

I have a unit with back up batteries. This unit gains it's main power from a battery charger type power brick which controls the charging voltage depending on the current being drawn. The original designers of this cabinet decided to power the control module from the same supply since the control module houses battery monitoring.

Because the control module draws current of its own, the charging module still thinks the batteries need a higher 'boosted' voltage. This is dangerously overcharging and ruining expensive lead acid batteries.

The idea was to allow the boosted voltage to remain untouched to reach the batteries for no longer than 1 hour then switch a relay in to connect a current limiter in series with a diode in series for reverse polarity protection of the current limiter. A reverse biased diode across the current limiter will allow back up power to reach the unit.

Something like this (for active HIGH relay, swap HIGH/LOW if active LOW)...

const int buttonPin = 2;
const int relayPin = 13;              // Use pin 13 (builtin LED for testing)

boolean relayIsOn;                    // Keeps track of the relay state..

unsigned long timerStart;             // Time when we turned on the relay;
unsigned long timerDuration = 10000;  // 10000 = 10 seconds for testing. 3600000 = 1 hour.


void setup()
{
  Serial.begin(115200);

  pinMode(relayPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);

  turnOnRelay();
}

void loop()
{
  if (relayIsOn)
  {
    if (millis() - timerStart > timerDuration)  // Have we been running long enough?
    {
      Serial.println("Turning relay off");
      digitalWrite(relayPin, LOW);
      relayIsOn = false;
    }
  }
  else
  {
    if (digitalRead(buttonPin) == LOW)
    {
      turnOnRelay();
    }
  }
}

void turnOnRelay()
{
  Serial.println("Turning relay on");
  digitalWrite(relayPin, HIGH);
  relayIsOn = true;
  timerStart = millis();
}

Genius! Thank you. A lot of that makes sense but some of it doesn't so I'll use your example to try and learn some new functions.

I'll give that a go when I next get the chance and post the results here.

Should be able to verify with an old mechanical hours timer I have.

I've got a few things on the shelf that I have no idea where to start. Like a Powertip display from an old Gent Vigilon fire panel.

I'll post results when I can, thanks again!

Just let me know if there's anything in particular you don't understand.

Thank you. Like I said, I'm a super noob at this. I can do all the hardware stuff and probably build this all from logic gates, BJT's and such. But would love to learn more about just giving instructions to a micro and it does what I want.

Maybe just practice makes perfect.

Why do I need 'Serial.begin'? I thought that was just for sending data to a port?

That's really only for debugging in this instance. It allows you to write (subsequent Serial.println() statements) to the serial monitor... very useful tool to see what is going on. You don't need it in your final version.

Ah ok. So it can lead me to find what state it is in during a fault? Very clever

Exactly... invaluable when the code gets more complicated and isn't doing what you expect.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.