Well, after a typhoon in Hong Kong last week, I have tried another work around solution which is partial work, need extra test after couple days.
Solution:
- ATmega8A: work with RF315MHz (or RF415MHz) Radio Freq Modules to decode the data from RF transmitter.
- ATtiny13A: work with ATmega8A, main propose to handle all of the sound (Doorbell ringtone & buzz)
PS: will upload the schematic after the POC works.
PCB Schematic:
JP1: Connect to ATmega8A (Pin from left: GND, VCC, ATmega8A-D4, ATmega8A-D2)
JP2: Doorbell Ringtone Module (Connect to button pins)
JP3: Buzz
U1: ATtiny13A / ATtiny25 / ATtiny85
U2: NE2501 / PC817
R1: 220ohm
R2: 220ohm
Sketch for ATtiny13/13A:
#define PIN_TTL_LB_WARN 0 //Phyicial Pin 5, INPUT_PU, Low Battery (Warn)
#define PIN_TTL_LB_NOTI 1 //Phyicial Pin 6, INPUT_PU, Low Battery (Notice)
#define PIN_DB_TRIG 2 //Phyicial Pin 7, OUTPUT, Play Door Bell (Play 50ms)
#define PIN_LB_BUZZ 4 //Phyicial Pin 3, OUTPUT, Connect BUZZ
void setup()
{
pinMode(PIN_DB_TRIG, OUTPUT);
pinMode(PIN_LB_BUZZ, OUTPUT);
pinMode(PIN_TTL_LB_WARN, INPUT_PULLUP);
pinMode(PIN_TTL_LB_NOTI, INPUT_PULLUP);
}
void loop()
{
bool stateTestBtn = digitalRead(PIN_TEST_BTN);
bool stateLowBattWarn = digitalRead(PIN_TTL_LB_WARN);
bool stateLowBattNoti = digitalRead(PIN_TTL_LB_NOTI);
if( stateLowBattWarn == LOW && stateLowBattNoti == LOW){
playDoorBell();
}else if( stateLowBattWarn == LOW ){
lowBatteryBeep( true );
}else if( stateLowBattNoti == LOW ){
lowBatteryBeep( false );
}
delay(1000);
}
void playDoorBell()
{
digitalWrite(PIN_DB_TRIG, HIGH);
delay(50);
digitalWrite(PIN_DB_TRIG, LOW);
delay(1000);
}
void lowBatteryBeep(bool isWarning)
{
if( isWarning ){
//Warning Level (<3.6v), replace battery ASAP
for( char c = 0; c < 6; c++){
myTone(PIN_LB_BUZZ, 1200, 200);
delay(230);
}
}else{
//Notice Level (3.8-3.6v)
for( char c = 0; c < 3; c++){
myTone(PIN_LB_BUZZ, 1200, 300);
delay(1000);
}
}
}
void myTone(byte pin, uint16_t frequency, uint16_t duration)
{ // input parameters: Arduino pin number, frequency in Hz, duration in milliseconds
unsigned long startTime=millis();
unsigned long halfPeriod= 1000000L/frequency/2;
pinMode(pin,OUTPUT);
while (millis()-startTime< duration)
{
digitalWrite(pin,HIGH);
delayMicroseconds(halfPeriod);
digitalWrite(pin,LOW);
delayMicroseconds(halfPeriod);
}
pinMode(pin,INPUT);
}
Logic For ATmega8A:
digitalWrite(2, LOW) to trigger play a short beep (which is low battery warning)
digitalWrite(4, LOW) to trigger play a long beep (which is low battery notice)
both 2 & 4 are LOW, to trigger play a ringtone via doorbell module