0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電子工作メモ - ブザー

Last updated at Posted at 2024-03-21

ブザー

ブザーについて

  • 種類

    • アクティブブザー: 内部にオシレーター(電源が供給されている間ずっと鳴る)が入っている。

    • パッシブブザー : オシレータがないので、外部にオシレーターが必要。PWM を使って周波数を変えて音を鳴らす。共鳴周波数が最も大きい音が鳴る。

    • 見分け方

      • アクティブブザーには、表面に音声出力の穴がある(絶対ではない)
      • アクティブブザーは、回路構成が複雑で内部にクリスタルオシレーターなどがあるので、下側に防水加工がしてある。
  • 動作使用

    • アクティブブザー
      • 電圧: 1.5V ~ 24V
      • 電流: 10mA ~ 150mA

トランジスタ

  • NPN: 8050(キット内)
  • PNP: 8550(キット内)

マイコンの電流出力容量はとても小さいので、電流が多く必要なデバイスを使う場合に増幅する必要がある。その場合にトランジスタを使う。

  • 回路
  • NPNの場合の回路
    GPIO が High 出力の場合に電流が流れる。Low の場合にオフになる。
  • PNPの場合の回路
    GPIO が Low 出力の場合に電流が流れる。High の場合にオフになる。

接続

NPN型を使う。

  • ブザー側

    • VBUS(5V): ブザーの+
    • トランジスタ
      • E: GND
      • C: ブザーのー
      • B: 1kΩ抵抗(R1) => GP15
  • スイッチ側

    • 3V3 : 10kΩ抵抗(R3) => スイッチ上側
    • GP16: 10kΩ抵抗(R2) => スイッチ上側
    • GND : スイッチ下側

コード

Doorbell(押したときに鳴る)
from machine import Pin
import time

button = Pin(16, Pin.IN, Pin.PULL_UP)
activeBuzzer = Pin(15, Pin.OUT)
activeBuzzer.value(0)

while True:
    if not button.value():
        activeBuzzer.value(1)
    else:
        activeBuzzer.value(0)
Alertor(PWMで鳴らす)
from machine import Pin,PWM
import math
import time
PI = 3.14
button = Pin(16, Pin.IN, Pin.PULL_UP)
passiveBuzzer = PWM(Pin(15))
passiveBuzzer.freq(1000)

def alert():
    for x in range(0, 36):
        sinVal  = math.sin(x * 10 * PI / 180)
        toneVal = 1500+int(sinVal*500)
        passiveBuzzer.freq(toneVal)
        time.sleep_ms(10)
     
try:
    while True:
        if not button.value():
            passiveBuzzer.duty_u16(4092*2)
            alert()   
        else:
            passiveBuzzer.duty_u16(0)
except:
    passiveBuzzer.deinit()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?