Adventures with an Arduino

#1
For a while I'd been toying with the idea of integrating an Arduino into a vehicle. With the COVID19 crisis providing me with tons of free time I opted to start plugging wires and code into things to see if I could let the smoke out of them. As I mess with interesting vehicle related Arduino projects I'll post them here.

First an introduction into what an Arduino is in case you're wondering.

Arduino is an open source electronics platform. The Arduino boards all conform to a standard set of instructions, and can accept input signals, do things with those signals and then generate some sort of output. Any example would be using a light sensor to detect when it's dark outside and then turning on a light. Arduino boards are used by a wide variety of folks for different purposes. Everything from art installations to complex scientific instruments have been created using Arduino boards as the "brains" of the operation.

I'm using an Elegoo Mega2560 for my projects. I went with this board over a standard Arduino for a few reasons, but mostly because it offered additional digital input/output pins allowing me to plug in more stuff at once.

1588958098999.png

Visiting www.arduino.cc gets you the IDE for writing code for the Arduino. That and a USB cable are all you need to get started, although without any external input or output devices there's not a whole lot you can do. Now, on to the projects.
 

richard310

Adventurist
Moderator
Author
#2
Arduino's open tons of options that a lot of people don't realize. We've utilized them with photolight sensors, vibration sensors, programming LED lighting sequencing and coloration, servo programming, etc.

Once you wrap your head around the basics of programming and understand the language, it's not too difficult to understand. I tried at one point in time, but at my work place, we just hire someone to do it now lol.

Looking forward to seeing what you come up with.
 
#3
Project 1: Touchscreen Controlled Relays

I trade vehicles a lot. It's a bit of an addiction. In most cases I've modified those vehicles, especially electrically (see an example here) and when the vehicle goes to it's new home hopefully the new owner makes use of those additions. It would probably be smarter of me to make a modular system that could integrate into any vehicle thus allowing me to move it as I trade. (As a side note @Scott B. I fully intend to keep the F250 for a while).

Here's the parts, besides the Arduino, I'm using for this project:

Nextion 3.2" Enhanced Touchscreen LCD
8 Channel Relay Board
Assorted Jumper Wires

Here's the wiring diagram:

nextionwire.jpg

This is the layout for how I'm setting it up to test and develop. Once it gets put in an enclosure and mounted in a vehicle the power layout might change a bit.

It looks like a rats nest of wires, but it's not that bad.

Arduino 5V - Relay Board VCC
Arduino Pin 0 - Nextion TX
Arduino Pin 1 - Nextion RX
Arduino Pin 2 - Relay IN1
Arduino Pin 3 - Relay IN2
Arduino Pin 4 - Relay IN3
Arduino Pin 5 - Relay IN4
Arduino Pin 6 - Relay IN5
Arduino Pin 7 - Relay IN6
Arduino Pin 8 - Relay IN7
Arduino Pin 9 - Relay IN8

Some things to note:

1. The relays on the board are separated from the logic circuitry by opto-isolators (also called optocouplers). These little devices allow the Arduino to be completed separated from the high voltage side of the relay board. The output pins on the Arduino operate at up to 5V, so if 12V were to suddenly come back in somehow it would probably let the smoke out of the board.

Connecting VCC on the relay board to the 5V out on the Arduino board allows you to power the opto-isolators. Removing the jumper on the lower left part of the relay board and connecting JD-VCC and GND to a totally separate 5V source allows for the relay coils to be powered and not have anything to do with the Arduino at all, electrically speaking. This way if something happened with an accessory that's attached to a relay (some sort of short in an LED lightbar for example) and that power came back through the relay the worst that's going to happen is the relay itself might be damaged. The rest of the board is electronically isolated completely from that circuit.

The opto-isolators act as a switch between the two sides of these circuits using light instead of a physical connection.

2. When uploading code to the Arduino you should disconnect the RX/TX wires from pin 0 and 1 on the Arduino that are running to the RX/TX pins on the Nextion display. This prevents any conflicts between the two devices as the code is updated in the Arduino.

With the physical connections completed it's time to make everything work.

Step 1 is to create the GUI on for the LCD since it's going to send instructions to the Arduino. To do this I used the Nextion Editor Software available on their website. This gives you a WYSIWYG editor to create layouts and elements to interact with. The beauty of the Nextion LCD's is that they have their own processor and memory built in to handle all of this. The Arduino doesn't have to do any heavy lifting to create this GUI. There are several web tutorials on using the Nextion editor, and ultimately I came up with this:

editor.jpg

It's a basic screen with 8 buttons to control the relays. I used Photoshop to create the layout and then imported it into the Nextion editor. Inverting the button images and using the Image Clipping option in the editor allows you to generate an effect of the button being pressed as you touch the LCD screen:

1588961284766.png

The Ford logo is setup as a hotspot. There's no button effect, but touching that area moves you to a "Setup Screen" where you can change the brightness of the backlight on the display:

1588961369344.png

Pushing a button on the main screen causes the LCD processor to execute the following instruction: printh 23 02 54 01

This sends that data (23 02 54 01) to the Arduino.

On the Arduino side it's running a loop listening for instructions to come over, and when it receives them it turns on the proper relay. I'm using the EasyNextion Library available through the Arduino IDE to do this. The library has a command defined that listens for data and then executes instructions based on that.

trigger1() listens for 23 02 54 01
trigger2() listens for 23 02 54 02
trigger3() listens for 23 02 54 03 and so on all the way up to 53

So my complete code basically does the following:

1. In a loop listens for communication.

2. When it receives it, the data received activates one of the trigger commands and executes code that checks the state of the corresponding digital pin. If it's high it turns it low and if it's low it turns it high. This turns the relays on and off. There's some other code in there to ensure that when the Arduino powers up the relays are all set to off.

Pretty straightforward. Once I had learned how the Nextion editor worked and figured out the formatting of some of the things from the EasyNextion Library I had everything up and running in about an hour.

 
#4
Revision 1

Added another screen where I can toggle the buttons to be momentary vs latching.

Buttons are latching by default, touching a button on this screen flags it as momentary with an M. Exiting the screen saves all of the buttons status to the EEPROM so that when the power is cycled the settings are restored. Enabled the same memory storage for the back light brightness so that the previous setting is recalled after the power is cycled.

1588977620247.png
 
Last edited:

Daedalus

Adventurist
#5
This is fantastic. I just ordered all these parts today to play around myself. I will be sure to post whatever I come up with! I have literally 1 of 3 planned accessories to power on my vehicle but I have some other ideas for this too :)
 
#6
This is fantastic. I just ordered all these parts today to play around myself. I will be sure to post whatever I come up with! I have literally 1 of 3 planned accessories to power on my vehicle but I have some other ideas for this too :)
Nice! I'm interested to see what you come up with. I have some accelerometers coming early next week and I've got the preliminary code working for an inclinometer.
 

Daedalus

Adventurist
#8
Nice! I'm interested to see what you come up with. I have some accelerometers coming early next week and I've got the preliminary code working for an inclinometer.
I have a different project that is mostly working which is basically a server for the jeep. Raspberry pi with a TNC backpack to run xastir for APRS, internal battery backup, cradlepoint wifi / cell router, etc. One thing I would like to build into this is the ability to communicate via wifi or something. The server will mount back where the old CD changer was but provides its own wifi network that is cell connected. If I could read / write to the ard from this server it opens up some more fun possibilities.

I also ordered this guy to try with the wifi asspect.
 
#9
Fiddled around in the truck figuring out where to mount this little LCD. I've opted to modify the change holder in the dash as a mount for the screen. Easily reached from both the driver and passenger seat. Only downside to this Nextion LCD might be viewing angle. It washes out just a little when as you start to view it from the side, but it's still very readable from the driver's position.

mount.jpg

Messed around with some 3d modeling to make a bezel/enclosure for it. It might finally be time to buy a 3d printer...

I had plans to add some additional information to the lower portion of the main screen, but I've scratched that idea for now. With the screen sitting a little further out and my eyes getting older I decided larger buttons are the way to go. I took a few close up photos of the other OEM buttons in the truck and then used Photoshop to create something close.

oem.jpg

The great thing about the Nextion is I didn't have to re-code anything. I just uploaded the new graphics and then resized all of the button areas in the editor to match. Makes updates very easy if you decide to change the layout. Some of the stock buttons in the truck have a status LED so I decided this was something the digital buttons needed too. I learned a little bit more about the serial communication the board was using and now when one of the relay's is powered on the Arduino sends a command to the Nextion to generate my equivalent of a status light:

status.jpg

The buttons all have text labels that can be altered as I add accessories down the line. At this point I think this does everything I want it to so it's time to get the wiring done, put together an enclosure for the screen and get it mounted in the truck. That will have to wait until the truck comes back from the shop for it's suspension upgrades.
 
#10
Revision 2

Added an opening animation when the unit powers on. This matches the animation that truck's instrument cluster plays when the truck is cranked giving a little more of an OEM feel. I also decided that I'm going to make this it's own stand alone module, and as such it doesn't need the processing power the Arduino Mega is providing. I ordered a couple of Arduino Nano's and moved the program over to one of those. This also provides a much smaller form factor making it easier for me to house everything.

 
#11
Project 2: Inclinometer

The truck has an inclinometer built into the digital cluster of the dash. Here's an image shamelessly stolen from the internet:

1589427819377.png

That's great and all, but I wanted to make my own! I mean...the little truck on that screen doesn't even look like mine!

So using an Arduino Nano and a MPU-6050 Accelerometer / Gyroscope module I got started. The Accelerometer/Gyro module I linked to there comes in a pack of three and each one comes with two sets of pins to be soldered to the board, one vertical and one horizontal. I opted to do a mixture and soldered two straight up and down and one horizontal.

4 wires and the hardware is ready:

1589428283071.png

I found a library called TinyMPU6050 for the Arduino IDE which made initializing, calibrating and communicating with the module very easy. Outside of the included libraries there's actually only 6 lines of code I had to write.

I created a screen on the Nextion display showing the angles for the X and Y axis and then created images using ones that closely match my truck for each degree of roll and tilt. That was the most time consuming part.

1589428599784.png

After that I plugged everything in and....nothing happened. I did some testing and two of the three accelerometer/gyro boards I have seem to be malfunctioning. They'll report temperature (that sensor is on there too) but nothing else. The third board, however, worked flawlessly and I ended up with this:


I'm going to refine that layout a little...it's a sort of plain, and then figure out an enclosure for this module as well.
 
Last edited:
#12
Nice! I'm interested to see what you come up with. I have some accelerometers coming early next week and I've got the preliminary code working for an inclinometer.
Things have been crazy, I'm only just now starting to hook this stuff up to play with it. This thing is amazing!
 
#13
As I start thinking about how to start really working on this I wonder, should we have a vehicle specific github / bitucket or something for all this work we're doing? We could each add our own sub-section to it, etc as they are separate projects.

What do you guys think?
 
#14
As I start thinking about how to start really working on this I wonder, should we have a vehicle specific github / bitucket or something for all this work we're doing? We could each add our own sub-section to it, etc as they are separate projects.

What do you guys think?
By "vehicle specific" I mean, vehicle specific implementation of this hardware, etc. Not actually specific to vehicle types, etc.
 
#15
Microcenter is running the Ender 3 Pro on sale for $199 right now. It's time to pick these projects back up now that I can design and print enclosures.

20200721_212633.jpg

Almost 1/2 through the first test print and I'm pretty impressed with the detail. I was expecting something a lot less smooth.

20200721_212642.jpg

I had no idea you could get texture on a print like that.
 
#16
As I start thinking about how to start really working on this I wonder, should we have a vehicle specific github / bitucket or something for all this work we're doing? We could each add our own sub-section to it, etc as they are separate projects.

What do you guys think?
Sounds like a good way to organize it.
 
#18
I swear you read my mind. I'm only just now starting to even think about this again. (stuff going on, just got the jeep back from the shop, etc.) Motivation has been sorely lacking. I was just looking at this "8 Relay Module" and realized I have no way to safely enclose it. Regarding the source sharing bit, I also haven't given that any more thought but I figure it would be a way to collaborate / learn from each other, etc. I only just started watching videos on how to use the UI designer & hook that into arduino. This hw setup you came up with is really powerful! The display having its own local compute is huge.
 

Greg

Adventurist
Senior Staff
#19
Microcenter is running the Ender 3 Pro on sale for $199 right now. It's time to pick these projects back up now that I can design and print enclosures.

View attachment 52333

Almost 1/2 through the first test print and I'm pretty impressed with the detail. I was expecting something a lot less smooth.

View attachment 52334

I had no idea you could get texture on a print like that.
I found this looking into project boxes for something I have planned. Immediately thought of this.

Extruded Aluminum Enclosure (various colors and lengths)
716-CkNMnWL._AC_SL1500_.jpg
 
#20
Working on putting the Nextion display into the truck. Started out by removing the existing coin tray, spending a few hours with a digital caliper and redesigning the wheel coin tray minus the coin holding portion:

1595872045741.png

cointray.jpg

My goal was to create a flat surface to then build upon for the Nextion housing. This is where I ran into what is, probably, one of the downfalls of 3d printing. Because you can rapidly prototype things you tend to prototype everything. The print time on that piece was about an hour and a half. I checked in on it about 3/4's of the way through the print and realized that I had forgotten to make part of the model solid so the print wasn't coming out as it should. My only option here was to fix the model and start the print again. This would leave me waiting another hour and a half, using up that much more material and ending up with a piece that I was pretty sure would fit, but that would probably still need some adjustments. Printing this part over and over to fine tune it wasn't appealing to me.

I began looking at the project from a different direction. I already have the coin tray that fits into the dash properly because it's designed to do so. Why not create a piece that fits into the coin tray instead of printing the entire thing? So I created this little shape:

1595872493086.png

Which, after some test fitting into the coin tray, evolved into this:

1595872532072.png

Which ultimately became this shape:

1595872564282.png

1595872883242.png

All of those use minimal amounts of filament to print and the longest print time out of the 3 is 10 minutes. This let me make little tweaks without wasting too much time and material.

I did the same thing for the Nextion housing, designing some small parts to get the fit right before meshing it all together:

1595872781897.png

1595872849913.png

1595872908186.png

Which led to putting everything together and coming up with a housing that has three of the coin slot shapes on the back to insert into the tray:

housing.jpg

housing 2.jpg

Working it this way let me design all the little, size critical parts quickly before putting them together into what is, hopefully, the finished product. Even at a low infill and print resolution this part has a print time of almost 7 hours. Printing for 7 hours just to check minor parts for fitment just isn't reasonable. 4 hours from now I'll find out if this part works. :D
 
Top Bottom