Section control code help

Hi, I`m hoping some one code help me with some Arduino code adjustments.

I have a couple of sprayers running simple section control and it works very well. One of the control boxes is very simple and uses simple on off switches to control the sections. The other uses momentary switches that puts 12volts to the machines PCB and uses flip flop latching relays.
My issue Iam trying to get round is that I want to connect my relay board inline between the section control buttons and the machines PCB. I need the Arduino code to turn the relay on for 1 second and then off and stay off, I need it to do that for both turning the section on and off. Currently using the code #if defined (RELAY1_PIN) if (bitRead(relay,0)) digitalWrite(RELAY1_PIN , ON); else digitalWrite(RELAY1_PIN , OFF); #endif I have had a little play with the code with no joy making it work! But to be honest I have no clue what Iam doing with coding!.

Thanks in advance.

You don’t say what .ino you are using as base code?

But you would want something like:

digitalWrite(13, HIGH); // sets the digital pin 13 on
  delay(100);            // waits for a second, start at a low number and increase until you get satisfy switching
  digitalWrite(13, LOW);  // sets the digital pin 13 off

This would need to happen at both on & off points in the base code.
Change 13 for what ever is used in the code.

Please post the complete code you are using, than i can give you a better hint to solve the problem (get the required action.
Do you realy need a full second or will just an short impuls be sufficient?

Oops as @hagre noted, I copied/pasted that code snippet…changed 1000 to 100 but forgotten to change note text to match!!!..100 is 1/10 second.

Hello @muntieiow
I have done some codeing (It is not very clean an professional). It is compiling, and working as expected on my table, but i have not been using it in actual environment. Please try and give me feedback. You can adjust the the preset impulse length by adjusting the line 11

#define TIMED_LOOPS_FOR_IMPULSE 3 // adjust as required, example: 3 * 200ms => 600ms

USB_Relay_AGOpenGps_Forum_Request_V2.0.ino (15,4 KB)

Do not forget to “Invert Relays” in AgOpenGPS modul config if required.

It would be very desireable to get some feedback from the actual circuit to check if it is activated or not to prevent wrong settings of the “simulated pushbuttons” during flickering/fast changes.

best regards hagre

Thank you very much for the help. It works perfectly in simulation, I shall now try it on the machine.

Thanks again

it is a possible solution, but the arduino will stand still for 100ms. This I quite a lot of time!
better calculate the time to release the button: unsigned long releaseTime = 100 + millis();
and check if the time has passed if (millis() > releaseTime){ …}

just my 2 ct

@MTZ8302 you are correct, so i have rewritten the code, but just started to test it. All timings are now configurable and no time is wasted in a delay or so.

USB_Relay_AGOpenGps_Forum_Request_V2.1.ino (9,9 KB)

Looks good

Bug fix Version, now it is working! (with all timings adjustable)

What i discovered is that AGOpenGPS is not adjusting its lookahead for hydr. lowering according to the modul setting (it is always constant, in my test 4.2.02) and i don’t know if it is possible to adjust it at the moment.
USB_Relay_AGOpenGps_Forum_Request_V2.3.ino (10,0 KB)

@BrianTee_Admin Is the lookahead for hydr. lowering set according the modul setting?

The delay should be working - as you adjust time, the timing should change. Can check here in a bit.

It looks like the timing is adjusted, but the purple line is still in the same position/distance of the vehicle.

Now I updated the Machine_USB_4202_16pins_V3.2.ino (12,0 KB)
it is also avaliable in a pullrequest on Github the v4201 branch. (incl. serial connection with MEGA2560 correction in AGOpenGPS)

This new Arduino Mashine USB file with the posibility to select up to 16 Relays. (if compiled with MEGA2560)
It is possible to adjust all timings in the code without blocking.
Use of relays as simulated puchbuttons (as impulse) is selectable with
//#define OUTPUT_TO_RELAY_IS_IMPULSE //comment out if normal output is required

The purple line is look ahead of the lift, done in vehicle settings the other 2 lift time and lower time are set in arduino module form.