Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 8 months ago.
buzzer volume very low and keep beeping
the basic working of the circuit is to use limit switch to count and produce sound at buzzer. i want the buzzer only produce sound after 3 counts from limit switch, but the problem is the buzzer produced sound every press from the limit switch and the volume of the buzzer is very low. heres my code and circuit.
- include "mbed.h"
- include <string>
DigitalIn switch1(p22); DigitalOut buzzer(p21); DigitalOut myled(LED1);
int counter = 0; int pinread;
int main() { while(1) { read switch pin value, if pressed = 1 else = 0 pinread = switch1.read();
if(pinread == 1) { ++counter; printf("counter:%d\r\n",counter); when receive 3rd input from switch pin, beep for 0.5s if(counter == 3){ printf("beep\r\n"); buzzer.write(1); myled.write(1); wait(0.5); myled.write(0); buzzer.write(0); counter = 0; } } wait(0.2); } }