switch to DHT22
This commit is contained in:
parent
8c1ec36a31
commit
d31a52f5ac
@ -12,15 +12,15 @@
|
||||
platform = atmelavr
|
||||
board = attiny85
|
||||
framework = arduino
|
||||
lib_extra_dirs =
|
||||
../libraries
|
||||
~/Arduino/libraries
|
||||
lib_deps =
|
||||
adafruit/Adafruit Unified Sensor @ ^1.1.4
|
||||
adafruit/DHT sensor library@^1.4.3
|
||||
lib_extra_dirs =
|
||||
../libraries
|
||||
~/Arduino/libraries
|
||||
upload_protocol = stk500v1
|
||||
; each flag in a new line
|
||||
upload_flags =
|
||||
-P$UPLOAD_PORT
|
||||
-b$UPLOAD_SPEED
|
||||
|
||||
; edit these lines
|
||||
upload_flags =
|
||||
-P$UPLOAD_PORT
|
||||
-b$UPLOAD_SPEED
|
||||
upload_port = /dev/ttyACM0
|
||||
upload_speed = 19200
|
||||
|
||||
@ -1,39 +1,35 @@
|
||||
#include <Arduino.h>
|
||||
#include <TempSensor.h>
|
||||
#include <HumiditySensor.h>
|
||||
#include <TinyPower.h>
|
||||
#include <SoftwareSerial_Tiny.h>
|
||||
#include <DHT.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#define SEND_INTERVAL (int)(5*60/8)
|
||||
#define SEND_VCC_INTERVAL (int)(60*60/8)
|
||||
|
||||
// Pins
|
||||
#define TEMP_POSITIVE PIN_B3
|
||||
#define SENDER PIN_B2
|
||||
#define TEMP_PIN A2
|
||||
#define DHT_PIN PIN_B4
|
||||
|
||||
#if DEBUG
|
||||
#define RxD PIN_B3
|
||||
#define TxD PIN_B4
|
||||
SoftwareSerial AttinySerial(RxD, TxD);
|
||||
#endif
|
||||
struct DhtValues {
|
||||
int temperature;
|
||||
int humidity;
|
||||
};
|
||||
DhtValues readTemp();
|
||||
|
||||
int readTemp();
|
||||
|
||||
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||
TempSensor tempSensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||
HumiditySensor humidSensor = HumiditySensor(TEMP_SENSOR, SENDER);
|
||||
DHT dht(DHT_PIN, DHT22);
|
||||
|
||||
volatile int counter = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
#if DEBUG
|
||||
AttinySerial.begin(9600);
|
||||
AttinySerial.println("starting...");
|
||||
#endif
|
||||
sensor.setup();
|
||||
analogReference(INTERNAL);
|
||||
tempSensor.setup();
|
||||
pinMode(TEMP_POSITIVE, OUTPUT);
|
||||
digitalWrite(TEMP_POSITIVE, LOW);
|
||||
digitalWrite(TEMP_POSITIVE, HIGH);
|
||||
dht.begin();
|
||||
|
||||
TinyPower::setup();
|
||||
TinyPower::enableWdt(WDTO_8S);
|
||||
@ -41,35 +37,28 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
if (counter % SEND_VCC_INTERVAL == 0) {
|
||||
sensor.sendTempAndVoltage(readTemp());
|
||||
DhtValues values = readTemp();
|
||||
tempSensor.sendTempAndVoltage(values.temperature);
|
||||
delay(100);
|
||||
humidSensor.sendHumidity(values.humidity);
|
||||
counter = 0;
|
||||
} else if (counter % SEND_INTERVAL == 0) {
|
||||
sensor.sendTemp(readTemp());
|
||||
DhtValues values = readTemp();
|
||||
tempSensor.sendTemp(values.temperature);
|
||||
delay(100);
|
||||
humidSensor.sendHumidity(values.humidity);
|
||||
}
|
||||
TinyPower::sleep();
|
||||
}
|
||||
|
||||
int readTemp() {
|
||||
DhtValues readTemp() {
|
||||
digitalWrite(TEMP_POSITIVE, HIGH);
|
||||
delay(10);
|
||||
int reading = analogRead(TEMP_PIN);
|
||||
DhtValues dhtValues;
|
||||
dhtValues.temperature = roundf(dht.readTemperature() * 10);
|
||||
dhtValues.humidity = roundf(dht.readHumidity() * 10);
|
||||
digitalWrite(TEMP_POSITIVE, LOW);
|
||||
#if DEBUG
|
||||
AttinySerial.println(reading);
|
||||
#endif
|
||||
|
||||
float voltage = reading * (1100 / 1024.0);
|
||||
#if DEBUG
|
||||
AttinySerial.print(voltage);
|
||||
AttinySerial.println(" mili volts");
|
||||
#endif
|
||||
|
||||
float temperatureC = (voltage - 500) / 10;
|
||||
#if DEBUG
|
||||
AttinySerial.print(temperatureC);
|
||||
AttinySerial.println(" degrees C");
|
||||
#endif
|
||||
return roundf(temperatureC * 10);
|
||||
return dhtValues;
|
||||
}
|
||||
|
||||
ISR(PCINT0_vect) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user