Hallo an alle,
ich habe einen Temp Sensor NTC 5K an meinen Arduino angeschlossen und gebe die Temp. an ein I2c Display aus. Soweit funktionier alles.
Nun habe ich vor mit einem zweiten Temp Sensor eine zweite Temperatur anzeigen zu lassen.
Ich habe auf einem Bradboard die Schaltung ein zweites mal aufgebaut und das Datenkabel an einen anderen Analogpin angeschlossen und das Display so Programmier das es zwei Temperaturen anzeigt.
Mein Problem ist allerdings das es keine getrenten Temp anzeigen gibt.
Wenn ich Senor 1 erwärme dann steigen beide Werte im Display.
Wie bekommt man das hin, das Sensor 1 und 2 jeder seinen aktuellen Wert ausgibt?
Das ist mein verwendeter Code:
Code:
/* /* 0- General */
int decimalPrecision = 1; // decimal places for all values shown in LED Display & Serial Monitor
/* 1- Temperature Measurement */
int ThermistorPin = A1; // The analog input pin for measuring temperature
int ThermistorPin2 = A2;
float voltageDividerR1 = 10000; // Resistor value in R1 for voltage devider method
float BValue = 2500; // The B Value of the thermistor for the temperature measuring range
float R1 = 5000; // Thermistor resistor rating at based temperature (25 degree celcius)
float T1 = 298.15; /* Base temperature T1 in Kelvin (default should be at 25 degree)*/
float R2 ; /* Resistance of Thermistor (in ohm) at Measuring Temperature*/
float R3;
float T2 ; /* Measurement temperature T2 in Kelvin */
float T3 ; /* Measurement temperature T3 in Kelvin */
float a ; /* Use for calculation in Temperature*/
float b ; /* Use for calculation in Temperature*/
float c ; /* Use for calculation in Temperature*/
float d ; /* Use for calculation in Temperature*/
float e = 2.718281828 ; /* the value of e use for calculation in Temperature*/
float tempSampleRead = 0; /* to read the value of a sample including currentOffset1 value*/
float tempLastSample = 0; /* to count time for each sample. Technically 1 milli second 1 sample is taken */
float tempSampleSum = 0; /* accumulation of sample readings */
float tempSampleCount = 0; /* to count number of sample. */
float tempMean ; /* to calculate the average value from all samples, in analog values*/
/* 2 - LCD Display */
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
unsigned long startMillisLCD; /* start counting time for LCD Display */
unsigned long currentMillisLCD; /* current counting time for LCD Display */
const unsigned long periodLCD = 1000; // refresh every X seconds (in seconds) in LED Display. Default 1000 = 1 second
void setup()
{
/* 0- General */
Serial.begin(9600);
lcd.begin(); /* Tell Arduino that our LCD has 16 columns and 2 rows*/
lcd.setCursor(0,0); /* Set LCD to start with upper left corner of display*/
startMillisLCD = millis(); /* Start counting time for LCD display*/
}
void loop()
{
/* Temp L.: - Temperature Measurement */
if(millis() >= tempLastSample + 1) /* every 1 milli second taking 1 reading */
{
tempSampleRead = analogRead(ThermistorPin);
tempSampleSum = tempSampleSum+tempSampleRead; /* add all analog value for averaging later*/
tempSampleCount = tempSampleCount+1; /* keep counting the sample quantity*/
tempLastSample = millis(); /* reset the time in order to repeat the loop again*/
}
if(tempSampleCount == 1000) /* after 1000 sample readings taken*/
{
tempMean = tempSampleSum / tempSampleCount; /* find the average analog value from those data*/
R2 = (voltageDividerR1*tempMean)/(1023-tempMean); /* convert the average analog value to resistance value*/
a = 1/T1; /* use for calculation */
b = log10(R1/R2); /* use for calculation */
c = b / log10(e); /* use for calculation */
d = c / BValue ; /* use for calculation */
T2 = 1 / (a- d); /* the measured temperature value based on calculation (in Kelvin) */
Serial.print(T2 - 273.15,decimalPrecision); /* display in Serial monitor the temperature in Celcius*/
Serial.println(" °C");
tempSampleSum = 0; /* reset all the total analog value back to 0 for the next count */
tempSampleCount = 0; /* reset the total number of samples taken back to 0 for the next count*/
}
/* Temp L.: - LCD Display */
currentMillisLCD = millis(); /* Set counting time for LCD Display*/
if (currentMillisLCD - startMillisLCD >= periodLCD) /* for every x seconds, run the codes below*/
{
lcd.setCursor(0,0); /* Set cursor to first colum 0 and second row 1 */
lcd.print("Temp L.:");
lcd.print(T2 - 273.15,decimalPrecision); /* display current value in LCD in first row */
lcd.print(char(223)); /* print the symbol "degree"*/
lcd.print("C ");
startMillisLCD = currentMillisLCD ; /* Set the starting point again for next counting time */
}
{
/* Temp R.: - Temperature Measurement */
if(millis() >= tempLastSample + 1) /* every 1 milli second taking 1 reading */
{
tempSampleRead = analogRead(ThermistorPin2);
tempSampleSum = tempSampleSum+tempSampleRead; /* add all analog value for averaging later*/
tempSampleCount = tempSampleCount+1; /* keep counting the sample quantity*/
tempLastSample = millis(); /* reset the time in order to repeat the loop again*/
}
if(tempSampleCount == 1000) /* after 1000 sample readings taken*/
{
tempMean = tempSampleSum / tempSampleCount; /* find the average analog value from those data*/
R3 = (voltageDividerR1*tempMean)/(1023-tempMean); /* convert the average analog value to resistance value*/
a = 1/T1; /* use for calculation */
b = log10(R1/R3);
c = b / log10(e);
d = c / BValue ;
T3 = 1 / (a- d); /* the measured temperature value based on calculation (in Kelvin) */
Serial.print(T3 - 273.15,decimalPrecision); /* display in Serial monitor the temperature in Celcius*/
Serial.println(" °C");
tempSampleSum = 0; /* reset all the total analog value back to 0 for the next count */
tempSampleCount = 0; /* reset the total number of samples taken back to 0 for the next count*/
}
/* Temp R.: - LCD Display */
currentMillisLCD = millis(); /* Set counting time for LCD Display*/
if (currentMillisLCD - startMillisLCD >= periodLCD) /* for every x seconds, run the codes below*/
{
lcd.setCursor(0,1); /* Set cursor to first colum 0 and second row 1 */
lcd.print("Temp R.:");
lcd.print(T3 - 273.15,decimalPrecision); /* display current value in LCD in first row */
lcd.print(char(223)); /* print the symbol "degree"*/
lcd.print("C ");
startMillisLCD = currentMillisLCD ; /* Set the starting point again for next counting time */
}
}}
Nach
diesem Prinziep habe ich meine Sensoren angeschlossen, nur eben zwie mal statt nur einmal.