Newbie needs help with simple project.

Hello everyone. I am attempting to write a sketch that sounds a piezo buzzer if my ac power cuts out. I will be using a 5v phone charger as my input that is to be read. Once the power cuts from the 5v phone charger (even for a split second) , I need it to sound the buzzer. I will be powering my arduino uno with batteries, with hopes of putting this all on an ATTINY85 afterwards. I need to make this project to alert me to reset pumps in the boiler room of my apartment building in the event of power outages that may only last a fraction of a second. Any help would be appreciated.

byte powerOn = digitalRead(testpin);
if (powerOn == LOW) {
   soundBuzzer();
}

…R

Make sure the 5V phone charger is 5VDC.

Thanks everyone. I will give it a try and let you know how it works. BTW, the charger is confirmed at 5v.

No luck. I haven't programmed in over 2 years, and had limited skills to begin with. I need a bit more help.

Always show us a photo of your wiring and a copy of your sketch when you need help.

sardula:
No luck. I haven’t programmed in over 2 years, and had limited skills to begin with. I need a bit more help.

It will be much easier to help if you post the code you have tried.

…R

I don't have a sketch really. All i need is a sketch that if A goes dead, B turns on. I can figure it out from there.I am just having trouble with where to put what where in the sketch. From void setup to void loop to finish. I know it isn't that complicated, but I would really like some help. I actually found a super-useful way to use my Uno.

May I suggest you watch these https://m.youtube.com/playlist?list=PLV009FNOX7Tf-XSyghg2vrSYXw1QcCHaX

void setup(){
pinMode (12, INPUT_PULLUP); // wire switch that connects 12 to Gnd when pressed
pinMode (13, OUTPUT); // onboard LED
}

void loop(){
if (digitalRead(12) == LOW){
digitalWrite (13, HIGH);
}
else {
digitalWrite (13, LOW);
}

}

I think that is exactly what I need. Gonna sleep on it now.... Up since 3am.

It works! (Thanks to CrossRoads) (I am still awake). It works with an LED. I just need some help to get a tone to play from an 8 ohm speaker (revising from buzzer) instead of turning on an LED. I am really sorry if I am clueless with this. I know what I want, and am so close to getting it right! Thanks to everyone out there!!!!!!

Do you have a Piezo speaker? If so you can connect it to an Arduino output pin. Look at the tone() function. http://arduino.cc/en/reference/tone

If you only have an 8 ohm speaker you will need a power amplifier or a driver between the Arduino and the speaker. OR Try http://arduino.cc/en/Tutorial/tone but the volume will be low.

sardula: All i need is a sketch that if A goes dead, B turns on. I can figure it out from there.

Reply #1

...R