Custom Fighters - Custom Streetfighter Motorcycle Forum banner

DIY M-unit style electronics control box

17K views 15 replies 11 participants last post by  Linus 
#1 ·
Based on a few comments expressing interest on a write-up on my electronics processor build, I am providing a write-up of it here.

INTRODUCTION

In my last project (http://www.customfighters.com/forums/showthread.php?t=105370) I had decided to begin development of my own microprocessor controlled electronics box to replace the mess of relays, flashers, and other things that typically handle electronic control on a motorcycle, more or less like the 'M-unit.' Motogadget's M-unit looks like a really attractive package (I've never actually had my hands on one). It says it will handle over-current situations, you can adjust a variety of settings with an arduino app, and it has screw terminals where you simply plug-in switches and output wires to your devices. So for $370 it's probably not a bad deal. I, however, like tinkering, and had been looking for an excuse to learn Arduino and putting together a ground up circuit and board design around one.

The device I will go over below is my first version, built with few frills in order to simplify the first attempt. Advantages I see of this over the m-unit is that it is open source, so you can really take it as far as your imagination lets you. Arduino has tons of support for it, and the board I used was only $10, so this can be done economically if you can get the rest of the components cheaply. Arduino has many add-ons made for it, including Bluetooth, Wi-Fi, etc. Also, people have built EFI controllers, digital displays, and etc with them.

The design I put together is more or less a way to get 12v motorcycle ins and outs through the Arduino, with current switching capacity of up to 20-30 amps at 12v, and provisions to help prevent hooking things up backwards, and noise that may be introduced from the harsh motorcycle environment. Though this design utilizes only very basic electrical engineering ideas (pretty much the extent of my knowledge), and I will try and write this in a very accessible manner, you'd be well served to know Ohm's Law is and what a resistor, capacitor, diode, and other basic components do to save yourself frustration trying to follow along.

DESIGN

The design begins with the schematic:



Don't worry about not being able to read everything, I will post the source files below.

INPUTS:

On the left side we have ten copies of the same basic circuit. These are the inputs into the Arduino. They can either be 'ground switched' or have current applied to them (just depends on which way you face the diode, the schematic is setup for current to flow in but IIRC I actually flipped them for ground-switched on the model I made). Ground switched just means that you ground the inputs to indicate 'on.' This saves you from having to route a + supply to the switches. The resistor prevents too much current from flowing, the diode prevents flow in the undesired direction, and the capacitor filters noise over a certain frequency (e.g. RF interference).

OUTPUTS:

The seven copies of the same circuit on the right are the outputs. The Arduino puts out something like, 5v? This won't work for a 12v system, so the switched outputs need to be brought up to 12v. To do this, a transistor is used first to generate more flow capability for switching the larger MOSFETS (you don't really want to directly switch anything with the Arduino because is output flow is limited to something around 10-20 milliamps). The transistor output is then routed through the voltage divider (pairs of resistors in the upper right) which changes the lower voltage transistor output of ~6v to 12v in order to switch the 12v flowing through the MOSFETS that do all the heavy lifting. I used MOSFETS as opposed to mechanical relays because they are smaller, cheap-ish, and won't be destroyed by vibrations from the motorcycle as easily.

POWER SUPPLY:

Although the Arduino can technically be powered by 12-ish volts, I was concerned that the wobbly power supply coming from a motorcycle might cause issues. To get cleaner power to the Arduino I used a 5v regulator, diode (reverse current protection), fuse (over-current protection) and capacitor (to filter out AC, or to stabilize power, I forget now). 12v in to the pad hooked to this circuit turns on the arduino. Thats why it has a separate pad from the 3 pads that go into the MOSFETS. Also, I use 3 pads to get power to the MOSFETS so that all the current being switched by the MOSFETS is being spread over three wires. I couldn't use one big wire because the terminal that goes into the box has a maximum of like 30 amps per pin.

THE CIRCUIT BOARD:

With the circuit design sorted, everything just needs to be arranged on a PCB. My arrangement is below. We're simply seeing all the components represented on the schematic in scale accurate perspective, with traces in the copper board laid out to interconnect everything. The big blue areas surrounding everything else is the ground plane, which is essentially the equivalent of the chassis in a motorcycle or car. The big circle on the ground plane is where the system ground wire gets routed to the chassis of the motorcycle. The traces on the left are small because they are for inputs and don't need to carry much current. The big thick traces on the right are for the MOSFET because that's where the heavy current switching happens.



The board layout file (under 'FILES' at bottom) can be used to generate G-code to mill the traces out, and drill the holes. This can be sent out to a board making place (e.g. pcbway, oshpark) and they will do a nice job for you, or you can do it yourself and maybe do an alright job (I fall in the latter category). I milled and drilled the board out of FR4 with somewhere in the neighborhood of 2oz copper. This is a heavy copper layer, I used this to handle heavier current, but you could probably go thinner since that lowers the price dramatically at the board printing houses.

Here are pictures of it while I was testing the board:





The board was coated with liquid tin (hence the silver color). After I verified everything worked I mounted it into an aluminum box and hooked everything up to a 40-pin Deutsch connector. Since the outputs are not fused you need to fuse them externally (they could be fused within the box, on the board, however you want), so the outputs hit a fuse box after coming out of the Deutsch connector. Also, you'll want to reduce vibrations to the board by using some kind of rubber mounts so the board doesn't shake itself apart, get solder cracking problems, etc.

Here is a picture of the box mounted on my bike:





I also run an external USB that is mounted to a weatherproof usb jack on the bike for changing code without having to disconnect anything:



In the aluminum box I simply used a small usb cable into the Arduino Nano's usb socket with the other end spliced into the Deutsch connector. Not the most elegant solution but since it's only seldom utilized to program things I just took the easy way out.

The really handy thing about this box is that it is all connective via one 40-pin connector. I pull this connector and 4 bolts and the thing comes out. Further down the line I would like the size of the box to shrink considerably, but it's always harder to package things neat and tight the first go round.

ARDUINO CODE:

I did this code awhile ago and it's really outside the breadth of this write-up to go through Arduino code. The code is reasonably well annotated within, so it should be clear what does what. Like I said, I kept things basic to get the ball rolling, so besides simply turning things off and on, I implemented the flashing of the turn signals, and a brake dependent turn signal auto-turn off (if it has been over 8 seconds since the brake was last released the turn signals will turn off). Other than this, I will leave it up to the reader to figure out the code if they want to change things, add features, etc.

PROBLEMS WITH THIS DESIGN

Power blip at Arduino turn-on:

I never quite figured out why, but whenever the board turns on all outputs go high for a brief moment. I've heard from many different sources many possible reasons why, but nothing I did would fix the issue (code or hardware wise). A possible solution would be to flip the operation of the outputs so that the first transistors are negative switched and the Arduino outputs are always on by default (i.e. the 'off' position), and go to ground to indicate being 'on.' This, however, creates the problem of what to do when the whole unit turns off. The outputs would stay on since there is no power to the arduino and the outputs float to ground then. You would need to create a main switch for the 12v to MOSFET ins. I just deal with the brief on pulse when I turn on the bike. One big concern, however, is the blipping on of the starter motor at start-up. To address this, and also to prevent the starter motor from accidentally triggering when I'm riding, I wired the output from the control box to the starter relay through the starter switch and kickstand. So, the starter output is always hot when the Arduino is on, but the kickstand must be down AND the starter button must be depressed for the starter motor to turn on. With the addition of the clutch lever also being in the equation, this is how many stock bikes are wired.

Possible current leak through at MOSFETS:

At higher speeds -- maybe because of higher vibration or higher voltage -- I notice a little current bleeding through the MOSFET's on some LEDs on my dash setup. I only notice it at night, and when I'm really cruising, so I don't suspect it is much current at all. I have never had a full false trigger (e.g. headlight on or off when its not supposed to), so I've not chased this down. Could be wiring out of the box, or leak through the MOSFET itself. Something to be aware of.

Arduino TX and RX pins may need to be cut:

After mounting the Arduino to the board I made I couldn't sync up my laptop to program the board. I had the Arduino TX and RX pins simply connected to isolated pads, and I made sure they were electrically isolated from everything else. For whatever reason, it wasn't until I literally cut those pins so they weren't even going to isolated pads that I was able to sync to the Arduino again.

ADDITIONAL NOTES:

I am not an electrical engineer and this board has not undergone the high level of development that you'd expect from a commercial item. Some of my information above may be slightly to completely incorrect. So if, for example, a component looks backwards on the board layout, it may in fact be backwards and I flipped it when I stuffed the board. All this information was meant for me and sometimes I'm sloppy and correct things later as I remember.

Do not hook the board straight to the starter motor, you still have to use a starter relay or the MOSFET will fry. The starter relay can be powered by one of the control box outputs though.

CONCLUSION:

This is just the basic foundation to get your old motorcycle into the world of open source micro-processor control.
With this box you are able to control motorcycle components with code. This allows for easy manipulation and versatility. This version takes little advantage of this fact. Please do cooler stuff with this basic design! I was going to hook up a vibration sensor for alarm functionality. I am currently working on a bluetooth EEG interface so I can control this box with my brain signals (I work with bluetooth EEG as part of my day job). You could also integrate EFI, LCD control screen, whatever you want! Also, Infineon makes great 'PROFET high-side' switches for automotive applications that have all sorts of useful features packed in them. The are MOSFETS purpose built for the automotive and motorcycle world (they even have a motorcycle PROFET!).

FILES:

This zip file contains the Arduino code I'm using, and files for the board and schematic that need to be opened in a program called Eagle. I forget which particular Eagle files are necessary to open the project, so I just threw everything I had for this project in the folder. There is also a text file with the components needed and Digikey reference #'s.

https://ufile.io/xokiv
 
See less See more
7
#2 ·
Thanks for the writeup! I'm gonna have to spend a minute reading it all 5 times over.
 
#3 ·
Looks good man. Just a couple notes:

Startup power blip - you should be initializing your port register values before you set your port direction to output. I.e. PORTx = 0x00; DDRx = 0xFF;
then your transistors will be off when the ports get turned on.

Wondering why you biased the FETs for 1/2 VDS. You may not get full current that way, the FET will be dropping a few volts.

Bypass your processor power input with a .1uF cap, but since this is an Arduino it's probably done for you.

If you are intending on switching relays use a diode to suppress voltage spikes from the coil.
 
#7 ·
I forgot to add a parts list! Now a text file in the zip file linked with Digikey part #'s. Includes the Arduino and all the components on the schematic. I threw it in a cart and it was $53. Can probably save ~$10 on the Arduino by using a generic. I'm going to be making a revision soon and hopefully will order some boards from PCBway. After I do that I will be able to point to a board order, so you would just have to order the board from PCBway. Then all that would be left is soldering up the board and making the enclosure. Still have to get a terminal for the enclosure yourself. The one I used retails around $100 (I got it for free) so you'll have to figure that out still.

Thank you for your input SolidState!

"Startup power blip - you should be initializing your port register values before you set your port direction to output. I.e. PORTx = 0x00; DDRx = 0xFF;
then your transistors will be off when the ports get turned on."

I only speak Arduino when it comes to microprocessor code, but I believe I tried many forms of what you're talking about. It's been ~1 yr since I was troubleshooting the problem, but I recall thinking that a different bootloader was necessary because I couldn't affect the problem no matter what I did within the code.

"Wondering why you biased the FETs for 1/2 VDS. You may not get full current that way, the FET will be dropping a few volts."

Good point, prior to the next revision I'll check the range of voltage at the MOSFET gates to see where I'm at.

"Bypass your processor power input with a .1uF cap, but since this is an Arduino it's probably done for you."

Correct, done on the Arduino already.

"If you are intending on switching relays use a diode to suppress voltage spikes from the coil."

Thanks for this suggestion. Will put a diode inline with the relay output.
 
#15 ·
I used the transistors to minimize amperage draw on the arduino. I forget the total ma spec for arduinos, but if you have multiple outputs running at once you can easily start hitting the Arduinos limit. There may very well be suitable logic level MOSFETS out there that wouldn't draw too much ma, that is just the design that I came up with and that worked suitably for what I was trying to do.
 
#16 ·
Hello, I love what you´ve done in this Project! Sadly the download link to the .zip file is broken and I couldn't follow the text in detail.
Would it be possible to send me the .zip file you linked in the text? I am also working on a micro controller and your files could be the missing piece i'm looking for.
 
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top