Servos & Buzzer

Servos & Buzzer

So far, your programs have learned how to receive information.

Now it is time for your projects to do something.

The Servos & Buzzer category allows a project to:

 Move

 Rotate

 Play sounds

 Play melodies

 Create alerts and notifications

Think of this category as giving your project:

Muscles → Servos

and

Voice → Buzzer


What Are Servos?

A servo is a special type of motor that can be controlled by a program.

Examples include:

  • Robot arms
  • Doors
  • Steering systems
  • Camera mounts

A servo allows the program to create movement.


What Is a Buzzer?

A buzzer allows a project to make sound.

Examples include:

  • Beeps
  • Musical notes
  • Melodies
  • Warnings
  • Alarms

A buzzer allows the program to communicate through audio.


Servos & Buzzer Category

[INSERT CATEGORY IMAGE HERE: Servos & Buzzer]

Figure 5.1 – Blocks available in the Servos & Buzzer category.

The category can be organized into three simple families:

POSITION

   ↓

ROTATION

   ↓

SOUND


Block Quick Reference

BlockMain Idea
180° ServoMove to a position
360° ServoContinuous rotation
MIDI SetupCreate sound output
PitchPlay a note
Pitch TimePlay a timed note
StopStop sound
MelodyPlay music
TempoControl music speed
ResetReset MIDI

 180° Servo

[INSERT BLOCK IMAGE HERE: 180° Servo]

A 180° servo moves to a position.

Examples:

0°

90°

180°

servo.servo180_angle(26, 100)

Concept

Value

   ↓

Position

   ↓

Servo

180° Servo = Move to a Position


 360° Servo

[INSERT BLOCK IMAGE HERE: 360° Servo]

A 360° servo rotates continuously.

Instead of choosing a position, you control the rotation.

servo.servo360_speed(26, 100)

Concept

Value

   ↓

Rotation

   ↓

Servo

 360° Servo = Keep Spinning


180° vs 360°

Servo TypeThink About
180° ServoPosition
360° ServoRotation

Easy way to remember:

180° Servo

↓

Move Here

360° Servo

↓

Keep Spinning


Learning to Control a Servo

Start simple.

Choose Value

      ↓

Move Servo

      ↓

Observe

Then:

Change Value

      ↓

Observe Movement

Students learn best when they can immediately see the result.


 MIDI Setup

[INSERT BLOCK IMAGE HERE: MIDI Setup]

Before sound can be played, a MIDI object must be created.

midi = music.MIDI(26)

Concept

Create MIDI

      ↓

Play Sound


Playing a Note

[INSERT BLOCK IMAGE HERE: MIDI Pitch]

A pitch represents a musical note.

midi.pitch(131)

Concept

Pitch

   ↓

Sound


Playing a Timed Note

[INSERT BLOCK IMAGE HERE: MIDI Pitch Time]

A note can also be played for a specific amount of time.

midi.pitch_time(131, 1000)

Concept

Pitch

 +

Time

   ↓

Sound


Stopping Sound

[INSERT BLOCK IMAGE HERE: MIDI Stop]

midi.stop()

Concept

Sound

  ↓

Stop


Playing a Melody

[INSERT BLOCK IMAGE HERE: MIDI Play Melody]

Instead of one note, the buzzer can play a complete melody.

midi.play(midi.DADADADUM)

Concept

Melody

   ↓

Music


Tempo

Tempo controls how fast a melody plays.

Set Tempo

[INSERT BLOCK IMAGE HERE: MIDI Tempo]

midi.set_tempo(4, 120)

Get Tempo

[INSERT BLOCK IMAGE HERE: MIDI Get Tempo]

midi.get_tempo()

MIDI Reset

[INSERT BLOCK IMAGE HERE: MIDI Reset]

midi.reset()

Servos + Sensors

Later, servos can react to sensor values.

Example:

Distance Sensor

      ↓

Read Value

      ↓

Servo

      ↓

Move

This creates the robotics pattern:

SENSE

   ↓

THINK

   ↓

ACT


Buzzer + Logic

A buzzer can also provide feedback.

Example:

Obstacle Detected

      ↓

Play Warning Tone

or

Temperature High

      ↓

Play Alarm


Quick Guide for Students

Want movement?

Use:

180° Servo

or

360° Servo


Want a servo position?

Use:

servo.servo180_angle(...)

Want servo rotation?

Use:

servo.servo360_speed(...)

Want sound?

Create:

music.MIDI(...)

Then use:

midi.pitch(...)

Want a melody?

Use:

Play Melody


Want to stop sound?

Use:

midi.stop()

Quick Reference

FamilyMain Idea
180° ServoPosition
360° ServoRotation
MIDI SetupCreate sound output
PitchPlay one note
Pitch TimePlay a timed note
StopStop sound
MelodyPlay music
TempoMusic speed
ResetReset MIDI

Summary

In this lesson, you learned how programs can create movement and sound.

You explored:

180° Servos

 360° Servos

 Musical Notes

 Timed Notes

 Melodies

 Tempo Controls

 Sound Effects

 Combining Outputs with Sensors

Servos and buzzers allow a project to interact with the real world through movement and sound.


Key Takeaway

Servos create movement and buzzers create sound. Together they allow your projects to act, respond, and communicate with the world around them.