Power Control For Various Circuits in a Car

I apologize for the long post but bear with me please.

First off, I am new to Arduino but I did pick up one of the beginners sets and going through all the projects just to get a better understanding of how everything works before I start my project. I am not new to programming though I haven’t really used it in a while but I did know python and C++ pretty well. I will just have to shake off the cobwebs there.

The plan is to control a few accessories that I am adding to my Jeep and having it be a little smarter than just a bunch of regular switches, hence I decided to go with an Arduino. I guess just having switches and a few relays seemed too easy. Ha!
For the heavy lifting, I already have a fuse box that holds 10 fused circuits and 5 relays. I will need the Arduino to trigger those relays though which I don’t think will be a problem. Only three of the relays will be used for the time being and the other two will Aux 1 and Aux 2, in case I decide to add more things.

I will be adding a set of rear fog lights when bad weather hits (i.e. blizzard conditions) since jeep decided not include it as an option on the 2014s but they were available on the previous years. So I will just retrofit those. Since the bulbs have the two modes, dim and bright, I will have the dim setting come on with all of the regular lights and have them switch to the bright setting either when I turn on the rear fogs or have them turn on with the front fog lights. This is where the Arduino comes in and giving me the options of how I want those lights to behave.

I am also adding an LED light bar up front that will basically be either on or off without any real logic built into with the Arduino. This will be useful on some back roads that have little to no light. This part will be easy enough to do, so I am not worried about this one.

Currently, I have an Arduino UNO, Seeed Studio CAN-BUS Shield and a 4D Systems 3.2 inch touchscreen LCD. The plan is to use CAN-BUS data as opposed to tapping into various wiring for signals to figure out when various lights are on. Is an UNO enough to run a CAN-BUS shield, a touch-screen LCD and trigger five relays?

Since I will already be pulling data from the CAN-BUS, I also want to add the ability to pull and erase OBD2 codes if they come up. I am just worried that I won’t have enough memory on the UNO to upload such a big sketch and starting to lean towards using a Mega; having four native serial ports is a good bonus too.

I will probably be sending some data over the CAN-BUS as well since Jeep decided not to save last state for some things like ECO mode. So I would like to send the command to turn it off after the car starts but I don’t think that will be a big issue after the other CAN-BUS stuff is figured out. Once I get the prototype out of the way, I will have a custom PCB made for the sake of packaging and durability. I will also include a proper DC-DC power supply on the PCB.

So what are everyone’s thoughts? Am I crazy in my undertaking as a first Arduino project? Is an UNO enough for my project or do I need to step up to a Mega or a Due? I don’t plan on getting this done overnight but it is an ongoing project to work on during my free time.

Thanks for reading my wall of text!
Roman

Sounds like fun!

Remember that an Arduino can't drive a relay directly - it needs a MOSFET to supply the current required by the relay coil. (You can get really small relays that can be driven directly, but they're small!)

The UNO should be powerful enough. It really depends on how much stuff you're writing to the LCD screen. User-interface strings take up a relatively large amount of memory compared to 'logic' code that actually does stuff.

For the relays I will probably end up using an opto isolater to trigger a small relay or solid state relay to finally trigger the main 12 volt relays for the lights. I do have a sain-smart relay shield for the prototyping phase though.

As far the LCD, that was one of the reasons I went with the 4d Systems screen. It stores all of the textures and logic on the screen itself and it seems like I only need to pass small commands back and forth. Please correct me if I am wrong there.

Quick question for everyone. Has any used software serial with a 4d systems LCD? Their forums mentioned that the software serial library does not support interrupts but other libraries could. I am messing around with 4d calculator sample for now. I would like to do a software serial with RX on pin 1 and TX on pin 2. Any help here would be great. Code is attached.

calculator.ino (8.11 KB)

As pins 0&1 are used for the hardware serial port it is silly to use them for a software serial.

Main reason I think I would need a software serial is because, please correct me if I am wrong, the Seeed studio CAN-BUS shield uses pins 0&1 as well. The shield for the screen has jumpers to change the TX and RX pins to 2&3.

I might also be completely wrong here since I am extremely new to arduino.

You said:-

Roman2179:
I would like to do a software serial with RX on pin 1 and TX on pin 2.

Then

e shield for the screen has jumpers to change the TX and RX pins to 2&3.

This is not the same as what you said originally.

Sorry about that. That was a typo on my part. Pins 0&1 would used by the CAN- BUS shield then I would need to use pins 2&3 for the LCD with software serial.

Would it be best to just move to a mega and not worry about software serial altogether?

Would it be best to just move to a mega and not worry about software serial altogether?

If that is an option then yes that will make like a lot easier.

I ordered a mega, seems easier than messing with software serial.

In order to move power motor you need H-Bridge
This bridge uses 4 control lines (to move to all direction and stop motor)
But basically you can drive it in 3 or 2 lines
I did few projects, one of them you can see here:
http://www.electronics-freak.com/arduino-motor-pwm/
I will share also tomorrow my code for it

Also done one not Arduino for 3 phase power motor here
http://www.electronics-freak.com/3-phase-motor-control-segway-brush-less-motor-first-movie/
Thanks,
Roee

Simple explain about the - Hbridge
it has 4 mosfets connected like this

VCC_
------1 2-------
--motor--
------3 4-------
GND

VCC and GND is the motor power
and pins 1,2,3,4 are the control (which are the Mosfet GATE pins), the VCC is connected to DRAINS of 1,2 and GND is connected to SOURCE of mosfets 3,4

to move to one direction active pins 2,3 to the other active pins 1,4
if you active 1,2 or 3,4 the motor stops

in order to control speed active with PWM
Thanks,
Roee

I will only be triggering relays for various off road lights and a maybe a winch down the line. Regardless, it will all just be relays, no motors of any kind will be controlled by the arduino.

I can accomplish most of what I want with switches and a few relays but I want to be able to use some of the can-bus data to my advantage. It also prevents me from having to tap multiple wires for triggers for some 'automated' functions.

Thanks

Ok,
I have Put code example for Motor PWM
See here

http://www.electronics-freak.com/arduino-motor-pwm-code/

Note: since PWM is LOW frequency (500Hz or 1Khz) - there is coils magnetic noise.
It is recommended to work in higher frequencies (that the ear can't hear, above 15Khz)
Thanks,
Roee

That code might be useful for other projects but there will be no motors or PWM control for anything in this project. I will only be triggering relays.

roeebloch:
Ok,
I have Put code example for Motor PWM
See here

http://www.electronics-freak.com/arduino-motor-pwm-code/

Note: since PWM is LOW frequency (500Hz or 1Khz) - there is coils magnetic noise.
It is recommended to work in higher frequencies (that the ear can't hear, above 15Khz)
Thanks,
Roee

A good automotive-grade H-bridge chip is cheaper than a relay and once you've got it you'll think of lots of things to do with it. Dim the lights smoothly, make electric motors stop exactly where you want them to stop and so on. It does push you towards making a custom PCB however.

I predict that 5 years from now it will become difficult to obtain hobby-quality mechanical relays. Automotive relays will remain available for old cars and there's always industrial uses for apparently obsolete tech but just switching a light or motor will be done in solid state as a matter of course. "You mean you have to wait milliseconds for the contacts to move over to the other side of this little box? Weird!"

I think with the change over to a Mega, I won't be making a full new custom PCB as that is way over what I can accomplish at this point. Instead I think I will make a custom shield that has CAN-BUS, maybe a micro-sd card, maybe bluetooth, small relays to trigger the larger automotive relays and, finally, serial+power output for the LCD.

I figured that I could make a custom uno but the mega would definitely be outside my comfort area. I also want to include a dc-dc power circuit on the shield that will be able to work in a car without frying within the first couple of days.

Anyone have any good dc-dc power supply designs that will work well in a car? I have searched around for a while but no one seems to agree on any one design as the best one.

Thanks!

MorganS:
I predict that 5 years from now it will become difficult to obtain hobby-quality mechanical relays.

Want to bet $100.00 USD on that? I'm pretty sure I'd win that bet - because if it was going to happen, it would have happened already...

:smiley:

@Roman2179 - As a first project, it's pretty ambitious what you want to do, but not impossible if you already know your vehicle well from an electrical standpoint (or you have prior experience there). The fact that you are taking your time with the beginner projects and learning that end will help you tons for this project. Just break it down into sub-tasks, and everything should flow (mostly) smoothly.

Be aware, though, that an automobile is a very electrically noisy environment. To that end, you'll want to isolate the Arduino as much as possible from the vehicle's electrical system. For power, consider using a 1-2 amp 5 volt cigarette light switching regulator for power - most of them can be easily taken apart, and after a bit of modification, you can connect them to your 12 volt side and power the Arduino from the clean 5 volts. They are typically designed for powering/charging cell phones and such, so they already have all the needed circuitry to "clean" the various voltage spikes and other noise that's on a typical vehicle's electrical system.

Regarding the Mega - do your research here. Not all shields will work the same on a Mega as on an Uno, sometimes different pins need to be used, or other modifications will need to be made - so read everything from the manufacturer of the board (good manufacturers will note these differences, if any). Also note that - for any other things - some pins and functionality on the Mega may be different or missing from the Uno (you may not hit on any of this - but you need to be aware of it - for instance, one of the timers on the Uno isn't brought out to a header on the standard Mega - the pin exists on the chip, but a trace wasn't brought out - however, on some third-party Megas (notably ones from Seeedstudio) - all of the chip's pins are brought out to headers).

Finally - check that Sainsmart relay board - some of those boards used PNP high-side switching (so a LOW turns the relay ON) while others used NPN low-side switching (so a HIGH turns the relay on). Keep that in mind - as you may have to invert your logic depending on how your automotive relay switching compares to the relay module you are testing with (a good thing to do now, while you are in the planning/experimentation phase - define a global constant called INVERT_RELAY or something - then create a function: ie - setRelay(int relayNum, int state) - and check in that whether to invert the control signal (something like digitalWrite(pinNum, INVERT_RELAY ? !state : state); or something like that). That way, no matter what you do in testing, you can flip a flag and it will work right on the real thing (without having to change a mess of other statements).

Your project sounds similar to something I want to do on my VehiCROSS (once I get it back from the shop, and it cools down here in Phoenix). I want to add some various functionality (lights and such) - but I want to control the lights (overhead on a roof basket) from my Android phone and/or an Android tablet (likely "embedded" as a "nav system" on the VX - since it didn't come with one from the factory like that - unless you were lucky and got one from Japan - but then, it's right-hand drive, so I can't swap the dash out).

So - my plan is to take things wireless (we'll see if it works out) - use ESP8266 modules connected to Nano or Pro Mini Arduino controllers - and they would trigger the relays (standard Bosch auto relays) to control the lights. I would stuff each of these combos into IP66/67 rated project boxes, and mount them near the "point of need" - so all I would need to run to the box would be a single 12 volt line (of appropriate gauge to handle the total current draw - it will run to an aux fuse near the battery).

Doing this, the reasoning is multi-fold:

  1. By using only a single wire for power, it simplifies the wiring run on the vehicle - this is doubly necessary on this vehicle because I need to treat it as a potential collectible - so no drilling holes and running multiple wires all over the place (at least in areas that are visible to the "outside world"). Plus, it is going to be insanely difficult for me to get even this one line up to my roof basket in a clean way, and with minimal modding - I have a plan on a way to do it going up thru the rear spoiler - but I have to be EXTREMELY careful with any mods I do to body parts - because it isn't like I can just easily get another.

  2. Everything becomes wireless, and can be controlled by any Android device with the custom app I will need to develop to control it. All switches and other stuff become "virtual" at that point. This is important on the VehiCROSS - as there aren't many places that I can put switches without cutting/drilling into the dash (again - I can't do that, as I can't get replacements should the vehicle become a collectible and/or I need/want to restore it back to stock). There is really only one spot that I can put such switches, but I am limited in space there. Plus - going virtual opens up other possibilities...

  3. One wire means fewer things that can go wrong with connections and such - again, its all a part of simplifying things.

The potential downside might be that I won't be able to reliably communicate with the ESP8266 from inside the car (or outside of the car - for those modules inside the car) - due to the metal body. I will have to do a few tests to verify what will work and what won't.

I had thought about using some kind of communications bus (like CAN or RS422 or something similar) - but rejected a wired approach because I had already planned on adding a wifi backup camera to the vehicle (it needs one very, very badly - if there is one thing I hate about the vehicle, it's the lack of visibility to the rear). Going completely network controlled on these accessories just seems like the proper thing to do.

Good luck with your project!

:smiley: