Arduino cutting out

I have successfully constructed a DC generator for charging a 24v battery bank. I am using an Arduino uno to control the throttle using a servo. It works well but the arduino just randomly cuts out.

Connected between A0 and ground is the voltage sensor which is just a voltage divider consisting of a 10K resistor and a 5K potentiometer for calibration. If 32v goes in 5v comes out to the ADC. My batteries never go above 32v.

I am powering the arduino off a 3s lipo battery at the moment and the servo is on its own separate buck converter which is attached to the same battery.

I am using the servo example and only changed one line where the ADC is mapped to the servo.

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 784, 1000, 0, 180); // scale it to use it with the servo (value between 0 and 180)884 954
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

What exactly do you mean by "the arduino just randomly cuts out"

If the code you posted is the complete code it would almost not be noticeable if it restarted - I guess the servo would briefly go to some unwanted position.

How often does the cut-out happen? Are we talking minutes or hours? Or seconds?

Can you make a pencil drawing showing how everything is connected and post a photo of the drawing?

A photo of the complete machine would also be useful. Maybe there is some interference from the generator circuit.

...R

Hi, This sounds like "Electromagnetic Interference".

As Robin points out, we don't really know what you have without a diagram.

First Pass: WHERE is Ground? You should probably have a Single Common Ground Point. That would be the negative side of your 24V bank. IS that connected to the motor-generator frame? What is the Arduino Ground connected to? How?

I'm working on a page about this whole subject. Not Ready For Prime Time bit it might be helpful: HERE

Let us know what you find out..

Good start Terry. +1

I wish new people would create a reasonable name. At least then they would give an impression they might stay around and maybe help out in the future once they become proficient. :( .

By randomly cutting out I mean the servo just stops and I have to press the reset button. The LED on the board marked L also comes on and just flickers. All the grounds are common. I think there may be interference coming from an inverter which shares the battery bank. I will do more testing.

Any time there is a rough charging system you need to spend a great deal of time and effort to decouple your electronics.

http://www.murata.com/~/media/webrenewal/support/library/catalog/products/emc/emifil/c39e.ashx

https://forum.arduino.cc/index.php?action=dlattach;topic=367210.0;attach=148008

https://www.maximintegrated.com/en/app-notes/index.mvp/id/4645

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.337.8981&rep=rep1&type=pdf

You need to look at adding the items mentioned in the above links. Suppression diodes, decoupling capacitors, ferrites and supply inductors at appropriate locations. Watch out for ground loops, power cables should be in a star configuration and power your electronic from separate sources. Enclose electronics to gain from 'faraday shielding'.

.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

How is your servo/throttle supposed to control the speed with respect to battery voltage? How or what is your DC generator constructed, brushed or non brush type. Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)

If this is a petrol generator you have to be careful about the massive interference from the ignition system of any cheap petrol engine (ideally all sparkplug leads would be coax these days, but the old and frankly awful unshielded plug leads are commonplace).

The minimum you should consider is metal boxes for all the electronics, shielded cables for everything.

I have now fixed the issue. I simply uploaded the same program to an arduino nano and it has not cut out once. Exact same circuit was used. May be some fault with the UNO board.

Here is the work in progress setup now working nicely. I am from Fife in Scotland, so you won't really know what I'm saying but the video shows everything. https://www.youtube.com/watch?v=sJ4znw8CWpg

Hi, Just watched the video, before you do anymore work, get your wiring tidied up. The rats nest you have will if not now but in future cause you a lot of trouble.

Keep signal wires away from power wires, use shielded cable where input signals are small.

BUT please before you have a fire, get your wiring sorted, your high voltage and low voltage wires separated and LABELED.

Scenario, you get an electric shock and because of the rats nest no-one can get SAFELY near you to help you.

Do you have the proper clearance and fireproof material around the exhaust pipe through the wooden wall boards?

Does your arduino actually work out how much power is being produced by your generator? Just giving it more throttle to keep battery volts up is a very bad idea. How do you know if you are overloading your generator?

Is you "generator" not the motor, a permanent mag type or a field wound type?

You talk about a heck of a lot of current, and a current shunt that gets hot. Why.

Sorry but I have unfortunately come across installations like yours, and most lead to tears. Are you supplying inverter mains power to your house, or if I hear you right in another video "a grid tie" connection? If so does your insurance company know?

In fact in Australia we have regulations for home power and grid tie systems.

Tom... :)

True, a tidy up is badly needed. The whole setup is outside in a shed and provides DC power for charging an electric bike or powering a 3Kw pure sine inverter. I also have 1200w of solar panels on the shed. The exhaust is so oversized that nearly all the heat is removed before it exits the shed. I can keep my hand on the pipe outside and it is only warm. Increasing the throttle as load increases makes perfect sense as that is how inverter generators work to save fuel. I am using a 7Kw motor as a starter motor and generator. It barely gets warm. Do you know how current shunts work? They create a voltage drop. This voltage drop must create heat.

Hi,

Increasing the throttle as load increases makes perfect sense as that is how inverter generators work to save fuel.

But they also monitor electrical power out so as not to overload the generator.

Do you have field control on your generator? (That is how generators also work to save fuel, run the motor at its most efficient and control the field)

Tom.... :)

Current shunts get warm, not hot.

No field control is needed here. There is no way the engine could overload this generator. The system works by monitoring battery voltage and increases power as the voltage drops. It will be more efficient than a standard 240v generator, plus it runs on propane so less emissions. The motor outputs 3 phase which goes through a rectifier. The current shunt and meter were only put in for testing and due to the design of the meter, it will get hot when running at full current as the meter is powered off the shunt. I will be wiring it directly to the battery with thick cooker cable and it's own circuit breaker.