switched 12v+ to separate momentary on & off 12v+ pulses

Can someone help me with a sketch for the arduino to monitor an existing switched 12v+ signal
& output separate momentary on & off pulses, whilst consuming minimal to no power in the off state.

Also would like to use the same arduino for a 12v low battery cut out EG.
Using Analog 1 to monitor 12v battery level through some sort of voltage divider?
Or buy cheap voltage monitor with separate LEDs for each voltage?
Then join an optocoupler between each LED & empty Analog inputs?
When battery is above at or below a set level the Digital outputs 1&2 act as per above
(separate momentary on & off pulses)

EG2. Sketch for the arduino
Analog 0 is held high by 10k resistor to 5v+ (switched 12v+ in the off state).
When Analog 0 is held Low via relay contacts to ground (switched 12v+ in the on state),
this causes Digital 3 to Pulse for 500 milliseconds.
When the relay contacts to ground are disconnected (switched 12v+ in the off state),
this causes Digital 4 to Pulse for 500 milliseconds.
And Analog 0 is again held high by 10k resistor to 5v+.

In the attached image You can see a momentary SPDT ON-OFF-ON switch,
I would like to replace this switch with a circuit triggered from a switched 12v+ input,
that will output a control signal for the (BRN) & (ORG) wires.
As well as include a low voltage cutout.

Skill level.
I think I can handle the hardware side.(manliy thanks to other posts I’ve read)
The code side, I have built a few arduino projects follwing tutorials & adjusted the code to my needs.
But never somthing from scratch.


This is not really a get free code place but hey,

Is it possible that the switching on and off is happening within the given 500ms?

If not than you could try something like:

//define what is going to be used
#define Analog_0 A0
#define Digital_3 3
#define Digital_4 4

void setup()
  //inputs and outputs
  pinMode(Analog_0, INPUT);
  pinMode(Digital_3, OUTPUT);
  pinMode(Digital_4, OUTPUT);  

//Use this so the switching can only happen once every switching state
boolean Dig_3_Allowed;
boolean Dig_4_Allowed;

void loop()
  if (digitalRead(Analog_0) == LOW)
    Dig_4_Allowed = true;
    if (Dig_3_Allowed == true)
      Dig_3_Allowed = false;
      digitalWrite(Digital_3, HIGH);
      digitalWrite(Digital_3, LOW);
  if (digitalRead(Analog_0) == HIGH)
    Dig_3_Allowed = true;
    if (Dig_4_Allowed == true)
      digitalWrite(Digital_4, HIGH);
      digitalWrite(Digital_4, LOW);

I don't have anything here for arduino so very sorry if this fails (I'm not a c++ guru) but i think i would start with this.


did it work out?

Thanks for your quick reply
At a glance that code seems a great place to start if not exactly what I need.
I should have been more specific in my question, I was looking for any help/guidance as to the whole project.
I did however make a mistake with the pins & their uses.

list of the pins & their uses:
Analog 0 = Input from Battery to be monitored
Digital 5 = Normally held High, then pull Low when 12v+ is applied
Digital 4 = Pulsed Output to apply 12v+ to Brown wire
Digital 3 = Pulsed Output to apply 12v+ to Orange wire

When digital 5 goes low, digital 4 pulses high for 500 milliseconds
When digital 5 returns high, digital 3 pulses high for 500 milliseconds

Analog 0 constantly monitors 12v battery level through voltage divider
When battery is above at or below a set level the Digital outputs 3&4 act as per above
(separate momentary on & off pulses)

I’ve attached my idea of how I hope it will work???
Unsure though, would D4 (5v1 Zener Diode) act fine as over voltage protection?

I found this 12v lead acid battery cutoff sketch but how would I go about incorporating this into the code you’ve posted?

Again thanks for your help.

Arduino Constant - Momentary #2.bmp (852 KB)

sorry i don't have a lot of time these days...

But try and program something and ask for help.

Look into the blink without delay example, you will need it