Arduino make a Sound

  • Forgive the newbie super simple question......

    So im using the door/window switch sketch with a Doorbell, mostly to send push notifications to phone etc. So far so good on my bread-boarding prototype.

    Now i want to add a sounder, either tiny speaker or piezo so as it makes a noise like a ordinary doorbell, mainly so callers realise its working, but also for anyone to hear if not got push notification etc.

    The arduino will when fully installed will be run off mains power so not too worried about current draw, just need some simple code and how to edit it into the switch sketch, sorry learning arduino as i go, i know its basic. I googled some basic Tone code to make a sound, but getting confused on how to add it into existing code without breaking switch.

  • Hero Member

    @Euromir The tone function will do that. I have used it in this project to register when the touch buttons are pressed. I have used a small piezo buzzer but i believe a speaker can also be used.

    It is very easy to use, just three parameters pinnumber,frequency,duration

    So to play a tone on pin 7 at 1200Hz for 60ms you would use

    tone(7, 1200, 60);

Log in to reply

Suggested Topics