PHP Dashboard für HmIP Smartmeter
09.10.2024
Elektronik | Funk | Software
Der Technik-Blog
Beispielcode vom Projekt PT100 Temperatur messen mit dem Arduino. Dieser Beispielcode gibt die gemessenen Temperaturwerte im Serial Monitor aus.
Hauptartikel: PT100 Temperaturmessung mit dem Arduino
Beispielcode PT100 Arduino (LC-Display)
//More information about this project can be find here: https://www.aeq-web.com/pt100-temperature-sensor-arduino-r-u-converter/ const int pt100Pin = A0; // Define PT100 input pin const float offset = -0.00; // Offset (depending on the line resistance) // Define known points (voltage & temperature) const float voltages[] = { 0.079, 0.56, 1.04, 1.99, 2.95 }; // Voltages in Volts const float temperatures[] = { 0, 25.0, 50.0, 100.0, 150.0 }; // Temperatures in Celsius const int numPoints = sizeof(voltages) / sizeof(voltages[0]); // Linear interpolation float interpolate(float x, float x0, float x1, float y0, float y1) { return y0 + (y1 - y0) * (x - x0) / (x1 - x0); } // Calculate temperature from voltage float calculateTemperature(float voltage) { // Set to 0°C if voltage is higher than max. known point if (voltage > voltages[numPoints - 1]) { return 0; } // Find limits for interpolation int i = 0; while (voltage > voltages[i + 1] && i < numPoints - 1) { i++; } // Interpolate between limits return interpolate(voltage, voltages[i], voltages[i + 1], temperatures[i], temperatures[i + 1]); } void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(pt100Pin); float voltage = sensorValue * (5.0 / 1023.0); float temperature = calculateTemperature(voltage)+offset; Serial.print("Voltage: "); Serial.print(voltage, 3); Serial.print("V, Temperature: "); Serial.print(temperature, 1); Serial.println("°C"); delay(1000); }
STM Boards programmieren mit dem Arduino IDE - Alle Infos zur Einrichtung und Installation der Boards, Treiber und Bibliotheken
WeiterlesenAEQ-WEB © 2015-2024 All Right Reserved