Hello, I want to make something such that when a button is pressed, the piezo buzzer outputs a sound (like a car horn). How do I proceed to write a code for that in both processing and arduino? I'm still learning about serial communication between processing and arduino, so any help will be greatly appreciated ![]()
Forget the interaction between Arduino and Processing for now. Can you control the buzzer just using the Arduino ?
Is the buzzer active, ie you supply a voltage and it makes a noise, or is it passive, ie you need to turn the voltage to the buzzer on and off at the frequency required in order to make a noise ?
byte pinBuzzer = 10;
byte pinBut = A1;
void setup ()
{
Serial.begin (115200);
pinMode (pinBuzzer, OUTPUT);
pinMode (pinBut, INPUT_PULLUP);
}
void loop ()
{
#if 1
digitalWrite (pinBuzzer, digitalRead (pinBut));
#else
digitalWrite (pinBuzzer, ! digitalRead (pinBut));
#endif
}
What hardware are you using?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.