Arduino Button module KY-004 – arduino DOORBELL

Hello world! Today i made a example for the Arduino Button module KY-004.
Lets say its a very annoying doorbell. 🙂 But it works. You can set different tones.
This button module is handy for many stuff, of course this code is just simple and gives you a idea on how the button module works.

Schematic:
KY-004 button module, Arduino Button module KY-004

Parts list:
Arduino uno.
KY-004 Button module.
Buzzer.
Set of jumper wires MM/FF/MF.

Code:

//Arduino Button module KY-004
//Hello world! This time i made a very simple example on how to use a button.
//the KY-004 button module is very easy to use and requires just a small code.

int Buzzer = 3 ;
int Button = 10; 
boolean val ;

// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
//              1    2    3    4    5    6    7    8    9    10   11   12   13   14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below,  digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14

void setup ()
{
  pinMode (Buzzer, OUTPUT); 
  pinMode (Button, INPUT);
    //Part of buzzer tones
  for (int i = 0; i < Buzzer; i++)  ;   
}
void loop ()
{
  val = digitalRead (Button); 
    if (val == 0)  
  {
    digitalWrite (Buzzer, HIGH);
    tone(Buzzer, tones[14]);
  }
  else
  {
    digitalWrite (Buzzer, LOW);
    noTone(Buzzer);
  }
}
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

1 thought on “Arduino Button module KY-004 – arduino DOORBELL”

  1. Thank you for any other informative web site. Where else may I
    get that type of info written in such a perfect method?
    I have a undertaking that I am just now working on, and I’ve been at
    the look out for such info.

Leave a Reply

Your email address will not be published. Required fields are marked *