Need help for a "Low Battery" alarm [SOLVED]
ok, here is!!
i'm using code
i have velleman mk174 kit play message when battery low. think shoud around 11.5 volts (out of 14.4)
is there there??
i'm using code
code: [select]
/************************************************************
led dimmer using logic lever mosfet transitor
supply voltage 12v / led build 12v, no resistor needed
pir-sensor power fed arduino 5v / gnd-pins.
pir output digital pin (d2) - polled
pir can retriggable or non retriggable
led switches on when pir detects movement
led output stay 'on' until 5 minutes of 'pir silence'
led (mosfet gate) must connected pwm pin. (d11)
code can drastically redused on volume - made readability
****************************************************************/
// declare global constants
const byte led = 11; // connect gate
const byte pir = 3; // pir signal out
const byte turnontime = 1; // turn on/off time in seconds !(will forced: 50 > time > 0)
const byte secondstooff = 5; // seconds of 'silence' before "lights out" !! alter value
const boolean debug=false;
// declare global variables
boolean lightison = false; // remember led-status 'now'
unsigned long timetoturnoff; // time when led will turn off
unsigned long timenow; // current time
//*************************************************************
//displaymorethan5v sketch
//prints voltage on analog pin serial port
//do not connect more 5 volts directly arduino pin.
const float referencevolts = 5; // default reference on 5-volt board
//const float referencevolts = 3.3; // use 3.3-volt board
const float r1 = 2100; // value maximum voltage of 15 volts
const float r2 = 1000; // determine voltage divider resistors, see text
const float resistorfactor = 1023.0 / (r2/(r1 + r2));
const int batterypin = 7; // +v battery connected analog pin 7
void setup()
{
// set status og used i/o-pins
pinmode(led,output);
pinmode(pir,input);
serial.begin(9600);
}
//********************************
// small functions , procedures - make reading of main prog easier
boolean hewantslightson()
{
return (digitalread(pir)==high);
}
//********************************
void turnlightson(byte period)
{
// led shall increase light intensity on "turnontime" seconds
long delaytime = period * 5 ;
for (byte i=0; i<255; i++)
{
analogwrite(led,i);
delay(delaytime);
}
digitalwrite(led,high); // no pwm needed - turn on 100%
lightison=true; // remember status
}
//**********************************
void turnlightsoff(byte period)
{
// led shall decrease light intensity - 0
long delaytime = period*5 ;
for (byte i=254; i>0; i--)
{
analogwrite(led,i);
delay(delaytime);
}
digitalwrite(led,low); // no pwm needed - turn off
lightison=false; // remember status
}
//**********************************
void loop()
{
timenow=millis(); // note time now
if (hewantslightson()) // if movement -> light!
{
if (!lightison) turnlightson(turnontime); // if still dark - light! (else light on already)
// set 'new' time off -since told 'stay on mor minutes..)
timetoturnoff=timenow + secondstooff * 1000; // set 'off-time' minutes future (milliseconds used)
if (debug) serial.println("renew 1 minute");
}
// test "elvis has left building"
if (timenow > timetoturnoff) // time turn off ??
{
if (lightison) turnlightsoff(turnontime); // if light still on: turn them off
}
{
int val = analogread(batterypin); // read value sensor
float volts = (val / resistorfactor) * referencevolts ; // calculate ratio
serial.println(volts); // print value in volts
}
}
//***************end***********************
i have velleman mk174 kit play message when battery low. think shoud around 11.5 volts (out of 14.4)
is there there??
so problem exactly?
what get,
what did expect
what did try sofar?
what get,
what did expect
what did try sofar?
Arduino Forum > Using Arduino > Programming Questions > Need help for a "Low Battery" alarm [SOLVED]
arduino
Comments
Post a Comment