vibration motor/Driving it/06. The first buzz
Driving it · 06 of 10

The first buzz

Three wires, no library, and a sketch that buzzes for half a second and rests for half a second. VCC goes to a 5V pin on every board, SIGNAL to the pin this book uses throughout: D9 on an Uno, GPIO 4 on an ESP32 or ESP32-S3, GP15 on a Pico. The LED lights with every buzz.

Three wires

Three wires
Your board
VCC to
5V
SIGNAL to
D9
Pin current
0.50 mA
GND to GND, VCC to 5V, SIGNAL to D9. D9 is one of the six pins on an Uno that can do PWM, which the next articles need. The pin drives a MOSFET's gate and the 10 kΩ beside it, half a milliamp; the motor's current comes from 5V through the block's regulator.

GND to GND. VCC to your board's 5V pin: 5V on an Uno or an ESP32 board, VBUS on a Pico. SIGNAL to the pin this book uses throughout. NC stays unconnected.

The pins are the same as the XL LED book's, D9 on an Uno, GPIO 4 on an ESP32 or ESP32-S3, GP15 on a Pico, and for the same reason: each can do PWM, which the next article needs, and none of them does anything else at boot.

VCC on 5V beside a 3.3 V board looks wrong and is right on this block. VCC only feeds its regulator; why VCC can be 5V has the detail. 3V3 works too, and gives the motor the same 3.3 V.

The sketch

pinMode(MOTOR_PIN, OUTPUT) makes the pin drive SIGNAL. digitalWrite(MOTOR_PIN, HIGH) puts your board's logic voltage on the MOSFET's gate and the motor runs; LOW puts 0 V there and it stops. Nothing else is needed: no library, no transistor, no diode. The board has them.

Until pinMode runs, the pin is an input and SIGNAL floats, and the 10 kΩ on the board holds the motor off. So the motor is still while your board starts and while it uploads.

What you should see

The motor buzzes for half a second and rests for half a second, and the LED lights with each buzz. At 115200 the serial monitor prints:

on
off
on
off

Hold the board, or press it flat on the table, and the buzz is obvious. Lying loose it can rattle about and feel weaker than it is. How it feels in a project depends mostly on what it is fixed to.

The code

No library. digitalWrite HIGH closes the MOSFET and the motor runs; LOW opens it. Change MOTOR_PIN to the pin you wired SIGNAL to.

motor_first_buzz.ino
/*
  Vibration Motor - first buzz                          TK30 / /p/tk30

  Wiring. Count from the square pad on the TinkerBlock board, parts
  up, header at the bottom:

    GND    -> GND
    VCC    -> 5V: an Uno's 5V, the 5V pin of an ESP32 or ESP32-S3
              board on USB, a Pico's VBUS (3V3 works as well)
    NC     -> nothing   (unconnected on the board)
    SIGNAL -> D9 on an Uno, GPIO 4 on an ESP32 or ESP32-S3,
              GP15 on a Raspberry Pi Pico

  Arduino IDE
    Tools > Board                 your board, e.g. Arduino Uno
    Tools > Port                  the one that appears when you plug in
    Tools > USB CDC On Boot       Enabled   (ESP32-S3 only)
    No library needed.
*/

// The pin SIGNAL is wired to.
// Uno: 9. ESP32: 4. ESP32-S3: 4. Pico: 15.
const int MOTOR_PIN = 9;

void setup() {
  Serial.begin(115200);
  pinMode(MOTOR_PIN, OUTPUT);
}

void loop() {
  digitalWrite(MOTOR_PIN, HIGH);   // the MOSFET closes: buzz
  Serial.println("on");
  delay(500);

  digitalWrite(MOTOR_PIN, LOW);    // open: the motor coasts to a stop
  Serial.println("off");
  delay(500);
}

The motor does not stop dead on LOW. It coasts to a stop over a moment, so a short rest can feel shorter than it is. The next article sets the strength instead of only on and off.

When it does not work

The LED blinks but I cannot feel anything.

Hold the board, or press it flat on the table with a finger. Lying loose on a desk, much of the shake goes into lifting the board rather than moving the desk. If it is still in your hand, look at the motor's thin red and blue leads where they meet their pads.

Nothing happens, not even the LED.

Either VCC is missing, so the board has no 3.3 V, or SIGNAL never goes HIGH. Count from the square pad: GND, VCC, NC, SIGNAL. Check that MOTOR_PIN names the pin SIGNAL is on, and that GND goes to your board's GND.

It buzzes once and my board restarts.

The motor's start is drawing more than your board's supply can spare. That happens with VCC on 3V3. Move VCC to the 5V pin, or VBUS on a Pico, so the block's own regulator takes the surge.

The serial monitor stays empty on my ESP32-S3.

Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port does not bring up a serial port at boot, so the sketch runs with nowhere to print.

Where this goes next

analogWrite for a weaker buzz, and why the weakest settings do not start it.

Strength is a duty cycle

Edit this page — content/books/vibration-motor/the-first-buzz.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Vibration Motor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum