Advice needed on arduino circuit protection

Hi,

I'm looking for advice on how best to protect an Arduino in a system with motor and audio output. I've been trying to build a simple robot using the schematic attached to this post, which I've cobbled together from various sources around the net, I'm pretty much an electronics noob.

The short story is that the robot works fine for a while and then suffers some mysterious failure. In the first Arduino, it suddenly stopped communicating via USB and it stopped registering as a USB device on my computer. In the second, it suddenly stopped playing audio files from the SDCard.

What am I doing wrong and how do I stop frying any more poor innocent Arduinos?

Thanks,
Ivan Vuletich

Please resize your picture to around 1000 wide. Its too big to see it all.

Is the attached pdf easier to view?

CoffeeBot_schem.pdf (1.33 MB)

What type of MOSFETs are you using to drive the Motors? How far away are the motors from the arduino?

Motors are noisy, and can wreak havoc on sensitive digital electronics.

Not sure how you're distributing your 9v power source... but a 10uF electrolytic cap by the Arduino supply, and larger (100-1000uF) caps at the motors could help. Put one at the amp as well... 10-100uF.

Put some 100-200R resistors between D5/D6 and the transistor gates to prevent gate capacitance from damaging the output pins.

I have no idea what Part 2 is.. the itead thing. It looks like a wardrobe malfunction over the second pin from the bottom. (Or is that the top? It's upside down...)

Your SD module is 5v signal tolerant, yes?

The whole system runs off a 9V battery which is wired into the barrel jack of the Arduino. From there, a wire leads off to a small piece of perf board where the mosfets and the power lead of the audio amp is wired in to.

Part 2 is a HC-SR04 ultrasonic ranging module, the Fritzing part model I got off the net. Its wired directly into D7 & D8 pins as shown. The 5v pin is wired to another part of the same perf board & then into the Arduino 5v pin. The SD module is a SD card reader from DF Robot and is wired into 5v the same way.

Should the 10uF electrolytic cap be placed across the Arudino power input? I take it, that its there to soak up any AC spikes and let DC past, correct?

Also, should the cap to the amp be placed in series with the D9 pin to pass AC signal only?

Thanks for the advice from everyone, I'll give those tips a try.

Ivan Vuletich

The caps I referred to are bulk caps, for providing current in case of instantaneous demand -- and therefore, to keep large current spikes from having to traverse the PCB, stripboard, and wiring. They should be placed between V+ and ground near devices that use current.

Your 9v battery connects to the stripboard, and from there you have a barrel plug wired for the Arduino supply, right? Then put a 10uF cap between 9v + and ground where the barrel plug wire connects. Put another right where you feed power to the LM386, and one right next to each of the motors -- or a single one next to both motors, if the former is not possible, or if they're close enough to each other that separate caps makes no sense.

These are all effectively in parallel with each other, but by having them as close to the load as possible, they are able to supply current quickly on-demand, with less impedance (hopefully) than having to go through all the boards and wiring back to the battery. This tends to stabilize the power at every device, and make them less likely to suffer from power dips.

(Incidentally, having one in the audio path makes it an "AC coupling cap", or "DC blocker", since it blocks DC and permits the AC audio signal to pass. The LM386 provides much of this for you, so no need to add any of that beyond what the data sheet or your reference design calls for.)

I actually have the 9v battery wired into the barrel plug of the Arduino. Is this the wrong way to do things?

Not necessarily, I'm just missing how you get from the battery to your other 9v components if the battery connects directly to a barrel plug into the Arduino. Are you tapping off the Vin pin on the header or something?

Thats right, I'm tapping off the Vin header pin.

The mosfets are capacitive animals. Every time you switch it, you exceed (or reach) the current limitation of your ATmega. One solution is to put a MOSFET driver in between. You can also consider to put a 1K resistor series with the gate, if switching speed and loss is not a concern. Also put some TVS protection parallel with the motor, slightly bigger than the power supply voltage. Use separate wiring for the motors if possible, with star grounding and star power supply.

Much more viewable schematic.

Does the "SD card reader from DF Robot " have 5V to 3.3V signal level translators on it, as well as a 5V to 3.3V supply?

  1. your robot can only go forwards and turn. You want to use h-bridges on your motors, so the robot can also go backwards. If those are small motors, L293D h-bridges will work (600 mA max). Eg, adafruit.com motor shield. If large motors, then check pololu.com for h-bridge boards. H-bridges will also have more protection for your Arduino pins than bare mosfets.

  2. if that's the sort of 9V battery I think it is - ie, a little slug 2" long by 1" wide x 2/3" thick - it's too dinky to run your robot for very long. You need a battery with a lot of energy to run a robot.

CrossRoads:
Much more viewable schematic.

Does the "SD card reader from DF Robot " have 5V to 3.3V signal level translators on it, as well as a 5V to 3.3V supply?

I suppose it must do, as it only has a 5V power pin

oric_dan:

  1. your robot can only go forwards and turn. You want to use h-bridges on your motors, so the robot can also go backwards. If those are small motors, L293D h-bridges will work (600 mA max). Eg, adafruit.com motor shield. If large motors, then check pololu.com for h-bridge boards. H-bridges will also have more protection for your Arduino pins than bare mosfets.

  2. if that's the sort of 9V battery I think it is - ie, a little slug 2" long by 1" wide x 2/3" thick - it's too dinky to run your robot for very long. You need a battery with a lot of energy to run a robot.

  1. Correct. This is my first robot project, the design started life as the Coffeebot project from Vol. 34 of Make magazine and grew from there. The motors are little ones that came with a Tamiya double gearbox, but they seem to be up to the job.

The problem I see with the Adafruit motor shield is that it uses some of the pins I need for the SDcard reader. Even a custom H-bridge is a bit problematic as I've maxed out the digital I/O pins. But I just realised the other day that I could move the sonar and LED pins to the analog pins, thereby freeing up some pins for an H-bridge, future enhancement :).

So is having 100R current limiting resistors on the motor driving pins sufficient protection for the Arduino? Or is something more needed, aside from bigger caps across the motors.

  1. Yep, thats another lesson that I've learned the hard way, any recommendations on a good battery?

Thanks,
Ivan Vuletich

The Tamiya dual motor geartrain is a good motor for a first robot. Small h-bridge chips like the L293D and 754410 [drop in replacement] will handle those motors. However, the first thing that will happen is the robot will run into a corner and not be able to get out, so you really need a reverse.

If you look at the adafruit motor shield schematic, you only need 2 h-bridge channels and the board has 8 channels on 2 chips. Since it's DIY, you can leave out the U1 h-bridge chip, and pick up all the lines you need for SD [ie, SPI D13..D11, and D4]. Might have to cut one trace. I would use always a socket for the L293 chip with DIY.

There are also other shields around that would work.

Unfortunately, there does seem to be a lapse into idiocy by people who draw Arduino shield schematics. They rarely indicate which headers are the Arduino headers. Duh!

For batteries, I use NiMH AA-cells on all my robots. 2200-2500 mA-hr.

Also, just found this one,
http://robotbits.co.uk/arduino/shields/arduino-robot-shield/prod_21.html
This one I like especially well, because the 3-row male headers make connecting r/c servos and various sensors much much easier than with any standard boards in the Arduino world.

oric_dan:
The Tamiya dual motor geartrain is a good motor for a first robot. Small h-bridge chips like the L293D and 754410 [drop in replacement] will handle those motors. However, the first thing that will happen is the robot will run into a corner and not be able to get out, so you really need a reverse.

If you look at the adafruit motor shield schematic, you only need 2 h-bridge channels and the board has 8 channels on 2 chips. Since it's DIY, you can leave out the U1 h-bridge chip, and pick up all the lines you need for SD [ie, SPI D13..D11, and D4]. Might have to cut one trace. I would use always a socket for the L293 chip with DIY.

There are also other shields around that would work.
http://www.dfrobot.com/index.php?route=product/product&product_id=69#.Uks149K-p-5
http://www.dfrobot.com/index.php?route=product/product&product_id=59#.Uks19dK-p-4

Unfortunately, there does seem to be a lapse into idiocy by people who draw Arduino shield schematics. They rarely indicate which headers are the Arduino headers. Duh!

For batteries, I use NiMH AA-cells on all my robots. 2200-2500 mA-hr.

I like the look of those shields, especially now that I've learned some lessons the hard way =(. One thing that most of the doco on these types of shields say is to have an independent power supply for the shield. In the robot context does this mean that you need separate battery packs for the Arduino & shield or can you have 1 battery pack with the Arduino and motor shield wired in parallel?

Thanks,

NANDBlog:
The mosfets are capacitive animals. Every time you switch it, you exceed (or reach) the current limitation of your ATmega. One solution is to put a MOSFET driver in between. You can also consider to put a 1K resistor series with the gate, if switching speed and loss is not a concern. Also put some TVS protection parallel with the motor, slightly bigger than the power supply voltage. Use separate wiring for the motors if possible, with star grounding and star power supply.

Do you mean that because I'm powering the motors via the Vin pin that I'm exceeding the max current limit on the Arduino? What is the difference between putting a 1K resistor in series with the gate instead of 100R as some other posters have recommended? Is it a case of ensuring a lower limiting current from the PWM pins or is there more to it than that?
I'm beginning to think that optoisolators would be a good idea.

Also could you expand on your comment about separate wiring and star power supply, what do you mean here?

Thanks.

As an aside that might be useful here, you can do forward, stop and reverse using a single pin on your Arduino and a L293D. All you need is a simple circuit that uses 3 resistors and a cheap transistor. It relies on the fact that an I/O pin on an AVR has 3 states, High, Low and high-Z.

See the attached schematic. I came up with this a few years back when I needed to get 2 motors independently controlled with only 2 I/O pins.