Arduino coby termostat
Napsal: 30 led 2015, 19:05
http://www.ebastlirna.cz/modules.php?na ... le&u=35121
Jsem to já ztratil sem heslo k e-mailový schránce.
http://arduino.cz/termostat-s-raspberry-pi/
Ahoj, zajímalo by mě, zda by se tento program v Pythonu dal nějak překonvertovat do prostředí Arduina. Pokud nedal, potřebuji vysvětlit princip funkce tohoto programu (je to nějaký jiný vzorek, uzpůsobený přímo pro Arduino, který mi ale přijde velice skromný):
/*
Temperature Sensor
Reads an Analog Devices TMP36GT9Z-ND or AD22100 temperature sensor on analog pin 0
and converts the voltage value to temperature.
Connect Pin 1 to 5 V.
Connect Pin 2 to A0.
Connect Pin 3 to Gnd.
*/
//#if defined(ARDUINO) && ARDUINO >= 100
// #include "Arduino.h"
// #else
// #include "WProgram.h"
// #endif
int TsensorPin = A0; // select the input pin for the sensor
int ledPin = 13; // select the pin for the LED
int wait = 500; // 1/2 wait time between measurements
double temperature = 0.0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(TsensorPin, INPUT); // and set pins to input.
pinMode(ledPin, OUTPUT); // Set Temperature Sensor Pin
Serial.begin (115200); // Set up the Serial Connection.
Serial.println("Reading the Temperature Sensor"); // Greet user.
}
void loop() {
temperature = TMP36GT_AI_value_to_Celsius(analogRead(TsensorPin)); // read temperature
// temperature = AD22100K_AI_value_to_Celsius(analogRead(TsensorPin)); // read temperature
Serial.print("Temperature read (C): ");
Serial.println(temperature,2); // write temperature to Serial
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(wait); // stop the program for <wait> milliseconds:
digitalWrite(ledPin, LOW); // turn the ledPin off:
delay(wait); // stop the program for for <wait> milliseconds:
}
double TMP36GT_AI_value_to_Celsius(int AI_value)
{ // Convert Analog-input value to temperature
float voltage;
voltage = AI_value * (5000.0/1024); // Sensor value in mV:
return ((voltage -750) /10) +25; // Temperature according to datasheet: 750 mV = 25 °C
// 10 mV / °C
}
double AD22100K_AI_value_to_Celsius(int AI_value)
{ // Convert Analog-input value to temperature
float voltage;
voltage = AI_value * (5000.0/1024); // Sensor value in mV:
return (voltage -1375) /22.5; // Temperature according to datasheet: 1.375 V <-> 0 °C
// 22.5 mV / °C; Ratiometric measurement, conversion valid for 5 V!
}
Jsem to já ztratil sem heslo k e-mailový schránce.
http://arduino.cz/termostat-s-raspberry-pi/
Ahoj, zajímalo by mě, zda by se tento program v Pythonu dal nějak překonvertovat do prostředí Arduina. Pokud nedal, potřebuji vysvětlit princip funkce tohoto programu (je to nějaký jiný vzorek, uzpůsobený přímo pro Arduino, který mi ale přijde velice skromný):
/*
Temperature Sensor
Reads an Analog Devices TMP36GT9Z-ND or AD22100 temperature sensor on analog pin 0
and converts the voltage value to temperature.
Connect Pin 1 to 5 V.
Connect Pin 2 to A0.
Connect Pin 3 to Gnd.
*/
//#if defined(ARDUINO) && ARDUINO >= 100
// #include "Arduino.h"
// #else
// #include "WProgram.h"
// #endif
int TsensorPin = A0; // select the input pin for the sensor
int ledPin = 13; // select the pin for the LED
int wait = 500; // 1/2 wait time between measurements
double temperature = 0.0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(TsensorPin, INPUT); // and set pins to input.
pinMode(ledPin, OUTPUT); // Set Temperature Sensor Pin
Serial.begin (115200); // Set up the Serial Connection.
Serial.println("Reading the Temperature Sensor"); // Greet user.
}
void loop() {
temperature = TMP36GT_AI_value_to_Celsius(analogRead(TsensorPin)); // read temperature
// temperature = AD22100K_AI_value_to_Celsius(analogRead(TsensorPin)); // read temperature
Serial.print("Temperature read (C): ");
Serial.println(temperature,2); // write temperature to Serial
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(wait); // stop the program for <wait> milliseconds:
digitalWrite(ledPin, LOW); // turn the ledPin off:
delay(wait); // stop the program for for <wait> milliseconds:
}
double TMP36GT_AI_value_to_Celsius(int AI_value)
{ // Convert Analog-input value to temperature
float voltage;
voltage = AI_value * (5000.0/1024); // Sensor value in mV:
return ((voltage -750) /10) +25; // Temperature according to datasheet: 750 mV = 25 °C
// 10 mV / °C
}
double AD22100K_AI_value_to_Celsius(int AI_value)
{ // Convert Analog-input value to temperature
float voltage;
voltage = AI_value * (5000.0/1024); // Sensor value in mV:
return (voltage -1375) /22.5; // Temperature according to datasheet: 1.375 V <-> 0 °C
// 22.5 mV / °C; Ratiometric measurement, conversion valid for 5 V!
}