Author Options:

How to get a arduino to use 3push buttons as inputs, and output a different signal on a speaker Answered

Hey all,
 I am new to the whole arduino using world.  I have a project that uses 3push buttons, a  breadboard, arduino, lcd display, and speaker.
The goal is to write program to play a certain freq. signal through the speaker, (each pushbutton has it's own frequency for the signal) when each of the buttons is pushed, and also display each signal on  the LCD display while doing it.

7 Replies

mpilchfamily (author)2013-04-02

Have you looked at similar projects?

These are a little more complicated then what you already have but will give you some ideas about how to go about achieving your goal. This first one will give you some ideas about the buttons and the sounds.

This next one takes things a bit further adding an LCD to the mix and some more options. 

Select as Best AnswerUndo Best Answer

dsm5286 (author)mpilchfamily2013-04-08

I got it figured out. Thanks for help. I started over from scratch and made each button it's own const int and each it's own button state, added in the LCD pin at Tx, and added the sub routines, and after few hours of fixing little typo's got it to work. Again thanks for the help.

Select as Best AnswerUndo Best Answer

steveastrouk (author)2013-04-01

Start simple: Use the examples in the Arduino IDE and make sure they work the bits you have. Learn how to read buttons, learn how to write to the LCD, learn how to make tones. Once you can do that, the code for the thing is very simple.


Select as Best AnswerUndo Best Answer

dsm5286 (author)steveastrouk2013-04-01

I have some code written. for setting up the buttons. The first two work, but the last one doesn't, and it just keeps playing one tone even if none are pressed...and I have the part down to write to the lcd.. I've made simple tones, but it keeps telling me I didn't define pitches.h in my program in one window, but if i copy and paste it to another blank page, it does what I described earlier in this reply.

Select as Best AnswerUndo Best Answer

steveastrouk (author)dsm52862013-04-01

Post your code. Do you have pull up resistors on your buttons, or pull downs ? "pitches.h" implies you are using a library. Where's it from ?

Select as Best AnswerUndo Best Answer

dsm5286 (author)steveastrouk2013-04-03

#include "pitches.h"

const int button = 0; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
// notes to play, corresponding to the 3 sensors:

int notes[] = {

void setup() {
pinMode(button, INPUT);
// initialize the pushbutton pin as an input

void loop() {
for (int button = 0; button < 3; button++) {
// get a sensor reading:
int buttonState = digitalRead(button);

// if the sensor is pressed hard enough:
if (buttonState == HIGH) {
// play the note corresponding to this sensor:
tone(8, notes[button]);
here is the code so far. and once i get it to work properly by addin a no tone when digitalread=0 then i will move the button pins to 2-4 and add LCD code.

Select as Best AnswerUndo Best Answer

steveastrouk (author)dsm52862013-04-03

But you only have ONE button defined in the setup, and that is digital Pin 0.

Select as Best AnswerUndo Best Answer