Hi folks, my first project beyond some tutorials and variations thereof. I plan to connect several temperature sensor probes that vary in resistance over a temperature range so I can monitor temperatures using the Arduino. The probes (two different thermistors) vary in resistance from 500K ohm to a couple K ohm and 4M ohm to a several K ohm, respectively. I have chosen 100K bias resistors to construct a voltage divider. The circuit has the thermistor connected to the supply voltage and the bias resistor connected to ground. Analog channels A0 and A1 are connected to the connection between bias resistor and thermistor. In other words, the A/D converter reads voltage on the 100K bias resistor and voltage across that resistor changes according to the resistance of the thermistor.
The problem I have run into is that after running a short while, the LEDs on the Arduino UNO dim and go out. (That is with the voltage dividers powered with the 5V supply.) I actually did some testing with this circuit with 20K bias resistors and ran for several hours while I collected data via USB/Serial with no difficulty (while I was impatiently waiting for delivery of a resistor kit. )
By my calculation (based on the bias resistor alone) the current should be 5V/100K => 0.05 mA which should be well within the current ratings of the 5V supply. I thought I might have a problem with the USB cable so I swapped that out with no benefit. If I switch the voltage divider to the 3.3V source, the system seems to run OK. I've double checked resistance values with a meter. I've stared at my circuit to convince myself it is wired correctly. The system is powered via USB from my laptop. Is it possible that is providing insufficient power? Normally USB should provide 500 mA, no? Even at the lowest resistance values, it the measurement point on the divider was shorted I wouldn't expect to see more than a couple mA of current.
Is there something I'm overlooking?
(I'm not sure this is in the correct forum. Please move it if not! It was not obvious where it should go.)
Thanks!
Here is the code, BTW
void setup()
{
Serial.begin(9600);
}
long filterAdd( const long prev, const int newVal, const int shift)
{
return prev - (prev >> shift) + newVal;
}
int filterVal( const long accum, const int shift)
{
return (int)(accum >> shift);
}
void loop()
{
static const int shift=2;
static long accum0=0, accum1=0; // filter accumulators
int a0=analogRead(A0); // read first channel
accum0=filterAdd(accum0, a0, shift); // roll latest sample into filter
analogRead(A1); // prime second channel
delay(10); // time to settle
int a1=analogRead(A1); // read seocnd chanel
accum1=filterAdd(accum1, a1, shift); // roll latest sample into filter
analogRead(A0); // prime first channel for next loop
Serial.print( a0 );
Serial.print( ", " );
Serial.print( filterVal(accum0, shift) );
Serial.print( ", " );
Serial.print( a1 );
Serial.print( ", " );
Serial.println( filterVal(accum1, shift) );
delay(1000);
}
I can think of two possibilities (the first of which you have already addressed)...
Short-circuit / high current consumption.
Computer is powering off the USB port preparing to sleep / hibernate.
I have no idea if #2 is even possible. It is supposed to be the slave device that goes to sleep thus consuming less energy not the other way around. I don't follow USB develop at all so it is possible modern USB ports have the ability to kill power.
An easy way to divide the problem is to disconnect everything from the Uno and let the sketch run. If nothing bad happens, the problem has to be hardware. If something bad happens, the problem has to be a defective Uno or software.
I've also done some additional testing since my original post. I found a post that indicated that I could connect a 9V battery while the USB cable was connected to a PC. Doing this brought the board back to life but when I touched a finger to the UNO's voltage regulator I found that it got hot to the touch after a minute or two. I did some further testing with various parts of the circuit disconnected. (This was after completely disassembling and reassembling the circuit.)
First I disconnected the leads to the A/D inputs as well as the 5V and GND leads. In other words the breadboard was completely disconnected from the UNO. With the temperature probes at room temperature (and high resistance - resistance decreases as temperature increases) the entire network measured 260K ohms. (Measurement is from the 5V rail to the ground rail.)
Next I powered up the UNO via the USB connection from PC. Voltage from 5.0V to GND was 5.00V (using a DMM.) next I connected power and ground leads to the breadboard. At this point the voltage had dropped to about 4.76V. I disconnected and reconnected repeatedly with the same results. In other words a 260K ohm load was dropping the 5V supply by a quarter volt. If I plugged in the 9V battery, it came back up to 5.00V. I cannot say whether this is normal behavior for the UNO when powered by USB. I had previously found (with probes heated and resistance lower) that eventually the voltage regulator would get too hot to touch (~140°F I would estimate) when powered by the 9V battery. Again, I do not know if this is normal but thought not and disconnected the battery.
Subsequent tests were performed using only USB power and with the green A./D connections removed. The UNO was only powering the resistor network via the 5V and GND leads. I again heated the probes and found at a certain point the 5V supply started to drop slowly, probably a tenth of a volt every several seconds. When the voltage reached about 3.5V it dropped rapidly to 1.7V (and the UNO was no longer operating, of course.) At this point I disconnected the 5V and GND leads and found that the resistance of the network on the breadboard had dropped to about 80K ohm. If I calculate correctly, sourcing 0.6 mA takes the UNO down.
Testing is complete tonight. I appreciate your replies and any further thoughts on this and will check back tomorrow.
I'm not sure you answered the original question - connect nothing to the Arduino except the USB cable, leave it to sweat for a quarter hour, half an hour or so, running the sketch and see whether it fades. If it does, you have a fault on the Arduino board (or the computer USB port) and can forget about the rest of the project for the present.
You can measure the Vcc on the Arduino most easily with meter probes on pins 2 (Vcc) and 6 (Gnd) of the ICSP.
Breakthrough! Short answer - My test setup must have some sort of ground loop. I'm using metal clad probes in a metal pot on the stove. I'm using a water bath to heat the probes. I discovered this when I saw that connecting the 5V lead alone to the full test setup still caused the UNO to shut down. Pulling the probe out of the water bath brought the UNO back to life. With the breadboard disconnected I measure 5.15V between the UNO 5V connection and the 5V rail on the breadboard. I can also measure 106 ohms from the breadboard 5V rail to the stove top. The stove top features electronic ignition so I suppose it is grounded.
Longer answer... I performed a series of tests without the probes and using a single 1K ohm resistor for the load and then with the circuit and the temperature probe connections shorted to provide worst case measurement conditions. Behavior was as expected and the problem was not duplicated until I set up the full test with the probes in the water bath.
Thanks again for all of your help. Now to work on a test setup that does not introduce ground loops!
Edit: On further reflection, this is not really a ground loop but an inadvertent ground. The outer sheath of the temperature probe cables must be connected to the same point which I connected to 5V. This is not really a good idea. I'm thinking about ways to connect this to ground for the final design. If I reverse the connections for the sensors it moves the cable portion to the same point as the A/D sampling point. If I then swap the sensor for the bias resistor then I measure voltage across the sensor rather than the bias resistor. The several voltage divider circuits I saw when researching this always had the sensor on the high side of the circuit with measurement across the bias resistor. I suppose that provides conductance proportional with current since the bias resistor does not change, I guess my next test is to rework the circuit with the bias and sensor resistance swapped and measure voltage across the sensor. I'm not sure that matters a lot to me since I plan to calculate temperature from interpolation within test data.
I actually looked at the pictures and failed to notice that you had the +5V rail connected to the sleeve of the 3.5 mm jacks instead of the ground.
I should have immediately commented on that blunder as I always explain here that anything external to the Arduino - switches, sensors or LEDs and such - should be referenced to ground for this very reason that you have to consider what is going to happen when the external device accidentally shorts out to ground. (Obviously, devices that must be provided with 5V - and ground - to operate need to have the 5V supplied, but any exposed connection such as the sleeve of a jack, should be the ground side.)
So as you observe, you simply connect the temperature sensor (casing) to ground and the pull-up resistors to Vcc.
Unfortunately, there is an only too well recognised (but difficult to remedy) problem in the Arduino tutorials where switches, sensors and such are shown going to Vcc - this is extremely foolish engineering practice, supposedly to make it "easier to understand" the operation. Of course, it turns out to be the very opposite!
Not worth beating yourself up over. It should have been obvious to me as well. (Reminds me that there's nothing scarier than a S/W guy with a screwdriver. )
As it was I got off easy on this one as the ground had sufficient resistance to prevent releasing the smoke in my new toy. And I learned to pay attention to stuff like that. It would be worth a mention in the tutorials but to he honest I cannot say the warning was not there. I tend to skim the text for the required information and could have overlooked any warnings.