Detecting 5 volts to activate an alarm

Hello friends.

I'm new here so please be kind and patient.

I am trying to learn how to do a sketch.

The sketch that I want to write will detect 5v from a cell phone charger and upon power loss, the Arduino will sound an alarm using the power from the Arduino's battery.

Please point me in the right direction.

Thanks.

5V is logic high or 1. Zero volts is logic low or 0.

The [u]Digital Read Serial Example[/u] shows you how to read a digital input-pin.

The [u]tone()[/u] function can make a tone through a piezo buzzer.

An [u]if-statement[/u] can be used to run tone() when the input is low.