Arduino question: unstable signal - Page 1
Forum section: electronics / general

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 17, 2019, 04:04:59 pm
content: I have built the circuit shown in the attached diagram. An if statement tells the LED to come on when the ADC number drops below a certain number. It works. The LED will eventually be replaced with relays controlling a network of fans and Peltier cooling elements for a wine cooler. My problem is that the LED (or relay) flashes off and on when approaching the desired number, then it finally becomes completely on or completely off. I've read about some complicated methods for using 3.3v, but they involve inner workings that I simply don't understand yet. I am using the smoothing method, but seems of very little help if any. Is there a simpler way? I was hoping maybe a well placed cap or something like that might work. Any help will be appreciated.PS: Using Uno V3

author: WildMOSFET
author_rank: Contributor
timestamp: March 17, 2019, 04:14:48 pm
content: Add a ten microfarad electrolytic capacitor in parallel with the resistance.And take an average of the readings.For example, take ten readings with a for cycle, add them all up and divide them by 10.For each reading, you need to add a small delay, for example 10 milliseconds.I have an example code, it is in Italian but I believe that the logic is understood the same.Code:float LetturaMediaTensione(int n_letture){unsigned int valore = 0;float tensione = 0;for(int i=0; i<n_letture; i++){valore += analogRead(A0);delay(10);}tensione = (valore/n_letture)*(300.0/1024.0);return tensione;}

author: djacobow
author_rank: Super Contributor
timestamp: March 17, 2019, 04:40:35 pm
content: Averaging, as described by another poster will help, but in theory even with averaging, the value will hover around your switch point. If you have a control loop, then it *will* hover around your switch point, and you will get a lot of annoying transitions.The normal way to deal with this is to add some hysteresis to your control, so that there is a bit of a dead band. You do this by making the turn on value a bit lower than the turn off value.Something like:Code:const uint16_t switch_point = 1234;const uint16_t half_dead_band = 5;bool getOutputState(uint16_t input) {static bool curent_state = false;if (input < (switch_point - half_dead_band)) current_state = true;else if (input > (switch_point + half_dead_band)) current_state = false;return current_state;}I didn't test this, but you get the idea.

author: WildMOSFET
author_rank: Contributor
timestamp: March 17, 2019, 04:48:56 pm
content: Quote from: djacobow on March 17, 2019, 04:40:35 pmYou made the idea right.Hysteresis is also important, otherwise the wine cooler would almost always be in operation, with short breaks.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 17, 2019, 09:19:42 pm
content: Thanks guys! Over time, I will explore averaging and hysteresis as I want to learn everything. But-- lucky me: I found another solution that seems to be dead-nuts perfect. I abandoned the thermistor and voltage divider, and the need for some kind of stabilization for a TMP36 temp sensor. It will mean pulling the two-conductor wires out of the cooler and letting a three-conductor be pulled in behind them. But that's a small price to pay for excellent performance. Thanks again!

author: Arznei
author_rank: Contributor
timestamp: March 17, 2019, 09:48:25 pm
content: I'm afraid you will run into the same problems you are having right now even using the TMP36. The problem you are having is not (only) an unstable or inaccurate output of your current sensor, but also the inherent noise of your ADC. Even with a perfectly stable voltage input your ADC readings might have their last bit or more flipping from reading to reading.Adding a small hysteresis is a pretty simple and working solution to that. Don't be afraid of it sounding somewhat complicated, it's actually easy to implement and will work like a treat, probably even with your original circuit.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 18, 2019, 03:24:41 am
content: "Adding a small hysteresis is a pretty simple and working solution to that. Don't be afraid of it sounding somewhat complicated, it's actually easy to implement and will work like a treat, probably even with your original circuit."Alright then. I won't kick that can down the road. How can I introduce hysteresis into the original circuit? And thank you.

author: Mr.B
author_rank: Unknown
timestamp: March 18, 2019, 03:30:55 am
content: Quote from: billbyrd1945 on March 18, 2019, 03:24:41 amYou don't introduce it to the circuit as such.You introduce it to the code.See the code @djacobow posted above.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 18, 2019, 03:40:43 am
content: I had edited the response about "introducing"...I explained what confused me aboutdjacobow'ssuggestion. But when I tried to send it, I got the red warning that I should read a new reply. By doing so, I lost my post. I hate it when that happens. Basically, I was just saying that I didn't understand how you can alter your IF statement on and off times beyond the desired temperatures.

author: Mr.B
author_rank: Unknown
timestamp: March 18, 2019, 03:48:58 am
content: Pseudo code:Code:Hysteresis = 5 degrees.SetPoint = 30 degrees.IF Temperature > (SetPoint + Hysteresis) THEN turn_cooler_onIF Temperature < (SetPoint - Hysteresis) THEN turn_cooler_offSo, what happens is the cooler comes on at 35 degrees and stays on until the temperature drops to 25 degrees.This way the on/off control is never dependent upon a single exact number. It will only switch the cooler at points that are miles apart from each other and therefore reasonably immune to ADC noise.Note: The narrower your Hysteresis band, the more your cooler will be turning on and off.

author: Kasper
author_rank: Frequent Contributor
timestamp: March 18, 2019, 04:17:23 am
content: Hysteresis is standard solution to stop jitter for all sorts of things.Specially when you are controlling machines, since jittering means machines starting and stopping much more often than needed and getting worn out faster because of it.temperature = GetTemperature();If (temperature > 20): TurnOnCooler();Elseif (temperature < 10): TurnOffCooler();

author: djacobow
author_rank: Super Contributor
timestamp: March 18, 2019, 08:29:12 am
content: It sounds like the OP is a bit confused or wants to limit his complexity in this project. I understand that, but there are certain things that it's definitely worth understanding if you are going to do more projects that interface electronics with physical reality.Physical reality is noisy, bumpy, and shaky. When you measure something you get noise. When you move something it often has "backlash", and it may even oscillate before settling. Because of all these phenomenon, you need to make your programs a bit more tolerant of slop. That's what hysteresis is about: it's creating logic so that there is some "space" between what causes your program to "do something" and to "undo that thing."Without hysteresis, your program will spend a lot of time doing and undoing for no particular benefit.Three people have provided you code or pseudocode now. What are you confused about?PS -- regarding averaging. It's great to average. You should almost always do it, whether you're reading from an ADC or your sampling device like the TMP36 is doing that for you. If you're measuring temperature, an instantaneous reading problem doesn't matter much anyway.There are lots of ways to average, but in microcontroller-land where time and memory are scarce, there is a cheap averaging you should always have in your toolkit, called an exponential moving average filter a.k.a. first-order low-pass IIR filter. Google and you should see examples of how to do it; it's very simple and cheap to calculate and requires only on variable for state.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 18, 2019, 11:59:31 am
content: Okay. I'm sorry if I seen stubborn about the hysteresis. Actually, I'm not. There's no way I would decline a solution. I will definitely implement it into the code. If I can use existing thermistors rather than fish in a third wire and and new sensors-- I'm a happy man. The only thing I didn't understand was how hysteresis was anything more than the period between off and on. But I'm sure it is or you guys wouldn't have offered it up. Now I'm excited about giving it a whirl. I will report back for sure!

author: TK
author_rank: Super Contributor
timestamp: March 18, 2019, 12:56:19 pm
content: Quote from: Mr.B on March 18, 2019, 03:30:55 amYou can introduce hysteresis control in your circuit or code, depending on your background knowledge (Hardware vs Software person)

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 18, 2019, 01:02:34 pm
content: Peltier? Seriously?

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 18, 2019, 02:32:43 pm
content: "Peltier? Seriously?"I realize that no one would think of Peltier as the ideal cooling mechanism. But that's what I happen to have. We bought a wine chiller about five years ago. The two power supplies went belly up. I worked diligently to repair the boards but simply didn't have the knowledge required. So, now I'm replacing the two power supplies with one off-the-shelf unit with enough current to power the two Peltiers (one for the top of the cabin, one for the bottom). I'm sure I've got several hundred hours and some cash invested in repairing it. I knew from the get-go that it wasn't cost feasible. Instead-- I looked at it as a learning experience. But replacing the power supplies was only part of the fix. I had to find someway to marry it to a small break-out board. After failing at that I thought I might have enough Arduino experience to use an Uno to manage the system. I knew I could produce a high and low state to turn on an LED. So why not substitute the LED with Peltiers (going through relays). And shazam! I was actually able to pull it off with the exception of the bouncing back and forth which had the test relay buzzing around on my desk. So, now, I'll Google hysteresis as it applies to writing a proper sketch. If all goes well-- I'll have my wine cooler back, my wife will think I'm a genius, and only you and I will know that Peltiers are the most next-to-nothing cooling devices known to man.PS: Volunteers to write the sketch will not be turned away. Top and bottom cabin chill to 60F. A fan for each Peltier comes on after enough heat is produced to warrant cooling them. They stay on for a short while after the Peltier is turned off. Another fan inside the cabin comes on with the Peltier (to draw in cool air). It stays on for a while after the Peltier goes low (to pull in air from the still-cold element).

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 18, 2019, 04:30:10 pm
content: Quote from: billbyrd1945 on March 18, 2019, 02:32:43 pmIMHO... bin it!

author: djacobow
author_rank: Super Contributor
timestamp: March 18, 2019, 04:41:06 pm
content: Quote from: NivagSwerdna on March 18, 2019, 04:30:10 pmOh come on now, he's doing it for fun and learning.There is probably no more project more "Arduino" than your first thermostatically-controlled doohickey.He's needs to write like 10 lines of code and he's in business.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 18, 2019, 05:00:59 pm
content: Quote from: djacobow on March 18, 2019, 04:41:06 pmI know... I feel guilty saying it but Peltier fridges are just ****. Imagine if he nips out and buys a compressor based cooler... he will be able to cool a nice bottle of wine and then sip contentedly (knowing the performance and operating costs are going to be better) whilst working on a more useful project.It's a bit like saying, building a solar roadway is a learning experience.... but...If he insists... considering using an internal ARef (depends on which Arduino is being employed) and then the techniques listed above. Also consider cooling for the peltier element and having the fan overrun to stop heat from the hot side migrating into the cooler when the element is off - Already mentioned but important.

author: Mr.B
author_rank: Unknown
timestamp: March 18, 2019, 06:40:20 pm
content: Quote from: TK on March 18, 2019, 12:56:19 pmYes, you are correct.However, in this specific case I would suggest the OP will find it considerably easier to introduce it in code.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 21, 2019, 04:56:19 pm
content: 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 convertdjacobow'shysteresis 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 convertdjacobow'sexample 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.

author: Kasper
author_rank: Frequent Contributor
timestamp: March 22, 2019, 03:21:44 pm
content: If you post your code, it will be easier for people to recommend ways to add hysteresis.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 22, 2019, 03:59:19 pm
content: 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 potentiometerint ledPin = 13; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorvoid setup() {Serial.begin(9600);pinMode(ledPin, OUTPUT);}#define SIZE 512int j=0;int i = 0;int n = 0;int readings;void loop() {digitalWrite(ledPin, HIGH);// read the value from the sensor:sensorValue = analogRead(sensorPin);readings = sensorValue;i++;i %= SIZE;if (n<SIZE) n++;j++;if (j==10000) {int min=readings;int max=readings;for (int k=0; k<SIZE; k++) {if (readings<min) min=readings;if (readings>max) max=readings;}Serial.print("Reading: Min ");Serial.print(min);Serial.print(", Max ");Serial.print(max);Serial.println();j=0;}// turn the ledPin ondigitalWrite(ledPin, LOW);}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 533Reading: Min 532, Max 533Reading: Min 531, Max 533Reading: Min 531, Max 533Reading: Min 531, Max 533Reading: Min 532, Max 533Reading: Min 532, Max 533Reading: Min 532, Max 533Reading: Min 531, Max 533Reading: Min 532, Max 533Reading: Min 531, Max 533Reading: Min 531, Max 533Started warming NTC....Reading: Min 531, Max 534Reading: Min 530, Max 533Reading: Min 528, Max 532Reading: Min 514, Max 518Reading: Min 503, Max 506Reading: Min 492, Max 497Reading: Min 486, Max 489Reading: Min 480, Max 483Reading: Min 474, Max 478Reading: Min 470, Max 474Reading: Min 467, Max 471Reading: Min 463, Max 467Reading: Min 460, Max 465Reading: Min 458, Max 463Reading: Min 455, Max 459Reading: Min 453, Max 457Reading: Min 451, Max 455Reading: Min 449, Max 453Reading: Min 448, Max 452Reading: Min 446, Max 450Reading: Min 444, Max 449Reading: Min 443, Max 448Reading: Min 442, Max 445Reading: Min 443, Max 445Reading: Min 445, Max 447Reading: Min 447, Max 448Reading: Min 447, Max 450Reading: Min 448, Max 452Let go of NTC...Reading: Min 451, Max 452Reading: Min 453, Max 454Reading: Min 454, Max 456Reading: Min 455, Max 456Reading: Min 455, Max 458Reading: Min 456, Max 458Reading: Min 457, Max 459Reading: Min 458, Max 460Reading: Min 459, Max 461Reading: Min 460, Max 461Reading: Min 460, Max 462Reading: Min 461, Max 462Reading: Min 461, Max 464Reading: Min 462, Max 464Reading: Min 463, Max 464Reading: Min 463, Max 465Reading: Min 464, Max 465Reading: Min 464, Max 466Reading: Min 464, Max 466Reading: Min 464, Max 467Reading: Min 466, Max 467Reading: Min 466, Max 468Reading: Min 466, Max 468Reading: Min 467, Max 469Reading: Min 467, Max 469Reading: Min 468, Max 469Reading: Min 468, Max 470Reading: Min 469, Max 470Reading: Min 469, Max 471Reading: Min 469, Max 471Reading: Min 469, Max 471Reading: Min 469, Max 472Reading: Min 471, Max 472Reading: Min 471, Max 472Reading: Min 471, Max 472Reading: Min 471, Max 473Reading: Min 472, Max 474Reading: Min 471, Max 474Reading: Min 473, Max 474Reading: Min 473, Max 474Reading: Min 473, Max 475Reading: Min 473, Max 475Reading: Min 473, Max 476Reading: Min 474, Max 476Reading: Min 475, Max 476Reading: Min 475, Max 477Reading: Min 475, Max 477Reading: Min 476, Max 477Reading: Min 475, Max 478Reading: Min 476, Max 478Reading: Min 477, Max 478Reading: Min 477, Max 478Reading: Min 477, Max 479Reading: Min 477, Max 479Reading: Min 477, Max 479Reading: Min 478, Max 480Reading: Min 478, Max 480Reading: Min 478, Max 480Reading: Min 479, Max 480Reading: Min 479, Max 481Reading: Min 479, Max 481Reading: Min 480, Max 481Reading: Min 480, Max 482Reading: Min 481, Max 482Reading: Min 480, Max 482Reading: Min 481, Max 483Reading: Min 480, Max 483Reading: Min 481, Max 483Reading: Min 482, Max 484Reading: Min 482, Max 484Reading: Min 483, Max 484Reading: Min 483, Max 485Reading: Min 484, Max 485Reading: Min 484, Max 486Reading: Min 483, Max 486Reading: Min 485, Max 486Reading: Min 485, Max 487Reading: Min 485, Max 487Reading: Min 485, Max 487Reading: Min 486, Max 487Reading: Min 486, Max 487Reading: Min 486, Max 488Reading: Min 486, Max 488Reading: Min 487, Max 488Reading: Min 486, Max 489Reading: Min 486, Max 490Reading: Min 487, Max 489Reading: Min 487, Max 489Reading: Min 487, Max 490Reading: Min 488, Max 490Reading: Min 488, Max 490Reading: Min 489, Max 490Reading: Min 488, Max 490Reading: Min 489, Max 491Reading: Min 489, Max 491Reading: Min 489, Max 491Reading: Min 490, Max 491Reading: Min 490, Max 492Reading: Min 489, Max 492Reading: Min 490, Max 492Reading: Min 490, Max 492Reading: Min 490, Max 492Reading: Min 491, Max 493Reading: Min 491, Max 493Reading: Min 491, Max 493Reading: Min 492, Max 493Reading: Min 492, Max 494Reading: Min 492, Max 494Reading: Min 491, Max 494Reading: Min 493, Max 494Reading: Min 492, Max 494Reading: Min 493, Max 495Reading: Min 493, Max 495Reading: Min 493, Max 495Reading: Min 493, Max 496Reading: Min 494, Max 496Reading: Min 494, Max 495Reading: Min 493, Max 496Reading: Min 495, Max 496Reading: Min 495, Max 496Reading: Min 494, Max 497Reading: Min 494, Max 497Reading: Min 495, Max 497Reading: Min 495, Max 497Reading: Min 494, Max 497Reading: Min 496, Max 498Reading: Min 496, Max 498Reading: Min 496, Max 498Reading: Min 496, Max 498Reading: Min 496, Max 498Reading: Min 496, Max 499Reading: Min 496, Max 499Reading: Min 496, Max 499Reading: Min 497, Max 499Reading: Min 496, Max 499Reading: Min 496, Max 499Reading: Min 497, Max 500So seems pretty stable.... now what do you see...?(My suspicion is still on power rail droop confusing you)

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 22, 2019, 06:22:02 pm
content: 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 potentiometerint ledPin = 13; // select the pin for the LEDvoid setup() {Serial.begin(9600);pinMode(ledPin, OUTPUT);}int getTemp() {return analogRead(sensorPin);}#define STATE_HOT 1#define STATE_COLD 2int state = STATE_COLD;#define THRESHOLD_COLD_TO_HOT 500#define THRESHOLD_HOT_TO_COLD 520void 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);}Share & Enjoy

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 24, 2019, 03:05:56 pm
content: 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 ohms60.1F = 14.76K ohmsThermal 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 fansunsigned long bot_pelt = 9;//pin 9 turns on relay for 2nd peltierunsigned long previous = 0;int interval30 = 1800000;//30 minutesint interval20 = 1200000;//20 minutesint interval10 = 600000;//10 minutesvoid setup(){pinMode(8,OUTPUT);pinMode(9,OUTPUT);}void loop(){current = millis();//start the clockif(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>

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 24, 2019, 09:54:05 pm
content: 75.8F = 10.72K ohms60.1F = 14.76K ohmsApart from those quaint F units looks very like my thermister above... Resistance increases as it gets colder... NTC... and around 10k at 25CIt must be a power supply issue. Try powering the Arduino from a seperate 9V wall wart. Use my sketch above with your Arduino away from the rest with just 10k fixed resistor and the thermister as a voltage divider between 5V and GND... then report back. I think I used A0 on an UNO clone.PSI see you have start to think about timing...current = millis();Just be aware that millis() being 1000th of a second... is not continuous...https://www.arduino.cc/reference/en/language/functions/time/millis/it wraps... and your code should handle that.PPSDon't feel guilty about asking simple questions; it's that type we have a chance of answering... the tricky ones we leave to the experts.

author: billbyrd1945
author_rank: Regular Contributor
timestamp: March 25, 2019, 01:15:17 am
content: EUREKA!It worked! Thank you a million times!There are a couple more tweaks needed: The code provides two states. I would need a third one for a long transition from off to the first cool down. The cooler is so well insulated that I may not need it though. It may be able to function well with only short ons, long offs, gradually getting cool enough and able to hold it when off.The other thing is that there is some on/off behavior between full off and full on. It's so regular, it looks like a blink program. Too many number changes take place on the way to getting inside a window of solidly on or solidly off. I plugged in a three second delay in order to get a good look at the numbers. And I had to change the code settings from 500/520 to 768/762.The behavior is as follows:>768: solidly off<768 and > 762: blink program<=762: solidly onI didn't concern myself with actual cooler temps as I'm confident that moving the numbers up and down will take care of that. The fantastic thing is that the program actually works AND, I get to use the thermistors that I had completely given up on! The only problem with them is noise from the power supply I ordered. The testing tonight was with my bench supply that produces no noise. But that's another issue all together.I'm a happy man if I can get the blinking to go away. Then, all I'll need is some means of killing the noise from my power supply.Is there some way to put averaging in the program? I'm almost afraid to touch it. But I will though. Gotta try. I'll just keep a copy of this one. Or you can send an updated code if you would be so kind.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 25, 2019, 08:46:34 am
content: The blinking will be because your thresholds and or conditions are the wrong way around. (or your thresholds are too close relative to noise)Now welcome to the interesting part....In compressor fridges there are a number of trade offs so for example many start stops is a bad thing so parameters like minimum off time or max continuous on time can be considered. Also ice builds up on the cooling elements so at some points they stop cooling and let the ice melt perhaps by using a heating element (and typically lie to the user about their temperature).Have a Google for the instruction manual for an elliwell controller to get an idea for the sort of parameters.Cheers!PSAveraging isn't your problem. Averaging might allow you to eliminate some Gaussian wobble but it won't help if you have droopy signals because the ADC reference is moving. You could consider using a better reference, possibly an internal AVR one or fix your power supply to the controller. I have seen this with a design of a circuit that drove multiple servos and the designer was stumped that the circuit behaved badly when the motors ran leading to brownouts, confusion and general mayhem.

author: StillTrying
author_rank: Super Contributor
timestamp: March 25, 2019, 10:19:26 am
content: Quote from: billbyrd1945 on March 25, 2019, 01:15:17 amIt's very easy to test some averaging, just replace the the single analogRead() with 4 summed and then divided by 4, you can put it into a loop later. I think averaging will help even if it's supply noise. If your ADC value's noise is only +/- 3 counts that's not terribly bad.value = analogRead(sensorPin);delay(4);value += analogRead(sensorPin);delay(4);value += analogRead(sensorPin);delay(4);value += analogRead(sensorPin);value = value/4;

author: TK
author_rank: Super Contributor
timestamp: March 25, 2019, 12:33:50 pm
content: When dealing with thresholds, it is better to go with min/max rather than average. Measure the min and max for N measurements, then set your on/off thresholds based on those values