top of page

1. Using a Button to Activate a Buzzer

 

In this tutorial, you learn how to create an alarm noise on a buzzer and how to activate it with a button.

Required components:

SODAQ Moja

0.5W Solar Panel

1aH battery pack

Grove - Buzzer

Grove - Button

 

First, plug the buzzer into the D4/D5 pin in the always on row.

Then, plug the button int the D2/D3 pin in the always on row.

Next, plug the 0.5W solar panel and the 1A LiPo battery into the respective sockets (see http://www.sodaq.net/#!getting-started/c21ma for a board diagram)

 

Turn on the SODAQ board, compile and upload the following sketch from the arduino IDE onto the SODAQ Board, and then unplug the USB cable from the computer when it is working:

const int buttonPin = 2; //set pin 2 for the buttonconst

int buzzerPin = 4; //set pin 4 for the buzzer

int buttonState = 0; //buzzer starts off

 

void setup()

{

 pinMode(buzzerPin, OUTPUT);

   //define the output and input in the  equation here

 pinMode(buttonPin, INPUT);

}

 

void loop()

{

 buttonState = digitalRead(buttonPin);

 

 if (buttonState == HIGH) {

            // turn buzzer on:

        digitalWrite(buzzerPin, HIGH);

 }

else {

           // turn buzzer off:

        digitalWrite(buzzerPin, LOW);

 }

}

© 2013 SODAQ. All rights reserved.

  • Facebook Classic
  • Twitter Classic
bottom of page