Reading various sensors in an automobile - voltage dividing, multiplex, filter

(first time poster, long time searcher) Greetings,

I'm working on a data logging project for my rally car. Arduino Duemilanove Adafruit SD logger (w/RTC) SparkFun 16x2 Serial LCD back pack 4 input buttons Three Axis Accelerometer 4051 Mulitplexer

For my first BIG Arduino project I've somehow managed to use every pin :D I turned to the 4051 to multiplex 8 inputs into 1 analog read.

Software working well with a 5V analog temp sensor - then I hooked the 4051 up to some real world 12V SLA batteries I'm charging and everything stopped working "well". All the pins on the 4051 are setup with a simple resistor divider (10k / 4.7k - 3.1276) so at 15V that means the 4051 will get less then 5V to the pins. The output of the 4051 (z pin) is wired directly to AD pin 3. The ground is common. I'm pretty sure that's not the best way to do it :blush:

Lots of RF introduced when being powered from the computer, nice and quiet when being powered by battery. As testing went on lots of weird stuff started happening: Serial LCD backpack wouldn't start up correctly when all 8 pins of the 4051 were plugged into the 12V source. (had to reset several times) Strings like "Begin Logging!" were no longer appearing correctly on the screen - yet other strings in the program work fine?! SD writing became buggy and then I probably messed it up more by chasing what I thought at first was a software problem. Found a loose ground on the LCD, but fixing it didn't resolve my issues. Went searching here and found some design issues with the SparkFun serial LCD. More confusion... When all the pins are wired up to my battery bank (for testing) the LCD just goes nuts and blinks. Yet I tested every pin and nothing is hitting the box with more then 5V.

My main question is? How should I be protecting those input pins? I just don't understand enough about impedance, etc. to figure out what to do... Clearly doing something bad. They are going to be taking 0-12v analog readings from various places around the car. Car voltage is a noisy dangerous place... :|

Thanks for the help! - Kris

The resistive dividers you have already provide a degree of protection. For greater protection, you could increase the values, e.g. to 15K and 33K. You could also add a diode between each CD4051 input and +5V, and between each input and ground, to prevent the inputs going much above 5V or below 0V.

If some strings appear and other don't, it sounds to me that you could have run out of RAM. Do you know how much RAM your sketch needs? Have you used the F() macro to put string literals in program memory where possible?

dc42 - That helped.
I did some more research and it looks like the SparkFun Serial LCD 2x16 has some reset issues: Serial LCD - SparkFun Electronics
I’ve been using the latest SoftSerial, but when powering up the device with other power sources connected it just refused to display.
The key was when I noticed that it didn’t even show the splash screen. ← this is how I knew it was the module and not my software.
I opened the box up and changed where the ground was. I was originally pulling ground from where the buttons and input ground was. Changing this to the board and making sure that was ground was connected to all of these sources together (board, LCD, buttons, input pins) seemed to make it start up correctly after resetting 80% more of the time. There is STILL something up with this LCD and I read that powering it separately or switching it ON after the Arduino was powered seemed to be the only way to get it to 100%.
http://www.flickr.com/photos/planetkris/8106241868/

Second issue - Free Memory
I went back to a working sketch that had no smoothing arrays. My weird string issues went away, and I had suspected that in the past.
I originally checked it with a function until I noticed this: http://www.arduino.cc/playground/Code/AvailableMemory
“Note: For Arduino 1.0, you have to replace #include <WProgram.h> with #include <Arduino.h>.” No wonder I never saw the values change :expressionless:
Now I have 211 bytes free with filling 4 values into a smoothing arrays on all 11 sensors: aX, aY, aZ, temp, 1-7
When I change to only 2 values going into the array I have 233 bytes free… This doesn’t shrink as I collect data for a second and flush write it to the SD.
When I fill the arrays with 10 pieces of data the program fails after logging for a few seconds. It doesn’t even write to the SD.

Is 200 bytes of free RAM just not enough?
Guess I’ll have to not smooth the data on the device - or go through a 3rd round of slimming my program down.

  • Kris

200 bytes of free memory should be enough, provided that you are not using the String class or anything else that uses dynamic memory allocation. I would need to see your sketch to be certain.

Interesting project, how have you got on with it? I'm looking to do something similar