Products > Embedded Computing

Arduino question: unstable signal

<< < (5/6) > >>

billbyrd1945:
As suggested by several posts, averaging didn't work out. It dramatically reduced the amount of bounce so that readings would vary by three or four digits rather than ten or so. But, the result was that the LED I wanted to control would always be half-on (dim) even as the numbers were no where near the turn-on range. And when the wine cooler temp got low enough so that all numbers clearly were in range, the LED remained dim as if it were controlled by a 50% duty cycle in PWM.

The purpose of that particular test was to see how effective "smoothing" would be in cleaning up the numbers. I knew that it might not have anything to do with the use of hysteresis, but still something I wanted to see.

If the group is wondering why I don't just go ahead and convert djacobow's hysteresis example, it's because I haven't yet figured out how to write it. And since my last post I've discovered that the whole thing may not work anyhow as my power supply's noise throws any data (sent to the Arduino) into total chaos. I might have never known this without adding a laptop to the project so that I could actually see the ADC (Analog to Digital Converter) numbers with and without the power supply.

But I still won't abandon the project until I'm able to control the cooler with the Arduino even if I have to connect it to a car battery! As stated before, the goal is to learn enough electronics/Arduino to (at least) control the chiller according to fluctuating temps. To do that, I will try again to convert djacobow's example to my application.

I know that all this seems pointless to many viewers. On the other hand, maybe someone as slow on the uptake as I am, and will be able to benefit from the thread.

(The ADC number that correlates to the temp for turning off the cooler would be 650. The numbers correlating to the temp for turning the cooler back on would be 675. So that's the range.)

Suggestion to learn about first-order low-pass filter duly noted.

Kasper:
If you post your code, it will be easier for people to recommend ways to add hysteresis.

NivagSwerdna:
Can you tell us a bit about the Thermister?  What is is it's resistance at two temperatures?

Also, post your code.

How does your code compare against say... http://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/ ?

... oh... and although it is possibly a guess too far... your voltage divider is currently referenced to the supply, If you get a sag/ripple on the supply it will affect your measurements.   

I reached over to my box of sensors and grabbed a thermister....  which is NTC 10k Ohms at 25C.   It currently measures around 8k6 Ohms... in an arrangement with a fixed 10k resistor that should give a range between 2.5V (at 25C) and 3.7V (at 0C)... what sort of numbers are you getting?  Are you using an UNO?

I took a 10k resistor and put it between 5V and A0, Put the NTC across the A0 and GND....


--- Code: ---int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);
}

#define SIZE 512

int j=0;
int i = 0;
int n = 0;
int readings[SIZE];

void loop() {
  digitalWrite(ledPin, HIGH);
 
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);

  readings[i] = sensorValue;
  i++;
  i %= SIZE;
  if (n<SIZE) n++;

  j++;
  if (j==10000) {
    int min=readings[0];
    int max=readings[0];
    for (int k=0; k<SIZE; k++) {
      if (readings[k]<min) min=readings[k];
      if (readings[k]>max) max=readings[k];
    }
    Serial.print("Reading: Min ");
    Serial.print(min);
    Serial.print(", Max ");
    Serial.print(max);
    Serial.println();
    j=0;   
  }
   
 
  // turn the ledPin on
  digitalWrite(ledPin, LOW);
}
--- End code ---


The example is unnecessarily complex but just takes 512 samples and then every now and again looks at the set and calculates max and min to give a range... under steady state max and min should be similar (and they are)...

It gives a very stable set of readings....


--- Code: ---Reading: Min 531, Max 533
Reading: Min 532, Max 533
Reading: Min 531, Max 533
Reading: Min 531, Max 533
Reading: Min 531, Max 533
Reading: Min 532, Max 533
Reading: Min 532, Max 533
Reading: Min 532, Max 533
Reading: Min 531, Max 533
Reading: Min 532, Max 533
Reading: Min 531, Max 533
Reading: Min 531, Max 533

Started warming NTC....

Reading: Min 531, Max 534
Reading: Min 530, Max 533
Reading: Min 528, Max 532
Reading: Min 514, Max 518
Reading: Min 503, Max 506
Reading: Min 492, Max 497
Reading: Min 486, Max 489
Reading: Min 480, Max 483
Reading: Min 474, Max 478
Reading: Min 470, Max 474
Reading: Min 467, Max 471
Reading: Min 463, Max 467
Reading: Min 460, Max 465
Reading: Min 458, Max 463
Reading: Min 455, Max 459
Reading: Min 453, Max 457
Reading: Min 451, Max 455
Reading: Min 449, Max 453
Reading: Min 448, Max 452
Reading: Min 446, Max 450
Reading: Min 444, Max 449
Reading: Min 443, Max 448
Reading: Min 442, Max 445
Reading: Min 443, Max 445
Reading: Min 445, Max 447
Reading: Min 447, Max 448
Reading: Min 447, Max 450
Reading: Min 448, Max 452

Let go of NTC...

Reading: Min 451, Max 452
Reading: Min 453, Max 454
Reading: Min 454, Max 456
Reading: Min 455, Max 456
Reading: Min 455, Max 458
Reading: Min 456, Max 458
Reading: Min 457, Max 459
Reading: Min 458, Max 460
Reading: Min 459, Max 461
Reading: Min 460, Max 461
Reading: Min 460, Max 462
Reading: Min 461, Max 462
Reading: Min 461, Max 464
Reading: Min 462, Max 464
Reading: Min 463, Max 464
Reading: Min 463, Max 465
Reading: Min 464, Max 465
Reading: Min 464, Max 466
Reading: Min 464, Max 466
Reading: Min 464, Max 467
Reading: Min 466, Max 467
Reading: Min 466, Max 468
Reading: Min 466, Max 468
Reading: Min 467, Max 469
Reading: Min 467, Max 469
Reading: Min 468, Max 469
Reading: Min 468, Max 470
Reading: Min 469, Max 470
Reading: Min 469, Max 471
Reading: Min 469, Max 471
Reading: Min 469, Max 471
Reading: Min 469, Max 472
Reading: Min 471, Max 472
Reading: Min 471, Max 472
Reading: Min 471, Max 472
Reading: Min 471, Max 473
Reading: Min 472, Max 474
Reading: Min 471, Max 474
Reading: Min 473, Max 474
Reading: Min 473, Max 474
Reading: Min 473, Max 475
Reading: Min 473, Max 475
Reading: Min 473, Max 476
Reading: Min 474, Max 476
Reading: Min 475, Max 476
Reading: Min 475, Max 477
Reading: Min 475, Max 477
Reading: Min 476, Max 477
Reading: Min 475, Max 478
Reading: Min 476, Max 478
Reading: Min 477, Max 478
Reading: Min 477, Max 478
Reading: Min 477, Max 479
Reading: Min 477, Max 479
Reading: Min 477, Max 479
Reading: Min 478, Max 480
Reading: Min 478, Max 480
Reading: Min 478, Max 480
Reading: Min 479, Max 480
Reading: Min 479, Max 481
Reading: Min 479, Max 481
Reading: Min 480, Max 481
Reading: Min 480, Max 482
Reading: Min 481, Max 482
Reading: Min 480, Max 482
Reading: Min 481, Max 483
Reading: Min 480, Max 483
Reading: Min 481, Max 483
Reading: Min 482, Max 484
Reading: Min 482, Max 484
Reading: Min 483, Max 484
Reading: Min 483, Max 485
Reading: Min 484, Max 485
Reading: Min 484, Max 486
Reading: Min 483, Max 486
Reading: Min 485, Max 486
Reading: Min 485, Max 487
Reading: Min 485, Max 487
Reading: Min 485, Max 487
Reading: Min 486, Max 487
Reading: Min 486, Max 487
Reading: Min 486, Max 488
Reading: Min 486, Max 488
Reading: Min 487, Max 488
Reading: Min 486, Max 489
Reading: Min 486, Max 490
Reading: Min 487, Max 489
Reading: Min 487, Max 489
Reading: Min 487, Max 490
Reading: Min 488, Max 490
Reading: Min 488, Max 490
Reading: Min 489, Max 490
Reading: Min 488, Max 490
Reading: Min 489, Max 491
Reading: Min 489, Max 491
Reading: Min 489, Max 491
Reading: Min 490, Max 491
Reading: Min 490, Max 492
Reading: Min 489, Max 492
Reading: Min 490, Max 492
Reading: Min 490, Max 492
Reading: Min 490, Max 492
Reading: Min 491, Max 493
Reading: Min 491, Max 493
Reading: Min 491, Max 493
Reading: Min 492, Max 493
Reading: Min 492, Max 494
Reading: Min 492, Max 494
Reading: Min 491, Max 494
Reading: Min 493, Max 494
Reading: Min 492, Max 494
Reading: Min 493, Max 495
Reading: Min 493, Max 495
Reading: Min 493, Max 495
Reading: Min 493, Max 496
Reading: Min 494, Max 496
Reading: Min 494, Max 495
Reading: Min 493, Max 496
Reading: Min 495, Max 496
Reading: Min 495, Max 496
Reading: Min 494, Max 497
Reading: Min 494, Max 497
Reading: Min 495, Max 497
Reading: Min 495, Max 497
Reading: Min 494, Max 497
Reading: Min 496, Max 498
Reading: Min 496, Max 498
Reading: Min 496, Max 498
Reading: Min 496, Max 498
Reading: Min 496, Max 498
Reading: Min 496, Max 499
Reading: Min 496, Max 499
Reading: Min 496, Max 499
Reading: Min 497, Max 499
Reading: Min 496, Max 499
Reading: Min 496, Max 499
Reading: Min 497, Max 500

--- End code ---


So seems pretty stable.... now what do you see...? 

(My suspicion is still on power rail droop confusing you)

NivagSwerdna:
Here's my example code... given that the measurements are pretty stable... within a couple...  A small state machine and different thresholds does it.

Note that for my NTC sensor the numbers increase as it gets colder and decrease as it gets hotter... A PTC sensor would do the opposite and the comparisons and thresholds would have to be the other way around.  (If you get the thresholds the wrong way round it oscillates at the switch point... maybe that is your only problem?)


--- Code: ---int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED

void setup() {
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);
}

int getTemp() {
  return analogRead(sensorPin);
}

#define STATE_HOT 1
#define STATE_COLD 2

int state = STATE_COLD;

#define THRESHOLD_COLD_TO_HOT  500
#define THRESHOLD_HOT_TO_COLD  520

void loop() {
    int current = getTemp();

    switch(state) {
      case STATE_COLD:
        if (current<THRESHOLD_COLD_TO_HOT) {
          state = STATE_HOT;
        };
        break;
      case STATE_HOT:
        if (current>THRESHOLD_HOT_TO_COLD) {
          state = STATE_COLD;
        };
        break;
    }
//    Serial.print("Reading: ");
//    Serial.print(current);
//    Serial.print(" ");
//    Serial.print(state);
//    Serial.println();

    digitalWrite(ledPin, (state == STATE_HOT) ? HIGH : LOW);
}
--- End code ---

Share & Enjoy

billbyrd1945:
I should probably throw in the towel. I have no business posting on a forum while lacking the most fundamental knowledge. It's not fair to you guys. Bryan Reagan, a stand up comedian, does a bit where he's taking very simple instructions from UPS on how to get some packages ready. After half of the first sentence, he says "Slow down!" That's me! So maybe I'll end the thread after today.

The problem in trying to help someone like me is that suggestions (do this), leads to "I don't know how to do that or what you're even talking about". While another beginner may see hysteresis as an obvious fix, I'm trying to figure out how to execute it.

Anyhow, I'm going to respond to the latest crop of generous suggestions. Any of you who see this as a lost cause can bail.

Answer to thermistor question:
75.8F = 10.72K ohms
60.1F = 14.76K ohms

Thermal control is currently off the table though as Arduino ADC output numbers are chaotic when power supply running.

Arduino is Uno Rev 3

(In addition to scrapping the original power supplies, I ditched the break out board the controlled them. That's where the Arduino comes in.)

As to my code: It's constantly changing with trial and error. The thinking was-- hit on something that works, and then figure why. I've had this wine cooler in the middle of our home office for (probably) four months. Remember, it's about the challenge, not whether the cooler is worth having in the first place.

The ideal completed project would have two Peltier elements on slightly different schedules: one for the lower half for white wine, the other for the top half for red wine (or the other way around). Additionally, there are two heat sink fans that would come on shortly after the Peltiers come on and need cooling. They might be programmed to stay on for a bit shortly after the Peltiers go off. Two more fans, one for the top half, one for the bottom half, are located in the cabinet to pull air over the cold sinks and into the cooler. Ideally, they too, would be on slightly different schedules.

As if that weren't complicated enough, There are controls on the door display to change the settings. That would be another project altogether.

What I'm shooting for now is an initial cool-down from room temp, maybe 30 minutes, and then an concessional restart of the cooler as the temp begins to rise. So, maybe, run both Peltiers and all fans (as if they were one) for 30 minutes. That seems adequate to get around 58F or so. Then, shut down for maybe 20 minutes. It seems insulated well enough to maintain a temp no greater than 62F or so. After the 20 minutes shut down, everything comes back on for ten minutes.

So, on for 30minutes; off for 20 minutes; then repeated cycles of off for 20 minutes; on for 10. Hopefully, that crude arrangement would have the cooler functional. I could go back to simple projects no bigger than the top of my work bench. In time I would master skills needed to improve the wine cooler, even the door, with proper code. Having said all that, I'm unable to go beyond mostly psuedo code as follows:

<code>

unsigned long top_fans_and_pelt = 8;//pin 8 turns on relay for top peltier and all fans
unsigned long bot_pelt = 9;//pin 9 turns on relay for 2nd peltier
unsigned long previous = 0;
int interval30 = 1800000;//30 minutes
int interval20 = 1200000;//20 minutes
int interval10 = 600000;//10 minutes

void setup(){
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}

void loop(){

current = millis();//start the clock

if(current > 0 || < 5){
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}

after 30", shut down (one time)

then off 20"
then back on 10"
repeat over and over
}//end loop

</code>

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version