2

So this is my basic circuit. Three voltage dividers: one 10k pot, 2 thermistors. Fan driver circuit using TIP120 (currently just driving an LED from the 3.3v source). Board is a Leonardo clone, circuits.io only had the Uno in their library. Edit: circuit is now more simplified.

Schematic:

bbw temp controller

reality:

enter image description here

When I adjust the pot, the ADC value of airPinValue changes, regardless of which analog input it is connected to. meatPinValue does not change. Swapping the inputs that airTempPin and meatTempPin are assigned to has no effect, airTempPin changes the same. Physically swapping the thermistors has no effect, nor does switching which input they connect to.

Code:

#define potPin A0
#define airTempPin A5

int potValue = 0;
int airPinValue = 0;
int i = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  i++;
  potValue = analogRead(potPin);
  airPinValue = analogRead(airTempPin);
  if (i == 2000) {
    Serial.print(potValue);
    Serial.print(",");
    Serial.println(airPinValue);
    i = 0;
  }
}

EDIT: much simplified code

EDIT v2.0 : I have now swapped out the board for an official Uno, as well as swapped everything to a different breadboard and a different Leonardo, with no change in behavior.

EDIT v3 : Corrected code sample. I have also dropped my DMM onto this, reading from the 5v rail to the voltage going to A2. With the pot set to 0 I see 2.401v from the divider, pot to max, same voltage, 2.401v.

EDIT v4: with only the pot and airTemp hooked up, still happens. Further DMM probing actually shows that this only happens when the pot and thermistor are both hooked up to the arduino. If either one is disconnected, the voltage being read by airTempPin is stable/correct. Once both are hooked up to the analog pins on the arduino, that's when the voltage at airTempPin goes off...

Also update diagram, pic, and code to match what I'm currently testing with.

EDIT v5 : This is some sort of analog bleed between the analog input ports. Not really sure how I can combat this :\

  • if pin A1 is left floating like the schematic and used like in the code, any noise will alter it's value. Use A2 in code and it should work. – dandavis Mar 3 '17 at 4:23
  • sorry, that was a copy/pasta problem. As stated in in the question, I've tried using different analog pins to see if the behavior was the same, and it doesn't change when reading from A0 or A2 (and move the physical connection to that pin too) – twardnw Mar 3 '17 at 16:42
  • What do they change to? Can you swap a pot for airPinThermistor? maybe simplify the println(String()+String()+...) into separate lines without the string concatenation magic? – Dave X Mar 3 '17 at 16:47
  • Also, did you try swapping the order of analogRead()s? If it is a sample-hold problem from the prior read, this might help identify it. You could jumper A5 to GND or +5, and intersperse a analogRead(A5) too. – Dave X Mar 3 '17 at 17:02
  • potValue,airPinValue,meatPinValue 0,459,484 457,482,484 1023,515,484 - oh, apparently can't have linebreaks in comments. This is a small sample showing the values of the pins – twardnw Mar 3 '17 at 17:14
2
#define meatTempPin A0
#define airTempPin A1

Your code says A0,A1 but the circuit and picture of the wires say A0,A2.

Since A1 doesn't appear to be connected, as you scan things, the ADC could be sampling and holding some voltage from the prior conversion of potPin.

Try this instead:

#define meatTempPin A0
#define airTempPin A2
  • 1
    beat me by 5 secs, good work! – dandavis Mar 3 '17 at 4:23
  • sorry, that was a copy/pasta problem. As stated in in the question, I've tried using different analog pins to see if the behavior was the same, and it doesn't change when reading from A0 or A2 (and move the physical connection to that pin too) – twardnw Mar 3 '17 at 16:30
  • This is sort of a common problem with open-circuited analog inputs. When you are doing your swapping of wires and pins, could one of the jumpers or one of the breadboard connections be open-circuit? – Dave X Mar 3 '17 at 16:52
2

Moral of the story, the multiplexer was not switching between inputs quickly enough causing the odd reading, looking very much like bleed between the pins. By simply reading each analog input twice and only storing the value of the second reading, I was able to get a valid, stable, reading as expected.

#define potPin A4
#define airTempPin A0


int potValue = 0;
int airPinValue = 0;
int i = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  i++;
  analogRead(potPin);
  potValue = analogRead(potPin);
  analogRead(airTempPin);
  airPinValue = analogRead(airTempPin);
  delay(10);
  if (i == 50) {
    Serial.print(potValue);
    Serial.print(",");
    Serial.println(airPinValue);
    i = 0;
  }
}
  • How resistive are your thermistors? I think I saw if they were on the order of 10K, they can switch pretty fast, but if lots higher, it takes more time to slew. Maybe adding a cap to buffer/hold the thermistor signal would be good too. – Dave X Mar 3 '17 at 21:24
  • 1
    They're 220k-ish, and pretty slow to change (might update to RTDs in the future, but these work for now). My supply of caps is a bit low right now, got an order of a bunch from China arriving next week. – twardnw Mar 3 '17 at 22:12
  • 1
    5V/220k=22uA, which isn't a lot to fill up the sampling capacitor (14pF on the ATMega32u4 I'm used to). The embeddedrelated.com/showarticle/110.php recommends a cap of about 1000x the sampling capacitor, or 14nF or so. – Dave X Mar 5 '17 at 4:45
  • Good to know. Would I just drop that between the return leg from my thermistor and the analog pin, or parallel with the 220k resistor to ground? – twardnw Mar 6 '17 at 6:41
  • 1
    R1 is a 220K? Put the hold cap between the R1 +Rtherm junction and GND. It will charge all the time, and only discharge into the ADC sampling cap when sampled. – Dave X Mar 6 '17 at 16:42
0

https://www.arduino.cc/en/main/arduinoBoardUno

Vin. The input voltage to the Arduino/Genuino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.

Thisi not to be used as powersource for motor/LED whatever, this is input.

Use 5V instead, maybe this would solve the problem.

  • >or, if supplying voltage via the power jack, access it through this pin. – twardnw Mar 3 '17 at 16:31
  • Aside from that, even with it disconnected, the behavior is the same. – twardnw Mar 3 '17 at 16:42
0

You need to have a reference voltage for ADC the problem is that you are not setting the reference voltage for ADC.Change the code in setup where you add a analog reference voltage as internal or default according to your requirement.

  • This is kind of a vague answer. Please consider editing it to add some example code to demonstrate exactly what you're talking about. – per1234 Oct 3 '17 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.