HC-12 sleep mode question

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:

  1. 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:

  2. 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!

Hi
A couple of years ago I did a very similar project - a mobile sensor on Attiny85 with DS18B20 and HC-12. With sleep mode for Attiny and HC-12 the sensor still works 5 months with 600mA*h battery.

Here is the code i used to sleep and wake up HC-12:

//==============================
void hc_12_sleep() {
  delay(50);
  digitalWrite(HC_12_SET_PIN, LOW);
  delay(50);
  radio.println("AT+SLEEP");
  delay(50);
  digitalWrite(HC_12_SET_PIN, HIGH);
  
}
//==============================  
void hc_12_wakeup() {
  digitalWrite(HC_12_SET_PIN, LOW);
  delay(50);
  digitalWrite(HC_12_SET_PIN, HIGH);
  delay(50);
  
} 

Ok, but can I still do it with the analog pin? And with the declaration I have done?

You can use analog pin as didgital

Sorry if I open this question again. But i'm not able to sleep the HC12, you used
radio.println("AT+SLEEP");
But i have to replace the radio with my HC12 declaration from the SoftwareSerial? Because i tryed but not working, maybe i have to use the pin A2 for the SET pin? and i have to use HC12.println("AT+SLEEP"); because I declarated it with the SoftwareSerial?

yes, if you declared your SoftwareSerial ac HC12, you should use it instead of "radio" in my code

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.