Second Generation Nissan Xterra Forums banner

Power for Micro Controller

2K views 21 replies 4 participants last post by  KnightArmorX 
#1 ·
Does anyone here have experience using a micro controller to control accessories in an Xterra? If so, how did you feed clean, 5volt power to your controller?

This is not a CAN Bus project, but I do want to power the unit from the truck battery.
I am very new to electronics and struggle getting information from Arduino and Adafruit forums that are at my level. I’m not trying to learn electrical engineering. https://thenewx.org/forum/images/TheNewX_2015/smilies/tango_face_glasses.png I just need to know what component(s) to feed my battery power into to get good power to the controller. :tard:
HELP!?
 
#2 ·
Lots of info on this forum about powering various accessories.

I recommend doing a search for add a fuse or add a circuit. There’s a fuse box beside the glove box. You can get power there. It’s going to be 12v so you’ll need to step it down to 5v. There a lot of options for that as well. Amazon search for 12v to USB will get you started.


Sent from my iPhone using Tapatalk
 
#3 ·
Thanks, @eighty, I did see the different converters to power accessories and charge phones. It looks like those will make the voltage conversion that I need. Will they provide clean enough power for the micro controller?

The micro controller forums keep talking about individual components and board wiring configurations. (diodes, caps transistors, parrallel, series,...) It makes my head spin. I will eventually get to the point where I can understand what they are saying, but I want to build a project, not get an EE degree.

What I am hoping to find is a "module" or breakout board to run the power through to get clean, stable power to the controller. I am leary of just doing experimentation on my vehicle, because I don't have a lot of aftermarket electronics running in it that could affect the power in my truck.
 
#4 ·
I have no idea man. If I understand correctly, we get the power directly off the battery and then alternator charges the battery so...maybe? According to the spec, USB should be 5v constant and 2amps (or so) so if you look at something like this https://www.amazon.com/Blue-Sea-Sys...572532&sr=8-1-spons&keywords=12v+to+usb&psc=1 you should be golden.

I'm a software guy, I'm not an EE by any stretch so you gotta do some learning. I'm tinkering with some 12v/battery stuff and I find that you don't really have to build anything from scratch (at least at my level). It's like legos, some structure you can buy preassembled, at a higher cost I guess.

What are your plans with an arduino?
 
#5 ·
A lot of it depends on specifically what you are powering/controlling, some of it is more sensitive to voltage fluctuations than others. If it isn't that bad, an LM7805 rated to at least 15V input (voltage fluxuates in a vehicle, it isn't constant 12V) with a small filtering capacitor is usually one of the cheapest options. You do also want to make sure you know how much amperage the devices will pull, as you can burn out the power circuit if it isn't rated high enough.

https://www.adafruit.com/product/2164 The ones Adafruit sells are up to 35V input, should run an Arduino just fine. As mentioned, it depends on what the Arduino is controlling, and where that gets its power from as to whether this will have the current required.
 
#6 ·
@eighty @meisanerd Thanks guys.

I definitely have some learning to do. I really wanted it to be a little more like Leggos than it actually is. :surprise:
I am having to draw on the little bit of hands-on knowledge that I have in electrical and in programming. This project is a pretty good stretch for me, but I really love to learn.

It will be a wirelesss lighting controller. I have this issue with cutting holes in my vehicles if I can avoid it. Since I couldn’t figure out a way to mount a switch bank that looked the way I wanted and was expandable, I decided to go wireless.

The Arduino should use very little current. It only has to:
* Power a Bluetooth Low Energy breakout board.
* Send digital High/Low to up to 8 channels on the low power side of an optoisolated relay board.

The relay switching power will be a separate 12VDC feed, and of course the main power will come from the battery through a fused power distribution block.

New skills:
* Arduino micro controller programming
* Automotive accessory wiring design
* Electronics specification (I am starting from ZERO on the ones from here down.)
* Wireless communication
* App writing
 
#7 ·
Is the BLE breakout board one designed for an Arduino, that uses the existing pins? I would check the specs on it to be sure, but it should all be fine to run it off an LM7805 then. The optoisolated relay board is a good idea, it's something that I don't see too many amateurs using, but does well for keeping your microcontroller from burning itself out (a lot of them try to drive the relays directly, not realizing that the Arduino pins only really support like 40mA out).

Are you doing a custom mobile app for it? Android or iOS?

Will the microcontroller be inside the vehicle or outside? This makes a bit of a difference for weatherproofing.

Overall, other than the BLE stuff (can be annoying depending on phone support, it is getting better though), this looks like a good entry-midlevel project to learn on. Circuit shouldn't be too overly complicated and the code should be straight-forward enough to teach you the concepts.
 
#8 ·
@meisanerd So far it hasn't been too difficult.

I have already written basic code to test the relays. Pretty simple stuff. The switching code will get somewhat more complicated when I add a check for ignition switch "On", timer to force shutdown after ignition switch is turned off, option to turn lights on with ignition off with a timer to turn them back off. I have contemplated a low voltage check to shut them down and protect the battery.

I will be writing a custom app for my iPhone. If I stay focused on basic function and get it up and running, it shouldn't be too difficult. (I hope.)

The BLE breakout is the Adafruit Bluefruit LE SPI Friend - Bluetooth Low Energy (BLE). It is designed for Arduino compatibles. I have decided to use the Adafruit Metro Mini 328 - Arduino-Compatible - 5V 16MHz for the microcontroller. It is really small.
I will check these against the LM7805.

Last night I soldered the headers on the Metro Mini and the BLE breakout and tested them. Everything is working. I am halfway through the tutorials and example sketches. I should finish up those tonight and begin writing code so I can learn to use button pushes on the Adafruit Bluetooth test app. I hope to be ready to start learning how to build the iPhone app this weekend.

I will put all of the electronics inside of the cabin. From reading a lot of threads on this sight, I should be able to locate everything to the left of the glove box. I have watched a couple of YouTube videos of car guys building standard relay boards, so I have a pretty good idea how to assemble my components. When I get closer to assembling everything, I will find the exact spot so I will know if I need to make 2 assemblies or stuff everything onto 1. The only physical components of the control system that I don't have yet are the 12v to 5v converter for the microcontroller and the 12v to 12v conditioner for the switching power.

Thanks for your help and interest.
 
#10 ·
That's how I have it wired now. That is the same tutorial I am walking through.

The 12v to 5v converter is to make sure the power going into the microcontroller is clean and stable. All of the Adafruit and Arduino guys say that automobile power is too noisy for the microcontrollers and will cause errors. I don't have enough knowledge or experience to make a judgment, so I'll put a step-down converter in place to make sure I am covered.
 
#13 · (Edited)
This fits the bill for you https://www.amazon.com/DROK-Adjusta...7764186&sr=8-28&keywords=drok+dc+dc+converter I used this to step down a 36v source to 6.5VDC to the Vin on an Arduino Mega 2560 clone, this creates a high enough voltage for the board to then iron out to 5VDC using its own integrated voltage regulator. If you are running relays as it looks like you intend to, there are prebuilt modules that require very little current to trigger and will handle about 10A. If you need more, I would suggest using an opto-isolator or solid state relay to do the switching versus mechanical reed relay. Check out Opto 22 for nice, affordable solid state relays. For lower currents, such as LED lighting, etc, a TIP102 NPN darlington transistor, 1K ohm resistor and 1N4004 diode can go a long way to switch inductive loads up to about 8A peak with proper heat sinks installed.

I would suggest if you are going to use a microcontroller in the rig, use something that you can solder onto like the Arduino compatible Teensy 3.x series, 3.6 has real time clock built in, 3.2 has space to solder in a battery and 32khz crystal to provide real time clock functions. If you want something with more outputs, I would suggest the Meduino 2560 (which can be found on ebay for under $15) this is Arduino Mega 2560 compatible, has 8k RAM and 256KB storage. The Arduino Uno has only 2K RAM, and only a handful of pins free after a touchscreen is attached. The above DC-DC converter does a decent job of providing clean DC into the board.

https://www.amazon.com/SainSmart-iM...eywords=8+channel+remote+control+arduino&th=1
 
#14 ·
Thanks, @LNXPenguin. That should fit the bill.
I have already purchased most of the parts.:
* Optoisolated relay board
* Adafruit Metro Mini microcontroller
* Adafruit Bluefruit LE SPI Freind
I think these will work. I’m not planning to build a touchscreen for this project. I considered it, but decided to back away from that much complexity. I plan to use my iPhon for now.
 
#16 ·
Unfortunately, I haven't worked with Bluetooth and Arduino yet. I have worked on my fair share of Arduino projects in the past, and have had to get creative powering things. If you notice you have too much "ripple" even with that DC-DC converter, you can simply add a 1000 uf, 16v capacitor across the Vin and ground, making sure to match polarity of course, to smooth out the DC. I know your motivation for this was to create a control panel for lighting to give you more flexibility with switch locations as the conventional rocker switches do take up a lot of real-estate, which the front panels are greatly lacking.

I can suggest taking into account having a fallback localized controller for the systems. I know you have plans to use your phone to control the whole setup via Bluetooth, but remember, phones can get lost, break, batteries can die, etc. It's a nice additional feature to have for sure, and I like the way you are approaching the problem. There are touch screen displays, about 3.5" in size, or roughly 3 rocker switches in width, that are easily to natively wire to an arduino and the libraries aren't too hard to use and program with. It takes about 12 I/O lines I would suggest SPI bus for the easiest wiring. You will need to keep two of the analog pins free for the touch screen portion to work, but the remainder of pins are fairly flexible, I believe most Arduinos and clones have a 6 pin ICSP port that can handle supplying voltage, ground, MISO, MOSI, clock and reset signals to the device.

In case phone is out of commission, having that backup interface allows you to still use the features that you may or may not depend on, but they will still be an option. The phone can act as a backup in case the screen on the local controls get damaged, this ensures you a bit of a failsafe. I am sure you will see many people mention fail safe designs in many threads here, it is far better to have a solution be over-egnineered and never need some of the features than having something barely meet your needs and fail at the worst possible moment, experience has been a cruel, but fair teacher. Just my $0.02 cents.
 
#17 ·
Great advice, @LNXPenguin.
My backup plan has 2 layers. (1) A small, wired remote with a series of buttons to toggle the inputs HIGH/LOW. I’ll keep it tucked away out of sight. (2) Repurpose a retired phone as a permanent resident in the Xterra, and have the app on it and my active phone.

I really like the idea of a wired touch screen. If I don’t have a breakthrough with the Bluetooth LE (BLE) programming soon, I will probably switch gears completely and use a wired touchscreen as the primary interface. That option has cool factor also.

This will get the system running, and I can test the suitability of my optoisolated relay board.
This will also buy me some time to figure out the BLE communication.

This is a really beneficial conversation.
I think I will go ahead and order the touchscreen and related requirements just in case. That will be fun to play with anyway.
 
#18 ·
Yah, BLE is fun... I haven't done any iOS dev using it, but making it work on Android was entertaining, in a not-very-actually-entertaining sort of way... There is a lot of trial-and-error involved, matching up device ids and capabilities to get the access you want. Once you have it connecting, though, the actual signalling (ie: turn on light 1) was pretty straight-forward.
 
#19 ·
Hey, @meisanerd. I'm glad you're still with us.

I am having trouble finding some example code to use as a starting point. All of the code that I have been using from the example sketches is just talking back and forth from the phone app through the BLE & microcontroller to the computer Serial Monitor. For some reason, this isn't helping me understand how to get the microcontroller to take "On/Off" instructions and use them to switch the lights.

Maybe a couple of shots of Jose to go with my Miller Lite's will get my mind to relax enough to see it.
 
#20 ·
Without seeing which sketches you are looking at specifically, I can only guess, but chances are there is somewhere that it is doing a write to the serial for the computer, you would just have to replace that code with logic to determine what you are doing with the value being read. If you can get the example sketch working with your phone and computer, you are probably 90% of the way there as far as comms go, as the last 10% is just reading the value on the arduino instead of forwarding it to the computer, and then determining what to do with it. You could probably even get away with something as simple as sending a byte of data from the phone, and parsing it into the bits to know what to do (ie: first 7 defines switch id, last one is either 0 or 1 for off or on). The other thing to consider is monitoring, so the app on your phone knows if it worked or not.
 
#21 ·
@meisanerd
You summed up exactly what I have been thinking. Now I just have to find example code that is in the ballpark of what I am trying to do. I will have to take another swing at looking for some code this weekend.

I am planning to put in a few mods this weekend. These will be my first physical modifications. Hopefully turning wrenches can take my mind off of the coding issues for a little while.
 
#22 ·
Progress

@meisanerd @LNXPenguin

I have had several distractions lately, but I finally made progress on the Bluetooth LE programming. I managed to find the example Arduino code that works with the Adafruit BLE test app for push button controls. I studied the code and found what applied to my project and deleted all of the non-essential functions and declarations. This made it much clearer. This cut the length of the code in half. I was then able to figure out how to insert code that drives the IO pins to trigger the relays.

I can now toggle the IO's ON and OFF with my phone!!!:grin:

In theory, I can install my hardware and use this test app to control my lights. Since that app is too cumbersome to be practical, I am going to create my own app so I can streamline it and make it very easy to use.

My next step is to go through the XCode Tutorials and build my first, simple iOS app. Hopefully, I can jump directly from that canned tutorial to modifying the open-source code of the Adafruit BLE test app to fit my project. (much like I did with the Arduino code)

So, it looks like I am still on track for having an iOS app-controlled lighting system for my truck.

The parts for the backup controller are en route. I am researching some integration mysteries right now. I will post questions soon if the answers don't materialize.
 
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