Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Button with buzzer

Available Languages
Picture
Picture

Introduction 

Picture
Grove - Button is a momentary push button. It contains one independent "momentary on/off" button. “Momentary” means that the button rebounds on its own after it is released. The button outputs a HIGH signal when pressed, and LOW when released. The Sig marked on silk layer stands for signal while NC stands for not used at all. There are two versions of this button available as showed in the pictures. The only difference is the direction of the Grove socket.

Features
  • Easy to use momentary ON/OFF button
  • Uses Standard 4-pin Grove Cables

What we need and connection

For this tutorial we will need:
  • Arduino UNO
  • Grove Base Shield
  • Button
  • Buzzer (Connect Grove-Buzzer to A3 port of Grove-Base Shield)
Picture

The code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const int buttonPin = 2; 
const int buzzer = A3; 

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
    // initialize the LED pin as an output:
    pinMode(buzzer, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
}

void loop(){
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
        tone(buzzer, 1000);
    }
    else {
        noTone(buzzer);
    }
}
Download the code from here and open it with Arduino IDE.
grove-button.zip
File Size: 0 kb
File Type: zip
Download File

Well done!

Picture
You have successfully completed one more Arduino Grove tutorial.

I hope you liked this, let me know in the comments.
Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates