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