Site Tools


Sidebar

Content

pub:active_buzzer

Active_buzzer

What is active buzzer?
The buzzer is an integrated electronic alarm device that is powered by a DC power source, widely used in computers, printers, copiers, alarms, electronic toys, automotive electronics, telephones, timers, etc. The active buzzer can make a sound as long as there is a power supply. Our programming output alternated high and low levels to make the buzzer sound. Considering that some chips have a weak GPIO output current, we have integrated a transistor on the active buzzer module to drive the buzzer. The main function of the transistor is to amplify the voltage or current. The transistor is divided into two types, one is NPN, such as the S8050 we provided; the other is PNP, such as the S8550 we provided. And chip transistors are used on the module. The active buzzer we use


Connection:

S Digital input
+ VCC
- GND

Module schematic


Microbit

Preparation:

1 * microbit
1 * microbit expansion board
1 * USB cable
1 * Active buzzer module
- Several Jumper wires

Then connect the active buzzer to the micro:bit


microbit code:

makecode:


MU python:

#-----------------------------------------------------------
# File name   : Active_buzzer.py
# Description : Buzzer rang.
# Author      : jason
# E-mail      : jason@adeept.com
# Website     : www.adeept.com
# Date        : 2018/12/22
#-----------------------------------------------------------
from microbit import *
while True:
    pin0.write_digital(1) 
    sleep(500)
    pin0.write_digital(0)
    sleep(200)

Download the code to micro:bit:


Arduino UNO

Components

1 * Adeept Arduino UNO R3 Board
1 * Active Buzzer Module
1 * USB Cable
1 * 3-Pin Wires

Connect the buzzer to the Arduino UNO


Adeept UNO R3 Board Active Buzzer Module
D8 S
5V +
GND -

arduino code:

  /***********************************************************
File name: _10_ActiveBuzzerModule.ino
Description: The active buzzer beeps like the sound of "Di Di"..
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2018/12/22 
***********************************************************/
int activebuzzerPin=8; //definition digital 8 pins as pin to control the active buzzer
void setup()
{
    pinMode(activebuzzerPin,OUTPUT); //set digital 8 port mode, the OUTPUT for the output
}
void loop()
{  
    digitalWrite(activebuzzerPin,HIGH); //set PIN 8 feet as HIGH = 5 v "Di"
    delay(2000);                        //set the delay time,2000ms 
    digitalWrite(activebuzzerPin,LOW);  //Set PIN 8 feet for LOW = 0 v "no Di" 
    delay(2000);                        //set the delay time,2000ms 
}

Select the development board model and COM port


Click Download


Now you can hear the sound from the buzzer


Raspberry Pi

Components

1 * Raspberry Pi
1 * Passive buzzer module
1 * Breadboard
Several jumper wires

Connect the active buzzer to the Raspberry Pi

Copy the code to Raspberry Pi Linux

Raspberry code:

python code:

  #!/usr/bin/env python
 
#-----------------------------------------------------------
# File name   : 02_activeBuzzer.py
# Description : make an active buzzer beep.
# Author      : Jason
# E-mail      : jason@adeept.com
# Website     : www.adeept.com
# Date        : 2015/06/12
#-----------------------------------------------------------
 
import RPi.GPIO as GPIO
import time
 
BeepPin = 12    # pin11
 
def setup():
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BOARD)        # Numbers pins by physical location
	GPIO.setup(BeepPin, GPIO.OUT)   # Set pin mode as output
	GPIO.output(BeepPin, GPIO.HIGH) # Set pin to high(+3.3V) to off the beep
 
def loop():
	while True:
		GPIO.output(BeepPin, GPIO.LOW)
		time.sleep(0.1)
		GPIO.output(BeepPin, GPIO.HIGH)
		time.sleep(0.1)
 
def destroy():
	GPIO.output(BeepPin, GPIO.HIGH)    # beep off
	GPIO.cleanup()                     # Release resource
 
if __name__ == '__main__':     # Program start from here
	print 'Press Ctrl+C to end the program...'
	setup()
	try:
		loop()
	except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
		destroy()

C code:

  /*
* File name   : buzzer.c
* Description : Make an active buzzer sound.
* Website     : www.adeept.com
* E-mail      : support@adeept.com
* Author      : Jason
* Date        : 2015/05/02
*/
#include <wiringPi.h>
#include <stdio.h>
 
#define BeepPin  1
 
int main(void)
{
	if(wiringPiSetup() == -1){ //when initialize wiringPi failed, print message to screen
		printf("setup wiringPi failed !");
		return -1; 
	}
 
	pinMode(BeepPin, OUTPUT);   //set GPIO0 output
 
	while(1){
		digitalWrite(BeepPin, LOW);  //beep on
		delay(100);                  //delay
		digitalWrite(BeepPin, HIGH); //beep off
		delay(100);                  //delay
	}
 
	return 0;
}

Step 2: Edit and save the code with vim or nano.

(Code path: /home/Adeept_RFID_Learning_Kit_C_Code_for_RPi/03_passiveBuzzer/passiveBuzzer.c)\\


Step 3: Compile

$ gcc passiveBuzzer.c -o passiveBuzzer –lwiringPi -lpthread



Step 4: Run

$ sudo ./passieBuzzer



For Python users:

Step 2: Edit and save the code with vim or nano.

(Code path: /home/Adeept_RFID_Learning_Kit_Python_Code_for_RPi/03_passiveBuzzer.py)

Step 3: Run

$ sudo python 03_passiveBuzzer.py



Now, you can hear the sounds of the buzzer – in varying “rhythms”.


Link for code download:http://www.adeept.com/learn/ Download the kit information as needed.
Video link:http://www.adeept.com/video/

pub/active_buzzer.txt · Last modified: 2018/12/28 12:22 by Adeept