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
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
offHold 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.
/*
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.
The same buzz in MicroPython, for an ESP32, an ESP32-S3 or a Pico. motor.on() drives SIGNAL HIGH and motor.off() drives it LOW.
"""
Vibration Motor - first buzz, MicroPython TK30 / /p/tk30
Wiring. Count from the square pad on the TinkerBlock board, parts
up, header at the bottom:
GND -> GND
VCC -> 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 -> GPIO 4 on an ESP32 or ESP32-S3, GP15 on a Raspberry
Pi Pico
Thonny
Run > Configure interpreter MicroPython (ESP32) or
MicroPython (Raspberry Pi Pico)
Save it to the board as main.py to run it on every power-up.
Nothing to install: machine and time are built in.
"""
import time
from machine import Pin
# The GPIO number SIGNAL is wired to. ESP32: 4. ESP32-S3: 4. Pico: 15.
MOTOR_PIN = 4
motor = Pin(MOTOR_PIN, Pin.OUT, value=0)
while True:
motor.on() # the MOSFET closes: buzz
print("on")
time.sleep_ms(500)
motor.off() # open: the motor coasts to a stop
print("off")
time.sleep_ms(500)There is no Uno here: an Uno cannot run MicroPython. value=0 makes the pin LOW the moment it becomes an output, so the motor does not twitch as the script starts. Stop it with Ctrl-C; the motor stops where it was, so run motor.off() if it was on.
When it does not work
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.
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.
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.
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.
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
Questions about this product
See what other owners have asked, and read their solutions.
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.