Please Help New Guy

I am very new to the Arduino and may have bitten off more than I can chew.
I have an Arduino Uno with an I/O shield attached.
My project is a 12 volt inverter charger with a generator start feature that consists of a relay output the contacts are closed when the charger would like the generator to run and are open when the charger would like the generator to not run.
My plan is to connect that set of contacts to a input on the I/O shield. And use two relay outputs from the I/O shield to operate a wireless remote for my generator. The remote has 2 buttons a start and stop that need to be pressed for about 10 seconds to either start or stop the generator.
The code needs to monitor the state of the relay contacts on the charger and close the appropriate output on the I/O shield to either start or stop the generator.
The problem I having is the relay outputs on the charger are normally open then when call for generator to start they close and remain closed until it is time to stop.
I have not been able to find a way to stop my code from just continually activating one or the other outputs depending on state of input.
Any help would be great. This is where i am at

void setup()
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

pinMode(7, INPUT);
pinMode(6, INPUT);
pinMode(5, INPUT);
pinMode(4, INPUT);
pinMode(3, INPUT);
pinMode(2, INPUT);

void loop() {

int genStart = digitalRead(2);
if (genStart == LOW){
digitalWrite(8, HIGH);
if (genStart == HIGH){
digitalWrite(9, HIGH);
digitalWrite(9, LOW);


Well, I guess the used delay´s will terminate the needed realtime behaiviour of your sketch.
At least your sketch needs a time handler, based on the BWOD example to be found inside the IDE.

Time to read the forum guidelines, edit your post and fix the lack of code tags.

Your problem isn’t too hard, but it would help if you offer a block fiagram showing all your parts and labelled connections.

Don’t waste our time with a frizzy diagram… ink on paper or a simple drawing tool will be much more useful, and teach you a valuable skill.

The code needs to monitor the state of the relay contacts on the charger

Where does that happen ?

There is an example sketch in the IDE that I think will help you. It's called "state change detection" in the "digital" menu. Study that and ask any questions you need to. I realise you do not need to count anything, but that sketch demonstrates the important principal of how to not simply detect the state of an input but the changing of it's state.

Follow @lastchancename 's advice please.

I would not recommend following @paulpaulson 's advice, I think he is mistaken this time.

Each used delay() is burning CPU time, better to be used for other tasks.

As far as we know, there are no other tasks here.

Here, I think:

int genStart = digitalRead(2);

@trvsndrsn 's use of English is confusing and ambiguous.

At least to blink the LED_BUILTIN as heart beat indicator.

I thought that was monitoring the run state… where’s the start*stop functionality ?

It might help if all the i/o is named and commented.

The way I interpreted @trvsndrsn 's description, there is one input, which indicates demand for power from the charge controller. My guess is that the the charge controller contains a relay which it can use to switch on some external power source to recharge the battery. @trvsndrsn wants to use those relay contacts like a switch connected to an Arduino input. It concerns me that INPUT_PULLUP is not used and we don't have a schematic indicating if any external pull-up/down resistor is connected, so the input may be floating. There are two outputs, connected to relays. Those relay contacts activate two buttons on a remote control for a generator to start or stop the generator. @trvsndrsn said these buttons need to pressed for 10s, which seems like a long time, and the sketch simulates pressing them for only 0.5s.

I would like to follow you, but my chrystal ball is in the dishwashing machine at the moment :slight_smile:

I hope you checked the label on the bottom of the ball for the words "dishwasher safe". The cleaning chemicals could make the surface of the ball permanently cloudy!


pressing the start button turns the engine on and holds the starter on for as long as the button is pressed. pressing the stop button turns the engine off

#undef MyHW
#ifdef MyHW
const byte pinButStart = A1;
const byte pinButStop  = A2;

const byte pinRlyStart = 13;
const byte pinRlyEngOn = 12;

enum { ButOff = HIGH, ButOn = LOW };
enum { RlyOff = HIGH, RlyOn = LOW };

const byte pinButStart = 2;
const byte pinButStop  = 3;

const byte pinRlyStart = 8;
const byte pinRlyEngOn = 9;

enum { ButOff = HIGH, ButOn = LOW };
enum { RlyOff = LOW,  RlyOn = HIGH };

void setup()
    digitalWrite (pinRlyStart, RlyOff);
    digitalWrite (pinRlyEngOn, RlyOff);
    pinMode (pinRlyStart, OUTPUT);
    pinMode (pinRlyEngOn, OUTPUT);

    pinMode (pinButStart, INPUT_PULLUP);
    pinMode (pinButStop,  INPUT_PULLUP);

void loop() {
    if (ButOn == digitalRead (pinButStart))  {
        digitalWrite (pinRlyEngOn, RlyOn);
        digitalWrite (pinRlyStart, RlyOn);
        digitalWrite (pinRlyStart, RlyOff);

    if (ButOn == digitalRead (pinButStop))
        digitalWrite (pinRlyEngOn, RlyOff);

I have been trying to get the state change detection to work for weeks now. The problem is the input does not change state. Basically the input button is pushed and held.

I feel I need a second condition that would prevent the outputs from activating continuously. But with no other available input from any devices it would need to be code based.

maybe i misunderstood.

you'd like to press a button to both power the engine and power a starter motor. when the button is released, the starter is un-powered but the engine remains on

and when you press the stop button, you'd like the engine to be un-powered so that it stops

Actually I took apart the wireless remote used to start the generator and removed the microswitches from the circuit board and replaced with wires so that the relay outputs on the I/O shield can activate the start or stop on the remote

please post a schematic and/or block diagram of you project.

So I guess to simplify this I need if input pin 2 goes low then output pin 8 goes high for x amount of time then go low then ignore the input from input pin 2 (that is still being held low, this is the part i cant figure out) Then if input pin 2 goes high then output pin 9 goes high for x amount of time then go low then ignore the input from input pin 2 (that is now being held high). The code and wiring I have now works and everything starts and stops the way it should. The problem is the buttons on the remote are basically pressed every 2 seconds until the batteries are dead which renders the whole system useless.

so you saying when the start button is pressed, the starter relay needs to be held on for a specific period of time?

that since the button is remote, there's no indication that the button is being pressed and released