Go Down

Topic: power sawe on weight scale (Read 704 times) previous topic - next topic

bboris

Hi,i am new in this forum,I am working on a project arduino beekeeping sms scales , I made a prototype but I have a problem great battery consumption , namely my battery is spent in two days , it is necessary to take at least one month without recharging .

twice in 24 hours my balance takes the data from the sensors and through text messages sent  report on my cell phone , this time in the code are listed as one TIMER 1 , and TIMER 2.
whether it is possible to balance it off , and that wakes up only when the reading and sending messages .
if we can use an external RTC I have a DS1302 as a trigger, for awakening or some another way ?Sorry for my bad english,and thank you for any help!!
My code is:


#include <stdio.h>
#include <DS1302.h>
#define EEPROM_TARE 0
#define EEPROM_TIMER1 4
#define EEPROM_TIMER2 5
#define TEL_NUMBER "+385xxxxxxx"
#define OUTBUFSIZE 160
uint8_t CE_PIN = 11;
uint8_t IO_PIN = 12;
uint8_t SCLK_PIN = 13;
char m_outBuffer[OUTBUFSIZE];
void setup()
{
SerialInit();

Scale_init( EEPROMReadlong( EEPROM_TARE) );
TimersInit( EEPROMRead( EEPROM_TIMER1), EEPROMRead( EEPROM_TIMER2) );
Temp_humidity_sensor_init();
//SetGSMSerial(false);
//sprintf( m_outBuffer, "start" );
//SendData( m_outBuffer );
}

void loop()
{
SerialComunication();
if( IsNewHour() )
{
if( IsTimer1() )
{
SetGSMSerial(true);
MakeReport( m_outBuffer, 160);
SendData( m_outBuffer );
}
if( IsTimer2() )
{
SetGSMSerial(true);
MakeReport( m_outBuffer, 160);
SendData( m_outBuffer );
}
}
delay(1000);
}

void SerialComunication()
{
if( IsSerialMsg() )
{
GetSerialMsg();
int ordnerIndex = GerOrderIndex();
switch(ordnerIndex)
{
case 0://SetTimer1_hh
EEPROMWrite( EEPROM_TIMER1, ReadSerialInt(0, -1 ) );
SetTimer1( EEPROMRead( EEPROM_TIMER1) );
ClearOutBuffer();
sprintf( m_outBuffer, "Is%s%d", GetOrder(ordnerIndex), EEPROMRead( EEPROM_TIMER1) );
SendData( m_outBuffer );
break;
case 1://SetTimer2_hh
EEPROMWrite( EEPROM_TIMER2, ReadSerialInt( 0, -1 ) );
SetTimer2( EEPROMRead( EEPROM_TIMER2 ) );
ClearOutBuffer();
sprintf( m_outBuffer, "Is%s%d", GetOrder(ordnerIndex), EEPROMRead( EEPROM_TIMER2) );
SendData( m_outBuffer );
break;
case 2://Tare_
EEPROMWritelong( EEPROM_TARE, GetTare() );
Scale_init( EEPROMReadlong( EEPROM_TARE) );
break;
case 3://SetClock_hhmmss
SetClock( ReadSerialInt( 0, 2 ), ReadSerialInt( 2, 2 ), ReadSerialInt( 4, 2 ) );
ClearOutBuffer();
// GetTime( char* pcText )
break;
case 4://SendReport_
MakeReport( m_outBuffer, 160);
SendData( m_outBuffer );
break;
case 5://SetSendPC_ np #SetSendPC_#
SetGSMSerial(false);
break;
default:
ClearOutBuffer();
sprintf( m_outBuffer, "Not recognized order" );
SendData( m_outBuffer );
break;
}
Serial.print( "n" );
}
}
void ClearOutBuffer()
{
for (int i=0; i<OUTBUFSIZE;i++)
{ m_outBuffer=NULL;}
}
void MakeReport(char* pcReportText, int iSize )
{
for (int i=0; i<iSize;i++)
{ pcReportText=NULL;}
int h, m, s;
float hum = ReadHumidity();
float temp = ReadTemperature();
double mass = GetWeigth();
if( mass <0)
mass= mass*-1;
GetTime( &h, &m, &s );
sprintf( pcReportText, "%02d:%02d:%02d Hum: %d%% Temp: %d.%dC Weight: %d.%dkg",
h, m, s,(int)hum, (int)temp, (int)(( temp -(int)temp) *10 ), (int)mass, (int)(( mass -(int)mass) *10 ) );
}

Chagrin

https://github.com/n0m1/Sleep_n0m1 has examples for powering down your Arduino. You'd probably want to set it to power down for a few minutes, rechecking the time every so often to see if it's time to take a measurement. There is the possibility of rewaking on a pin change, but I don't think the DS1302 has any way of setting that type of output.

If you're sending text messages your biggest power hog will be your cellular device. Make sure you have a way of powering that down or anything else you do will be a waste of time.

Go Up