4051 Temp Monitor

After a long weekend, I’ve come to the conclusion that I need help.
I am trying to build a system that monitors 4 thermistors in different positions, accuracy can be ± 10*c for my purposes, and logging them to an SD card.

The thermistors are 10k @ 25*C, in a 10K voltage divider. specs found here

The mux I’m using is an analog 8-1, specs found here

Schematic of how I have it wired is attached.

I can’t quite say that I have working code, but it kind of works.

// ----------LIBRARIES--------------
#include "Arduino.h"
#include <LiquidCrystal.h>
#include <SD.h>

// --------CONSTANTS (won't change)---------------
const byte Mux = A1;
const byte ETEMP = 6;
const byte CVTTEMP = 5;
const byte TransTEMP = 4;
const byte AmbTEMP = 7;

//------------ VARIABLES (will change)---------------------
//analog reads
double V5 = 4.8;
double Vo;
int beta = 3892;
int R1 = 10000;
int R_inf = .0214186853;
byte TempTimer = 10;
int etemp;
int cvttemp;
int transtemp;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//================================================================================
void setup() {
  Serial.begin(9600); // Open serial communications and wait for port to open
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("test");
  delay(250);
  lcd.clear();
  lcd.setCursor(3,0);
  lcd.print("TEMP = ");

}
void loop() {
  /*for(int t=4; t<7; t++){
    Serial.print((Temp(5)));
    Serial.print(" , ");
    lcd.setCursor(11,0);
   // lcd.print(int(Temp(t)));
    delay(500);
  }*/
  Serial.println(Temp(4)); //Trans
  delay(500);
  //Serial.println(Temp(5)); //CVT
  delay(500);
  Serial.println(Temp(6)); //E temp
  delay(500);
}

//================================================================================

double Temp(int ch){
  double tempK;
  double tempC;
  double tempF;
  if(ch==4){                            //selecting the correct temp ch from the mux.
    digitalWrite(A4 ,HIGH);
    digitalWrite(A3, LOW);
    digitalWrite(A2, LOW);
  }
  if(ch==5){
    digitalWrite(A4, HIGH);
    digitalWrite(A2, HIGH);
    digitalWrite(A3, LOW);
  }
  if(ch==6){
    digitalWrite(A4, HIGH);
    digitalWrite(A3, HIGH);
    digitalWrite(A2, LOW);
  }
  if(ch==7){
    digitalWrite(A2, HIGH);
    digitalWrite(A3, HIGH);
    digitalWrite(A4, HIGH);
  }
  delay(2000);
  Serial.println(ch);
  //Serial.println(1024/analogRead(Mux));


//calculating the temperature of selected ch

  //Equations to match my thermistors Exactly.
  //Vo = ((analogRead(Mux)*.0049));
  //Serial.println(Vo, 10);
  //tempK = beta/(log(((((Vo*R1)/(V5-Vo)))+136)/(R_inf)));
  

//Matches thermistors +- 5deg.
double Temp;
  Temp = log(((10240000/analogRead(Mux)) - 10000));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  tempC = tempK - 273.15;              // Convert Kelvin to Celsius
  tempF = (tempC * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit - comment out this line if you need Celsius
  return tempF;
 

}

While the code is running, I can grab one thermistor and its temperature reading jumps to approximately my body temperature, but the others that are still at room temperature also read my body temperature.

Is this due to how I have it wired, or is it code based?

Pins 9, 10, 11 on the 4051 needs to be wired to digital pins on the Arduino.
Since you have four thermistors, you could have

pin9  pin10  pin11
----   ------  ------
0      0        0        == tc1
0      0        1        == tc2
0      1        0        == tc3
1      0        0        == tc4

wire TC1 to pin 13
wire TC2 to pin 14
wire TC3 to pin 15
wire TC4 to pin 12

wire pin3 of 4051 to A0 of Arduino

You'll also want to read http://playground.arduino.cc/ComponentLib/Thermistor

The reasoning behind wiring the Ch selects to A2-4 is that this project is mounted on a data logger shield that uses 11, 12, 13, and A5 for chip select, and an LCD shield that uses 4-10, and then two interrupt triggers on 2 and 3.

I do agree that wiring into Channels 0-3 would make the code a little bit easier to follow, but as I have it laid out it makes little difference.

Hi, i don’t understand why you are using a 4051 chip at all for this. The Arduino already has one built-in. Why not attach the thermistors directly to A1 to A4? (Each will need its own 10K).

21da29394a5a13bd96bae030e438595b3ae4464e.jpg

bracer:
The reasoning behind wiring the Ch selects to A2-4 is that this project is mounted on a data logger shield that uses 11, 12, 13, and A5 for chip select, and an LCD shield that uses 4-10, and then two interrupt triggers on 2 and 3.

I do agree that wiring into Channels 0-3 would make the code a little bit easier to follow, but as I have it laid out it makes little difference.

A0 - A5 are inputs. How can you be using them for chip select?

I understand that using the 4051 at this point looks like overkill.

After digging in other posts, and data sheets, you can use the analog pins as digitals if need be.

Since this whole thing is going to be mounted into a mini baja, and rules are strict about batteries, I plan on putting a voltage divider for a battery monitor.

I also plan on putting more sensors on the engine for more data locations, possibly the intake, exhaust, and cooling fin. Current set up is just engine oil, trans oil, and the temperature in the clutch box.

Like I said in the first post, I can read the temperatures fine, but when switching between thermistors, it acts like it sticks on the highest temperature.

bracer:
I understand that using the 4051 at this point looks like overkill.

After digging in other posts, and data sheets, you can use the analog pins as digitals if need be.

Since this whole thing is going to be mounted into a mini baja, and rules are strict about batteries, I plan on putting a voltage divider for a battery monitor.

I also plan on putting more sensors on the engine for more data locations, possibly the intake, exhaust, and cooling fin. Current set up is just engine oil, trans oil, and the temperature in the clutch box.

Like I said in the first post, I can read the temperatures fine, but when switching between thermistors, it acts like it sticks on the highest temperature.

Let me write it again, A0 - A5 on the Arduino are inputs. Understand?

ieee488:
Let me write it again, A0 - A5 on the Arduino are inputs. Understand?

Yes we understand what you are saying. They can also be digital outputs.

bracer:
it acts like it sticks on the highest temperature.

Try removing the 10K shown in your diagram and adding a 10K from each thermistor to ground. I agree this should not be necessary, but... it sounds like the analog pin is floating.

So that way the measuring point is after the voltage divider?

Yes. If you were using an 8 way mechanical switch, I'm sure the single 10K would be ok. But i wonder if the 4051 doesn't quite work like that in some way. Maybe it reflects the input voltage at the output, but won't allow current to flow, so trying to form a voltage divider with the chip in the middle of it does not work. I am by no means sure about this but worth a try?

A couple of things I’ve noted:
1.
In your title you have a 4051. In the drawing you have a 4052.
The way you are using it, as though it were a 4051.
2.
You do not declare the analog pins that you are using
as digital outputs in your setup. like:

pinMode(A2,OUTPUT);
etc.

These are completely missing.

CMOS mux chips are very static sensitive. I know as an engineer,
I have no static but I found it easy to blow these parts.
Always use a ground strap and make sure your circuit is also grounded
when installing these ICs. Make sure to hove all the leads connected
to something before inserting the chip on your proto board.

Dwight

PaulRB:
Yes. If you were using an 8 way mechanical switch, I'm sure the single 10K would be ok. But i wonder if the 4051 doesn't quite work like that in some way. Maybe it reflects the input voltage at the output, but won't allow current to flow, so trying to form a voltage divider with the chip in the middle of it does not work. I am by no means sure about this but worth a try?

Paul is somewhat correct here. There is some internal resistance
of these chips. Not having the specs handy you need to realize
this.
As well as having some resistance, it changes with the voltage
applied to the analog pins as well. It is almost an order of magnitude
change over the voltage range.
You'd do better using a resistor at each sensor instead of the shared
resistor.
Dwight

dwightthinker -
The chip in the drawing is a 4052, that's all that fritzing had in dip packaging. In the real circuit the chip is a 4051 installed into a removable header, but all of the wiring in the picture is for the 4051 pinout.

I will try using the pinMode(A#,OUTPUT);

I will also split up the voltage dividers to be before the mux and tying all of the un-used pins to ground with a 10K resistor also as I have quite a few laying around for this project.

I will post back tomorrow with the results of such doings.

Dwightthinker

Thank you for correcting me in my errorful ways. Declaring A2-5 as outputs is working flawlessly. Figured I'd try that first before soldering on the board more.

Now to finish it off and save everything to an SD card. That shouldn't be too hard.

Now you have it working, is it too late to suggest doing it a completely different way? Look up ds18b20 digital temp sensors. You can chain many of them on the same 2 wires. No extra chips needed.

Paul, thank you for the suggestion. Those look tempting, but would be hard to mount into the various locations. For the trans temp, I drilled out an M6 bolt. For the Engine temp, (which is a lawn mower engine) I drilled out the oil cap. For the clutch box, I have just zip-tied the wires to the backing plate.

Since this system is going into a collegiate race buggy, one aspect to this competition is total cost. Currently the entire system comes in at ~$25 including 8 temperature sensors, wheel speed, engine speed, SD shield, lcd shield, and the uno. Using the ds18b20 it would easily triple in price.

One should always read the arduino reference pages before for using anything
commands you haven't used before.
The DS chips are a good idea as well. They are better calibrated
than a number of thermistors would be.
Thermistors also age a little over time. RTDs are much better
but would need some front end circuitry unless using the 1K
platinum ones ( like these ).
Many industrial controls use thermocouples but they also
require some front end circuitry and understanding of how they
work when connected to circuits.
Dwight

bracer:
would be hard to mount ... would easily triple in price.

How are they harder to mount, and how do they triple the price? You can get them for as little as £1 each. And take off that the time and money spent on the 4051 and a circuit board for it.

http://www.ebay.co.uk/itm/1-2-5-10-20Pcs-DALLAS-DS18B20-18B20-Digital-Thermometer-Temperature-Sensor-SYUK-/201003085682?var=&hash=item2eccb7af72:m:mLpSx6EPT_F15ZqKh1fXKng

Alright, I miss spoke, Or rather didn't do my homework. The DS18b20 is rather equivalent in price, and if you would take out the price of the 4051, it would be almost exactly the same. Also, with this being the first revision of the temp monitoring system, I went for the widest temp range possible, just because I didnt know what temps we are seeing. If it is with in the range of the DS, that will probably be the way that i will go for the next buggy.

As far as accuracy goes, the team is okay with a 5 degree range, which the thermistors can achieve. Plus the code for the thermistors is a little bit easier to follow for a non-programmer (IE the rest of the team/future electrical leads).