Hi, i am trying to write a code that would reduce my NRF24lo1 power but it is constantly showing me 13mA i want it to be in uA and for that purpose i tried using the powerUp and powerDown function but unfortunately it didnt worked out for me, please check my code and let me if there are any errors to it.
I will be powering it up using coin battery and with 13mA it will deplete very fast.
I am using arduino UNO as a programmer for my attiny44 IC.
#include<nRF24L01.h>
#include<RF24.h>
#include<avr/wdt.h>
///pin
#define led 3
#define solarPin 7
#define CE 9
#define CSN 10
byte api='L';
byte ledState=LOW;
RF24 radio(CE, CSN);
const byte address[5]={ 'M', 'T', 'P', '0', '0'};
unsigned long lastSignal=0;
unsigned long Time=500;
unsigned long lastSolarCheck=0;
unsigned long lastSave=0;
unsigned long sleepTime=0;
bool night=false;
bool saveMode=true;
bool Sleep=true;
bool w=true;
void setup() {
wdt_enable(WDTO_4S);
pinMode(led, OUTPUT);
pinMode (solarPin,INPUT);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(0x66);
radio.setRetries(0, 0);
radio.setAutoAck(false);
radio.openReadingPipe(0,address);
radio.maskIRQ(1,1,0);
radio.startListening();
attachInterrupt(0, interruptFunction, FALLING);
}
void solarCheck()
{
if(millis()-lastSolarCheck>=5000)
{
night=((digitalRead(solarPin)==LOW)?true:false);
lastSolarCheck=0;
}
}
void loop() {
wdt_reset();
//after reciving signal, go to poweSave mode till ,10ms before next signal
PowerSave();
//check solar for every 5 sec
//solarCheck();
//if no signal for more then (2 signal time ) then go to sleepMode for 5mins
sleepMode();
///wakeup from sleepMode
//wakeUp();
}
void interruptFunction(){
if(radio.available())
{
radio.read(&api, sizeof(api));
ledState = (api== 'H')?HIGH: LOW;
digitalWrite(led ,ledState);
saveMode=false;
Sleep==false;
lastSignal=millis();
radio.stopListening();
radio.powerDown();
}
}
void PowerSave()
{
if((millis()-lastSignal>=Time-10)&&( saveMode==false))
{
radio.powerUp();
//radio.openReadingPipe(0,address);
radio.startListening();
saveMode=true;
}
}
void sleepMode()
{
if((millis()-lastSignal>=2000)&&(Sleep==false))
{
ledState=LOW;
digitalWrite(led, ledState);
radio.stopListening();
radio.powerDown();
sleepTime=millis();
Sleep=true;
w=false;
}
}
/*
void wakeUp()
{
if((millis()-sleepTime>=180000UL) && (Sleep==true) &&(w==false))
{
Sleep=false;
w=true;
radio.startListening();
}
}
*/