Problems with program freezing

hey first time posting, I've been playing with Ardruino for a couple years now latest project has been automating my round bale wrapper with and Ardruino Mega, 8 relay outputs, switch inputs, 1 hall effect sensor , program i wrote worked fine on the bench, then worked fine installed until the i started to run the old tractor we use for power on in (hydraulic and 12v electric) I'm using a cheap 12v to 5v buck converter with 2 1000uf capacitors to help smooth the voltage out, but it runs for a few minutes and then freezes (out put stays on and inputs do nothing) using a 4 digit 7 segment display to display current wrap count had an RF communication between a remote i was trying to use but disconnected and disabled code thinking it was the problem, the only things i can think is the problem is the solenoid valves I'm using but i installed diodes to mitigate spikes, and the alternator creating dirty power but battery should mitigate that, any help appreciated im willing to try just about anything at this point, though about second battery in the enclosure to prevent low voltage when solenoids are activated, but with the tractor sitting idle you can use the controls and run it and it probably wont freeze, its hit and miss and has gotten more frequent the more its used

@biga1216, your topic was moved to a more suitable location on the forum.

Can You supply more info about the relays? Usually relay coils draw too much current for an Arduino output to handle.
A wiring diagram could also be helpful.

Hi, @biga1216
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

hey first time posting,
I've been playing with Ardruino for a couple years now
latest project has been automating my round bale wrapper with and Ardruino Mega, 8 relay outputs, switch inputs, 1 hall effect sensor ,
program i wrote worked fine on the bench, then worked fine installed until the i started to run the old tractor we use for power on in (hydraulic and 12v electric)
I'm using a cheap 12v to 5v buck converter with 2 1000uf capacitors to help smooth the voltage out, but it runs for a few minutes and then freezes (out put stays on and inputs do nothing)
using a 4 digit 7 segment display to display
current wrap count had an RF communication between a remote i was trying to use but disconnected and disabled code thinking it was the problem, the only things i can think is the problem is the solenoid valves I'm using
but i installed diodes to mitigate spikes, and the alternator creating dirty power but battery should mitigate that,
any help appreciated im willing to try just about anything at this point,
though about second battery in the enclosure to prevent low voltage when solenoids are activated, but with the tractor sitting idle you can use the controls and run it and it probably wont freeze,
its hit and miss and has gotten more frequent the more its used

Sorry I had to edit your post into some sort of sectioning, this makes it easier to read and attract members who could help.
Can you post a circuit diagram please?
How long are your wires to the battery and the solenoids?
Is the Mega's power supply connected directly to the battery, via a fuse?
Are the solenoid valves power supply connected directly to the battery via a fuse?

Tom... :grinning: :+1: :coffee: :australia:

Thanks it was late and I wasn’t thinking about readability lol

I can post a diagram tonight

From battery to solenoid is about 20 feet

Same for the mega power supply I’m not using the on board I’m using an external power supply

the same wire feeds both solenoid and controller

Relays are on a driver board
Uses its own supply from the power

ELEGOO 8 Channel DC 5V Relay Module with Optocoupler Compatible with Arduino UNO R3 MEGA 2560 1280 DSP ARM PIC AVR STM32 Raspberry Pi https://www.amazon.com/dp/B01HCFJC0Y/ref=cm_sw_r_cp_api_glt_fabc_VWV8XD1E2W9JZYK2J3MV?_encoding=UTF8&psc=1

Hi,

Fine mate, you might need to have separate supply wires for the Mega, this would make sure the Mega power supply wires do not share the same current flow as the solenoids.
Also some bypass capacitors at the Mega power input.
Do you have back EMF protection diodes on each of the valve solenoids?

Tom... :grinning: :+1: :coffee: :australia:

Yeah I was thinking the same with the independent wires, but the wire is 12 awg (20 amps)
And the solenoids are only 3 amps

I have two 1000uf caps on board input I tried putting them before the power supply and after had 4 at one point