Introduction: Quick $20 G-force Car Gauge
For about $20 build this quick and easy 3-axis G-Force gauge
10x RGB leds display the ----
- strength of left and right turns
- braking and acceleration
- bounces from rough road conditions.
- display real-time graphs when connected to computer
A great excuse to get off the Interstate, out of the city and onto the curvy back-roads. Great for family road trips or to make school bus trips more educational. Educational and possibly even useful for analyzing driving styles.
If you want to get fancy, you can create a face and case for the board, then install it in a standard sized housing available at any car-parts store.
Basic Concept:
This project uses the built-in accelerometer sensor on Adafruit’s “Circuit Playground” board to read the forces exerted as your vehicle moves through space. Colorful LEDs (also built-in on the board) light up to give a visual display of those forces. There are 10 RGB-LEDs on the board. They are arranged in two arcs of five, one arc at the top of the board and one arc at the bottom. Each of these 10 LEDs can be individually lit in any color.
Turning - The turning forces are displayed on the top arc of 5xLEDs . When the car is being driven straight ahead, the center LED is lit in blue. When the car is driven through a curve (turned), additional LEDs light up blue to indicate the direction and sharpness of the turn. If the strength of the turning force increases enough, the LEDs begin to change from blue to red.
Acceleration and Braking – When the car is at rest, or moving steadily, the lights remain off. If the car is braked (decelerated) gently, the outermost two LEDs on either side of the bottom arc are lit in red. If the braking forces are stronger, two additional LEDs turn red. When the care is accelerated, the lights turn green in the same sequence.
Bouncing – The center LED in the bottom arc indicates the general roughness of the road by changing from a steady green for a smooth road, to yellow, to orange and then to red on roughening roads. When the vertical acceleration exceeds a certain threshold, as when hitting a pothole, multiple LEDs flash purplish for a moment.
Successes and Failures
While this is a great introductory project that yields entertaining and usable results within 10 minutes, it is in no way a “professional level” G-force gauge. It might be good for getting the kids and "car people" in your Maker Group interested in coding, but you will need multiple sensors to get really accurate readings. And you will likely have to tune the parameters to match your car and driving style.
The “turning” code works well on curvy roads, but highway curves don’t trigger it. The accelerometer senses the “change” of sideways acceleration better than a sustained sideways force. So as the car “settles into a curve” the indicator can return to the center position.
The braking code works well since these forces are strong, even at moderate braking. But I can’t get the acceleration code to be sensitive enough for normal cars and drivers without also getting triggered by road vibrations. The dial might work in a rail-dragster, but most people and cars simply don’t accelerate quickly enough to generate a strong force. When the sensitivity is set to detect “sedan and mini-van” acceleration, every small road bump also triggers the light. So I added a conditional in the code that prevents acceleration being shown if the bouncing forces are also high. Now, the acceleration does at least flicker green when the car is quickly accelerated hard from a standing start.
The bouncing indicator works well to indicate general road-roughness, but I failed to create the ability to differentiate between up and down motions.
The case and face are easy to make and work well. The visual shapes on the dial face are somewhat awkward, but they are distinct enough so that the lights’ functions are easy to discern. When they were all the same shape, or more subtly shaped, the dial appears (to me) to be just a mass of flashing lights.
Step 1: Materials and Methods
Hardware: Circuit Playground board from Adafruit: This board is a fantastic all-in-one Arduino compatible board that is loaded with sensors and outputs and costs a mere $20 USD. We only use the accelerometer and LEDs, but there's tons of great stuff on this inexpensive board.
Power Source: I used a 3xAAA battery pack with switch. But the board appears to work with anything from a LiPo up to 6v. You can power the board from a car USB 5v charger or a computer.
Case and Frame: I used a craft-cutter, cheap scrap-paper with some glue and paint to create the face of the gauge, then installed it into a scavenged housing. You could also 3D-print or laser cut a custom case and frame.
- Paper - one sheet of thick paper
- Scissors or Craft-Cutter
- Paint or Markers (If not using color paper)
- Adhesives- I used spray E6000 for the paper, hot-glue and tape to attach
- Case or frame
Support Software: You will need a recent version of the Arduino IDE (1.6+) along with the Circuit Playground libraries, drivers and board definitions from Adafruit. Check on the Adafruit site for the most up-to-date instructions. (I’m using an early release “Developer Edition” of the board, so there is a constant stream of improvements.)
Executable Code
Finally, download the attached .INO file and load it into your board.
Attachments
Step 2: Software, Sensors and Outputs
Software
The Arduino code is fairly simple. It's really just three series of if-then-else statements --- with one series for turning forces, one for braking and acceleration, and another for bouncing forces. The only tricky part is that we have to set an upper and lower limit for each test. For that we use the Boolean And symbol "&&" to create a range of values to test for.
if (turningForce > -100 && turningForce < 100) { CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(170)); } else if (....
Each series of if-thens tests to see if one of the accelerometer's axis reads within a certain value range. Then the code sets LEDs to indicate what range has been read.
Also, we must test the accelerometer for both the positive range and negative range. This allows us to determine whether the car is turning to the left or the right.
There are better ways to do the tasks (a for-loop that takes pairs of range values from an array), but I try to keep the code as simple as possible so absolute beginners can understand it.
There is also code that displays all three axes in the serial plotter of your Arduino IDE. Open the serial plotter from the Tools menu in the Arduino IDE. Move, tilt and twist the Circuit Playground board to see the results in the graph.
You will probably have to adjust the ranges of the test values to fit your car and driving style. I have it configured to react smoothly to my setup and style. However, I tested it with other drivers and cars and the results varied wildly. I use the traditional "brake, set, accelerate" style with curves, hopefully resulting in a smooth increase in forces. Others, however, dive into a curve, turn curves into straight-line segments, or are so timid there is no reaction. The readout does show these styles accurately, but I don't find them as entertaining as the smooth, power-through style. So play with the test values to get useful information for yourself.
REMEMBER: Keep your eyes on the road, hands of the wheel and attention fully on safe driving. Thank you!!!
The Arduino Board
The Circuit Playground is an Arduino compatible board pre-loaded with sensors and feedback devices. They are designed and manufactured by Adafruit. The board features an ATmega32u4 Processor, running at 3.3V, USB and a 2-pin JST power connector.
- Outputs include 10 x mini NeoPixels a miniature Speaker plus 8x Output-Pins
- Sensors include an Accelerometer (LIS3DH triple-axis accelerometer with tap detection, free-fall detection), a Temperature sensor (thermistor), a Light sensor (phototransistor), and a Sound sensor (MEMS microphone)
- Inputs include 2 x Push buttons a Slide switch and 8 x alligator-clip friendly input pads (various digital, analog and capacitive touch)
- Communication options include I2C, Serial and USB that can send mouse, keyboard and MIDI signals.
- Power and ground pads are included for adding extra components
- The size = 2” diameter (~51mm) circle.
That’s a lot of power for about $20 US.
This project only uses two of these many components (the accelerometer and LEDs), so using the full-featured Circuit Playground might seem like overkill. But gosh, it is sure is easy and convenient.
Adafruit seems to be positioning the Circuit Playground board for the education and new-maker markets. So they have gone to great lengths to make it easy to program right out of the box.
If you are familiar with any Arduino, then writing code for the Circuit Playground board will be easy, but there are some differences. There is no set-up code required for the built-in sensors and outputs. That’s because the folks at Adafruit have pre-configured almost everything on the board and hidden those annoying pin declarations inside the library.
However, if you want to attach something additional to the board (potentiometer, LCD screen etc.), you still have to set up that hardware the old fashioned way (define the pin, set the mode etc.) and load any needed libraries.
All the functions for the built-in sensors and outputs have been wrapped into a single library with a consistent format. No need to load multiple libraries, create names for all your sensors etc. Just ask for something like “CircuitPlayground.temperature()” to get the thermistor’s value, or “CircuitPlayground.motionZ()” to get a reading from the accelerometer.
Did You Notice? ---- There are no schematics here, no hook-up diagrams, no caution/warning about matching voltages or soldering guides. Why is that? Because all those things have already been taken care of for you. Just plug in the Circuit Playground and start coding. Compare with the complexity of these excellent but pre-Circuit-Playground tutes from DavidH666 and bhouston.
SENSORS - The Accelerometer
The triple-axis accelerometer is the only sensor we use for this project. The sensor is very easy to use, but difficult to explain. The easiest way to quickly understand how it works is to load the code and open the serial plotter window in the Arduino IDE (under Tools/Serial Plotter). Tilt the board and watch the graph change. Now shake it and watch the graphs spike.
Do the graphs tell you what you want to know, do they make sense to you? Then you could skip the rest of this section unless you want to understand a little more about how the sensor works
Axis and Orientation
It’s called a triple-axis (or 3-axis) accelerometer because it senses acceleration when moved (1) forwards and backwards, (2) from left to right and (3) up or down. It can sense movements on all three axes simultaneously.
The axes are labeled X, Y and Z on the Circuit Playground board and the software library uses these same labels when you ask for a sensor reading with a request like:
CircuitPlayground.motionZ();
The Cartesian coordinate system traditionally maps these X,Y,Z designations in a specific way and the Circuit Playground board adheres to this standard. The X and Y axes describe the flat plane of the board and the Z axis is the vertical or normal to the board’s face. This seems logical when the board is flat on a table.
But when you flip the board onto its edge, (like we do in this project), things can get a little confusing.
When flipped onto its side, the sensor’s Z axis is now measuring a horizontal forward/backward movement not the previous, more traditional up/down movement. The board and software do not care how the board is oriented. The axes stay the same as far as the board is concerned. That’s because the labels for X,Y,Z are “locally relative” to the sensor itself, but are fixed not relative to the world.
Think of it as your head and feet. Typically, your head will be higher than your feet. But if you hang upside down, your feet are now higher than your head. Yet we call them by the same names no matter what their relative position or orientation is to each other.
How Does It Work
This type of accelerometer is basically a weight attached to one end of a spring. The other end of the spring is attached to a fixed surface. The spring flexes whenever the spring/weight is moved. The quicker it is moved, the more the spring is flexed. The amount of flexure is translated into voltage and sent to the Arduino. When at rest the voltage is near zero, when it flexes in one direction the voltage is positive, when flexed in the opposite direction the voltage is negative. Combine three of these spring/weight into a single sensor to measure all three axes.
Although it’s called an accelerometer, the sensor also measures the force of gravity. The weight is pulled down by the “acceleration of gravity.” So at least one axis will be affected by this downward force.
This means the sensor is also affected by the how many degrees the board is tilted. So it affected by whether you are headed up or down a hill. For a more accurate reading you will need additional sensors to create an "IMU." The amazing amandaghassaei and XenonJohn have great info on IMUs and how to use them.
The sensor is based on the LIS3DH and Adafruit has a separate board with just this sensor. You could use this board with your existing Arduino and get similar results. Adafruit’s tutorial explains a lot about the concepts behind the accelerometer, plus shows you how to do some fancy tricks like change the range of G-forces it measures, how to detect free-fall, taps and double taps.
IMPORTANT: Make sure your gauge is level when the car is at rest and on level ground. If you must mount the gauge at an angle you will need to adjust the default values of the affected axis.
OUTPUT - The NeoPixels
“NeoPixel” is what Adafruit calls some of their addressable RGB and RGBW LEDs. The company features a wide range of NeoPixel products that include flexible strips, rings, panels and individual LEDs. The Circuit Playground uses ten of the small square versions arranged in two arcs of five on either side of the board.
To find out all about NeoPixels and how to use them, start with the Uberguide then play with any of the hundreds of other tutorials that use them.
NeoPixels have always been easy to use, but the Circuit Playground makes it even simpler. Adafruit has pre-configured the LEDs, hardware and software.
Now, all you have to do is make a simple call to set individual pixels to specific colors - here, setting pixel #1 to blue (170 on the colorwheel):
“CircuitPlayground.setPixelColor(1,CircuitPlayground.colorWheel(170));”
If you are familiar with NeoPixels you will notice some differences with this board. For example, the form of the commands is usually wrapped inside a call to CircuitPlaygroud, and the "show" command is not required for most usages. The LEDs are running on 3.3v and the global brightness was pre-set to a low value. These LEDs can be blindingly bright at full power and you can set them back to 100 percent brightness in the code.
Step 3: Making the Decorative Face
You don’t need a case to have a fully functioning G-Force dial, but it’s fun to make one and it looks so much more "race car."
I chose to play with my craft cutter and make a case from layers of glued paper - the poor man's 3D printer. I had an old chrome dial-frame in my scrap pile, so I glued the board and facing into the frame to make it look more official. Since this was designed to entertain some kids for a few hours, then get disassembled, I didn't get fancy with the housing at first. But with a diameter of 2” (~51mm), the Circuit Playground fits conveniently into a popular standard case-size for automotive gauges so I eventually put it into a fancier housing.
Basic Assembly
The dial face is made up of three basic components:
- A pair of "wings" that fit over the NeoPixels and elevate the main-plate above most of the other components to provide clearance. The wings also keep the light from the LEDs from bleeding over, so each LED looks distinct on the display
- The "main-plate" covers the body of the board and fits between the wings and decorative face.
- The decorative face is what the user sees. A black faceplate sits on top of orange decorative trim-plate. A diffusing layer sits behind the other two layers.
These components are made up of several layers of paper that are glued together. I used some scrap paper to experiment with, and it worked well so I kept it for the final project. I think it was some aged 80# matte inkjet paper. It required several layers to be build a shell thick enough to cover all the bumps and components on the board. You may need more or fewer layers depending on the paper or material that you use.
I thought the design process would be simple - "It's just a disk over a circle," I said to myself. So I grabbed my calipers and started measuring, then used the software from the Silhouette craft-cutter. That was a BIG!!! mistake. This little board is stuffed full of all kinds of components. Every portion of the surface has bumps and protrusions from all the components, all with tight tolerances. And the board is not nearly as symmetrical as it first appears.
At the very least, I should have used the more capable Inkscape or Illustrator programs. Both of those provide better tools for precise drawings and I could have output the results to DXF for further development. Better yet would have been starting the design in 123D Design or Fusion 360 so I could easily create a 3D-printer version.
Oh well, live and learn.
Assembly Tips and Tricks
Cut out the shapes and stack them on top of each other, gluing them as you go. The photos make it look complicated, but it really is that simple. The only tricky part is making sure you match the pieces correctly before gluing them. The pieces look a lot alike, but there are just enough differences in the shapes that you must match them correctly if you want to board to fit well. But if you do make a mistake, it's amazing what you can do with an X-acto knife and some patience.
Here are some tips to make assembly as easy as possible:
- Paint your pieces before assembly.
- Only glue two layers together at one time. The paper gets mushy and it is difficult to get all the layers to align properly.
- Let the glued layers dry before adding another layer.
- While one sub-assembly dries you can be working on the other parts.
- Test fit the wings to the board as you add layers.
- When gluing the wings and main-plate together, you may need to keep the wings snugly fitted around the NeoPixels to assure proper alignment.
- Let the entire assembly dry very well before testing the NeoPixels - we don't want to short out your Circuit Playground
Cutting File
Here is the cutting file for a Silhouette craft cutter:
Attachments
Step 4: Housing and Case
I intended this as an inspirational education toy, so I wanted to provide the other Makers with lots of options for making their own customized version. If you look around your house you will find lots of objects that fit a 2" circle. So I gathered some of them for the Maker Group to use.
I did most of my test runs with the dial in a simple plastic box. When I was ready for the first presentation I used an old frame from an automotive-gauge and hot-glued the face and battery pack to the frame. I wanted the electronic guts exposed so the "other kids" could see that it was the exact same Circuit Playground board we use in other projects. Yes, you can make a piano, flashlight, game controller etc. with the same board. Besides, if they liked it they might be inspired to make their own personalized case.
For my "final" installation I found an outlet-cover for a vacuum-cleaner in my junk pile. The dial-face fit perfectly, it had two wings to stabilize it, and the wedge at the back had a notch for the battery pack and fit snugly between the windshield and dashboard. I also added a yellow rubber ring from the junk pile for that finishing touch. I used hot glue to attach the Circuit Playground board to the decorative face, then hot-glued the dial/face assembly into the case. (If this was really a "permanent" solution I would use E6000 or equivalent) I left the battery case unglued so I could get to it easily. Make sure the gauge is level and securely fastened to your car's dashboard. I used some industrial strength double sided tape..
If you want a real permanent installation you can buy pre-made housings at any automotive store - most are conveniently designed to fit a 2" round face. But the top from a can of spray-paint, a small nuts canister, the lid of an orange juice container, a large plastic Easter egg - these all make a serviceable housing. Just have fun and make it however you want.
AND REMEMBER: This board also has atemperature sensor for making a visual thermometer, a sound sensor for making a cool VU and graphic-equalizer display and light sensor for making night/mood/emergency lamps. All of these types of cases, and other techniques of this project, make a good place to start for any type of gauge or dial system.