HC-12 not sleeping

Hello all,
I am measuring the current to my HC-12 module and it is steady at 14 mA whether in sleep mode or not. I do get an "OK+SLEEP" response from the module so I believe it is receiving the command ok. I am sure it is something really simple but I can't quite spot it. Any help would be greatly appreciated. I can sometimes see a drop for a split second in the current right when I send the sleep command so I think it may be waking up immediately for some reason. Here is my code:

// HC-12_sleep.ino

#include <SoftwareSerial.h>
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

#define APPNAME	"Sensor" 
#define VERSION 	"0.93 SL"


// pins
#define HC12_SET	5
#define HC12_TX	10
#define HC12_RX	11

#define RX_BUFFER_SIZE	32
char buffer[RX_BUFFER_SIZE];

SSD1306AsciiWire display;
#define I2C_ADDRESS 0x3C

SoftwareSerial HC12(HC12_TX, HC12_RX); // HC-12 TX Pin, HC-12 RX Pin

void Display(int x,int y,const char *message)
{
	display.setCursor((x*5)+1,y);
	display.println(message);
}


void HC12_Sleep()
{
	
	Display(10,3,"  ");
	Serial.println("About to sleep");

	digitalWrite(HC12_SET, LOW);            // Enter command mode
 	delay(100);                             // Allow chip time to enter command mode
 	HC12.print("AT+SLEEP");             	// Send command
 	delay(500);                             // Wait 0.5s for a response

 	int i = 0;
 	while ( HC12.available() && i < (RX_BUFFER_SIZE-1) ) 
	{       
		char ch = HC12.read();
    		buffer[i++] = ch;
	} 
	buffer[i] = '\0';
	Serial.println(buffer);
	
 	digitalWrite(HC12_SET, HIGH);         // Exit command / enter transparent mode
 	delay(100);                           // Delay before proceeding

}

void HC12_Wake()
{
	Serial.println("About to wake");
	digitalWrite(HC12_SET, LOW);            // Enter command mode
 	delay(100);                             // Allow chip time to enter command mode
 	digitalWrite(HC12_SET, HIGH);         // Exit command mode
 	delay(100);                             // Delay before proceeding

}
void setup()
{

	pinMode(HC12_SET,OUTPUT);

  	Wire.begin();
	Wire.setClock(400000L);
	display.begin(&Adafruit128x32, I2C_ADDRESS);
	display.setFont(Adafruit5x7);
	display.clear();
	delay(2000);

	sprintf(buffer,"%s v%s",APPNAME,VERSION);
	Display(0,0,buffer);

	HC12.begin(9600);
	HC12_Sleep();
	HC12.end();

	Serial.begin(9600);
	Serial.println("Starting");

}




void loop()
{ 
	char message[16];
		

	sprintf(message,"WAKE ");
	Display(0,2,message);

	HC12.begin(9600);
	HC12_Wake();
	HC12.end();

	delay(5000);

	sprintf(message,"SLEEP");
	Display(0,2,message);

	HC12.begin(9600);
	HC12_Sleep();
	HC12.end();


	delay(5000);
}

Anyone have any ideas?? I have switched devices and they all act the same. They seem to go into a lower power mode for a split second, then right back to 15 mA.

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