2 czujniki DHT11 oraz termistor problem! - bykol132 - 23-09-2017
Witam, jestem zielony z kodowaniem arduino, powoli się uczę i tak programowanie 1 czujnika DHT11 to nie ma problemu jednak już z 2 nie dałem rady wrzucę program jaki mam, może ktoś mi podpowie co trzbea zmienić (pokazuje mi temp i wilgotność na 1 czujniku, na 2 mam -7 i -7)
natomiast co to termistora mam program który za chiny nie wiem czemu nie działa..
cały czas pokazuje mi komunikat :
Average analog reading 1023.00
Thermistor resistance inf
Temperature -273.15 *C
2 czujniki
Kod: /*
Board int.0 int.1 int.2 int.3 int.4 int.5
Uno, Ethernet 2 3
Mega2560 2 3 21 20 19 18
Leonardo 3 2 0 1
Due (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
This example, as difference to the other, make use of the new method acquireAndWait()
*/
#include <idDHT11.h>
int idDHT11pin = 3; //Digital pin for comunications
int idDHT11intNumber = 1; //interrupt number (must be the one that use the previus defined pin (see table above)
int idDHT12pin = 2; //Digital pin for comunications
int idDHT12intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
//declaration
void dht11_wrapper(); // must be declared before the lib initialization
void dht12_wrapper();
// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
idDHT11 DHT12(idDHT12pin,idDHT12intNumber,dht12_wrapper);
void setup()
{
Serial.begin(9600);
Serial.println("idDHT11 Example program");
Serial.print("LIB version: ");
Serial.println(IDDHT11LIB_VERSION);
Serial.println("---------------");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapper() {
DHT11.isrCallback();
}
void dht12_wrapper() {
DHT11.isrCallback();
}
void loop()
{
Serial.print("Wilgotnosc (%): ");
delay(100);
int result = DHT11.acquireAndWait();
switch (result)
Serial.print("Wilgotnosc (%): ");
Serial.println(DHT11.getHumidity(), 2);
Serial.print("Temperatura (oC): ");
Serial.println(DHT11.getCelsius(), 2);
delay(2000);
Serial.print("Wilgotnosc (%): ");
Serial.println(DHT12.getHumidity(), 2);
Serial.print("Temperatura (oC): ");
Serial.println(DHT12.getCelsius(), 2);
delay(2000);
}
termistor
Kod: // which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 8
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
//------------------------------------------------------------------
const int temperatura_wlaczenia = 27; // PRZEKAZNIK PODLACZ POD PIN 13 (CYFROWY)
const int temperatura_wylaczenia = 30;
//-------------------------------------------------------------------
int samples[NUMSAMPLES];
void setup(void) {
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop(void) {
uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i = 0; i < NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i = 0; i < NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
Serial.print("Average analog reading ");
Serial.println(average);
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
Serial.print("Thermistor resistance ");
Serial.println(average);
float steinhart;
steinhart = average / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" *C");
pinMode(13, OUTPUT);
if (steinhart <= temperatura_wlaczenia)
{
digitalWrite(13, HIGH);
}
if (steinhart > temperatura_wylaczenia)
{
digitalWrite(13, LOW);
};
delay(1000);
}
RE: 2 czujniki DHT11 oraz termistor problem! - -adamek - 23-09-2017
Tak spytam czy to z dwoma czujnikami się kompiluje ?
Do poczytania http://cpp0x.pl/kursy/Kurs-C++/Poziom-1/Warunek-wielokrotnego-wyboru-switch-case/17
RE: 2 czujniki DHT11 oraz termistor problem! - bykol132 - 23-09-2017
tak kompiluje się
RE: 2 czujniki DHT11 oraz termistor problem! - krn78 - 18-10-2017
A termistor... jesteś pewien, że użyłeś poprawnego? Mam na myśli, że potrzebujesz NTC, a używasz PTC lub odwrotnie.
|