Hello Scientists;
I want to measure Temperature (Surface and Air) inside a Cabinet , thus I'm using nine (9) 10k NTC Thermistors , five for the surface Temp and four for the Air Temp.
I'm using Megunolinklibrary (exactly the Exponential Filter) to smooth noisy measurements.
Sketch:
#include "MegunoLink.h"
#include "Filter.h"
#include <LiquidCrystal.h>
//LCD Vars
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
float T_Sur_avr, T_Air_avr;
//MegunoLink Vars
TimePlot Plot;
//Exponential Filter Algorithm
// the <float> makes a filter for float numbers
// 20 is the weight (20 => 20%)
// 0 is the initial value of the filter
ExponentialFilter<float> FilteredTemperatureSurface(20, 0);
ExponentialFilter<float> FilteredTemperatureAir(20, 0);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
lcd.clear();
lcd.print("*** WELCOME! ***");
lcd.setCursor(4, 1);
lcd.print("Initializing");
delay(5000); //some time for Stabilization
}
void loop()
{
//Average Surfae Temperature
T_Sur_avr = (MeasureTemperatureSurface(A0) + MeasureTemperatureSurface(A1) + MeasureTemperatureSurface(A2) + MeasureTemperatureSurface(A3) + MeasureTemperatureSurface(A4)) / 5;
Plot.SendData("Surface Temperature", T_Sur_avr); //Plot Surface Temperature via Serial on Laptop
//Average Air Temperature
T_Air_avr = (MeasureTemperatureAir(A5) + MeasureTemperatureAir(A6) + MeasureTemperatureAir(A7) + MeasureTemperatureAir(A8)) / 4;
Plot.SendData("Air Temperature", T_Air_avr); //Plot Air Temperature
//LCD Display
lcd.clear();
lcd.print("Temp Surf:");
lcd.setCursor(11, 0);
lcd.print(T_Sur_avr);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Temp Air:");
lcd.setCursor(11, 1);
lcd.print(T_Air_avr);
lcd.print((char)223);
lcd.print("C");
delay(500);
}
//TempSurf Function
float MeasureTemperatureSurface(int A)
{
int nRawThermistor = analogRead(A);
/* Constants to help conver the raw analogue measurement into
temperature in degrees Celcius
*/
const float ThermistorResistance = 10000; // Thermistor resistance at some nominal temperature
const float R = 10000;
const float NominalTemperature = 25; // The nominal temperature where resistance is known.
const float BCoefficient = 3950; // The beta coefficient of the thermistor (from data-sheet)
const float Vsupply = 5.00; // The supply voltage for the voltage divider.
const float Vref = 5.00; // Analogue reference voltage.
// Calculate the output voltage of the voltage divider; it depends on temperature.
float Vout = (float)nRawThermistor * Vref / 1023.0;
// Calculate the thermistor resistance.
float VR = Vsupply - Vout;
float Rtherm = Vout / (VR / R);;
// Convert thermistor resistance into temperature using the Steinhart equation
float Temperature;
Temperature = Rtherm / ThermistorResistance;
Temperature = log(Temperature);
Temperature /= BCoefficient;
Temperature += 1.0 / (NominalTemperature + 273.15);
Temperature = 1.0 / Temperature;
Temperature -= 273.15; // convert to C
////Exponential Filter Algorithm to Smooth Surface Temperature measurement;
FilteredTemperatureSurface.Filter(Temperature);
float SmoothTemperatureSurface = FilteredTemperatureSurface.Current();
return SmoothTemperatureSurface;
}
//TempAir Function
float MeasureTemperatureAir(int Analog)
{
int nRawThermistor = analogRead(Analog);
/* Constants to help conver the raw analogue measurement into
temperature in degrees Celcius
*/
const float ThermistorResistance = 10000; // Thermistor resistance at some nominal temperature
const float R = 10000;
const float NominalTemperature = 25; // The nominal temperature where resistance is known.
const float BCoefficient = 3950; // The beta coefficient of the thermistor (from data-sheet)
const float Vsupply = 5.00; // The supply voltage for the voltage divider.
const float Vref = 4.94; // Analogue reference voltage.
// Calculate the output voltage of the voltage divider; it depends on temperature.
float Vout = (float)nRawThermistor * Vref / 1023.0;
// Calculate the thermistor resistance.
float VR = Vsupply - Vout;
float Rtherm = Vout / (VR / R);;
// Convert thermistor resistance into temperature using the Steinhart equation
float Temperature;
Temperature = Rtherm / ThermistorResistance;
Temperature = log(Temperature);
Temperature /= BCoefficient;
Temperature += 1.0 / (NominalTemperature + 273.15);
Temperature = 1.0 / Temperature;
Temperature -= 273.15; // convert to C
////Exponential Filter Algorithm to Smooth Air Temperature measurement;
FilteredTemperatureAir.Filter(Temperature);
float SmoothTemperatureAir = FilteredTemperatureAir.Current();
return SmoothTemperatureAir;
}
Electronics:
1--->I'm using External Adapter (9v 2A) to power on Arduino Mega via Vin.
2--->from the adapter I use LM2596 DC-DC Step Down Adjustable PSU Module fixed on 5v to power the voltage divider and the LCD (qapass lcd 16*2) with a 10k potentiometer for backlight adjust.
3--->10k NTC Thermistor sensor range (-40 ℃ to +300 ℃)
4-Multimeter (Farnell tenma 72-7725)
So everything works perfectly , I just have some issues that I would learn about :
1st--->When I power the arduino with Vin without USB cable , the readings on the LCD are changing fast , if the Temp is e.g 22° C on the lcd it's showing 15° C 20 , 25 , 12 , 19°C ..
Question1: I wonder why does this happen?
2nd--->When I plug the USB cable in the laptop to plot the Temperature ,first the sketch reset,second the readings are stable , so if the Temp is 22° C , on LCD it's 22° C ±0.1 !!
Q2: why the the arduino reset when I plug the usb cable ?
And why the readings are stable?
3rd--->When I take off the USB Cable , the LCD display wierd caracters "sometimes"until I reset the Arduino or power it off than power on again to get rid of these wierd caracters !!
4th--->if the Vin is off and the USB cable is plugged , I noticed that the the backlight of the LCD is on without any caracters despite of powering the LCD from the external +5v from the LM2596 , the only cables between LCD and Arduino are ofc RS , E , (D4-D7) and GND.
Q3: how or why this happens ?
5th--->I measured the 5v and 3.3v on arduino with the multimeter and I found respectivly 4.94/4.95 and 3.24.
Q5: is there anyway to increase it to real 5v or 3.3 ?!
Thx for any help :))))