Hi,
I have done this project that works really good:
Schematic:
The code:
#include <SoftwareSerial.h>
#include <dht.h>
#include <tinysnore.h>
SoftwareSerial HC12 (A1, 0);
dht DHT;
void setup () {
pinMode(A1, OUTPUT);
pinMode(PB1, INPUT);
HC12.begin(9600);
delay(10000);
}
void loop(){
DHT.read22(PB1);
float h = DHT.humidity;
float t = DHT.temperature;
HC12.print(t);
HC12.print("@");
HC12.println(h);
snore(60000);
}
With a battery 18650 with 2000mA the all thing last 23 days with a "costant" usage of 3,5 mah.
The Attiny85 in sleep mode uses 0,06 mah, but the HC-12 at the minimum settings uses 3,5mah.
Recently i discovered that the HC-12 has a sleep mode, and that can be activated via code.
⑩AT+SLEEP
After receiving the command, the module enters sleep mode after exiting from AT, the
working current is about 22μA, and this mode doesn’t allow serial port data
transmission. Then enter AT setting state again, and the module will exit from sleep
mode automatically.
e.g.:
When wireless data transmission is not needed, to save power, send “AT+SLEEP”
command to module, and the module returns “OK+SLEEP”
But the problem is that i'm not really sure how to do that, and i don't want break something.
This is how i would do that:
-
Connect the SET pin of the HC-12 to the A3 or A2 of the Attiny85.
This is the pinout of the Attiny85 to be sure that we are talking about the same pins:
-
Then, programatically i would write the code like that:
#include <SoftwareSerial.h>
#include <dht.h>
#include <tinysnore.h>
SoftwareSerial HC12 (A1, 0);
dht DHT;
void setup () {
pinMode(A3, OUTPUT); //SET pin HC-12
digitalWrite(A3, HIGH);
pinMode(A1, OUTPUT);
pinMode(PB1, INPUT);
HC12.begin(9600);
delay(10000);
}
void loop(){
hcWake();
DHT.read22(PB1);
float h = DHT.humidity;
float t = DHT.temperature;
HC12.print(t);
HC12.print("@");
HC12.println(h);
hcSleep();
snore(60000);
}
void hcSleep(){
digitalWrite(A3, LOW);
delay(200);
Serial.print("AT+SLEEP");
delay(200);
digitalWrite(A3, HIGH);
}
void hcWake(){
digitalWrite(A3, LOW);
delay(200);
digitalWrite(A3, HIGH);
}
If all this is correct please tell me, or if you have a better idea or some suggestion or something i'm missing tell me! Thanks!

