6 years 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. /media/uploads/Wengweng/30125392_1882879391724537_814352836_o.jpg

  1. include "mbed.h"
  2. 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); } }

Be the first to answer this question.