SD Temperaturlogger

Für Arduino


/* Libraries */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#include <EEPROM.h> // required for EEPROMAnything.h
#include "./EEPROMAnything.h"

/* Display Adresse und Connections setzen */
 LiquidCrystal_I2C lcd(0x3F, 20,4); // I2C adress, Cols, Rows

#include "./Timer.h"
Timer updateLCD(1*TIMER_SECONDS);
Timer storeValue(15*TIMER_SECONDS);
 
// Thermistor data
#define THERMISTORPIN A0        // which analog pin to connect      
#define THERMISTORNOMINAL 100000 // resistance at 25 degrees C
#define TEMPERATURENOMINAL 25   // temp. for nominal resistance (almost always 25 C)
#define NUMSAMPLES 5            // how many samples to take and average, more takes longer but is more 'smooth'
#define BCOEFFICIENT 3950       // The beta coefficient of the thermistor (usually 3000-4000)
#define SERIESRESISTOR 100000    // the value of the 'other' resistor
int samples[NUMSAMPLES];

int storePos = -1;

void setup() {
  lcd.begin(); //Display initialisieren
  lcd.backlight(); // backlight anlassen
  
  lcd.setCursor(0,0); //Zeilen und Spalten starten mit 0 -> Spalte 1 Zeile 1
  lcd.print("Temp.:");

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() {
  if(updateLCD.check()){
    int tmp = Thermistor();

    if(storePos==-1){
      
    }else if(storePos>=0 && storeValue.check()){
      
    }

    lcd.setCursor(7,0); //Spalte 8, Zeile 1
    lcd.print("   ");// reset
    lcd.setCursor(7,0); //Spalte 8, Zeile 1
    lcd.print(tmp);
   
  }
  if(Serial.available()){
    if(Serial.read()=='t'){ // Speicher auslesen und uebertragen
      for(int i=0; i<EEPROM.length(); i++){
        Serial.print(EEPROM.read(i));
        Serial.print(" ");
      }
    }
  }
}

float Thermistor(void){
  uint8_t i;
  float temp;
  for (i=0; i< NUMSAMPLES; i++) { // take N samples in a row, with a slight delay
   samples[i] = analogRead(THERMISTORPIN);
   delay(10);
  }
  temp = 0; // average all the samples out
  for (i=0; i< NUMSAMPLES; i++) {
     temp += samples[i];
  }
  temp /= NUMSAMPLES;
  temp = 1023 / temp - 1; // convert the value to resistance
  temp = SERIESRESISTOR / temp; // now temp contains the resistor
  Serial.print("Resistor "); 
  Serial.print(temp);
  Serial.println(" Ohm");
  temp = temp / THERMISTORNOMINAL;        // (R/Ro)
  temp = log(temp);                       // ln(R/Ro)
  temp /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  temp += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  temp = 1.0 / temp;                      // Invert
  temp -= 273.15;                         // convert to C
  return temp;
}


© Veit Götz 2012 - 2019
Impressum
Datenschutz
Statistiken
Spenden