/* This unit was designed to be used on 12V battery systems only. FEATURES ======== 6 LEDs to display voltage level (< 20%, >20%, >40%, >60%, >80%, 100% and above) Programmable maximum LED displayed voltage Programmable minimum LED displayed voltage 3 Independant programmable undervoltage alarms (independant of LED display) SPECIFICATIONS ============== Supply 8 to 18V Max measureable voltage 14.5V Min measureable voltage 8.0V Average current drain 0.25mA with display off @ 12.8V A/D Converter 10 bit A/D Resolution about 15.0mV Sample method Average of 100 samples taken every 8 seconds Prevered alarm settings >100mV between alarms
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
/*
This unit was designed to be used on 12V battery systems only.
FEATURES
========
6 LEDs to display voltage level (< 20%, >20%, >40%, >60%, >80%, 100% and above)
Programmable maximum LED displayed voltage
Programmable minimum LED displayed voltage
3 Independant programmable undervoltage alarms (independant of LED display)
SPECIFICATIONS
==============
Supply 8 to 18V
Max measureable voltage 14.5V
Min measureable voltage 8.0V
Average current drain 0.25mA with display off @ 12.8V
A/D Converter 10 bit
A/D Resolution about 15.0mV
Sample method Average of 100 samples taken every 8 seconds
Prevered alarm settings >100mV between alarms
BUTTON
======
Pressing the button will display voltage level for 30 seconds
if Alarm 1 or Alarm 2 is active, pressing the button will silence the alarms
Pressing button while powering up device, will enter CALIBRATION mode (see CALIBRATION)
While display is on, pressing the button has no effect
BUZZER
======
Beep 1 time every 8 seconds - voltage lower than ALARM 1 level. Press button to silence alarm
Beep 2 times every 8 seconds - voltage lower than ALARM 2 level. Press button to silence alarm
Beep 3 times every 8 seconds - voltage lower than ALARM 3 level. Alarm can not be silenced
Alarms that was silenced, will be reset once voltage exceeds 60% of display voltage for longer than 10 seconds
DISPLAY
=======
While display is on, no alarms will sound
Display will turn off automatically after 30 seconds to conserve battery
CALIBRATION
===========
Before applying power, press button and keep pressed for longer than 5 seconds
Device will beep constant
Release button
6 Beeps - program max display voltage
Top LED on
Device is now in CALIBRATE mode
To exit CALIBRATE mode, remove power from device before preesing the button again
Adjust to max display voltage and press button to save
5 Beeps - program min display voltage
Display will show lowest LED
Adjust to min display voltage and press button to save
4 Beeps - program alarm 1 voltage
Display will show lowest 4 LED
Adjust to alarm 1 voltage and press button to save
3 Beeps - program alarm 2 voltage
Display will show lowest 3 LED
Adjust to alarm 2 voltage and press button to save
2 Beeps - program alarm 3 voltage
Display will show lowest 2 LED
Adjust to alarm 3 voltage and press button to save
Device will give a long beep
Actual voltage is now displayed for 30 seconds
Calibration complete
! ! ! ! ! SPECIAL NOTE ON THE PROJECT ! ! ! ! ! !
To make use of the power saving options available on the AtMega328P, this
program was written with the clock speed at 8MHz, instead of 16MHz. I also
programmed the chip to use the internal 8MHz oscillator for maximum energy
saving.
This means all delays and millis() routines will run at half the speed.
*/
// Include this 3 files for the low power setups
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <EEPROM.h>
// define constants
const byte BTN = 2; // test button
const byte LED1 = 8; // 0%
const byte LED2 = 7; // 20%
const byte LED3 = 6; // 40%
const byte LED4 = 5; // 60%
const byte LED5 = 4; // 80%
const byte LED6 = 3; // 100%
const byte Buzzer = A4; // buzzer
const byte BatIn = A5; // battery monitor pin
// define variables
byte oldADCSRA = 0;
boolean BtnDwn = 0;
byte Range = 0;
// define battery settings
unsigned int Vmin = 0; // minimum displayed battery voltage
unsigned int Vmax = 0; // maximum displayed battery voltage
unsigned int Alm1 = 0; // alarm 1
unsigned int Alm2 = 0; // alarm 1
unsigned int Alm3 = 0; // alarm 1
unsigned int Batt = 0; // calculated voltage reading