Build it step by step
0 of 7 doneCheck the transistor legs
Collector, base, emitter from the datasheet.
Wire the motor, diode and transistor
Diode stripe to the 5 volt side.
Wire the button
D2 to GND.
Upload and open the serial monitor at 9600
Pattern 0 starts at once.
Feel pattern 0
A double beat like a heartbeat.
Press the button for the others
Ramp, pulse, knock and steady.
Change MAX_PWM
Feel the difference in strength.
How do you build a haptic pattern sampler?
A coin vibration motor plays five buzz patterns through a transistor and a button: a heartbeat, a ramp, a pulse, a knock and a steady buzz. You feel how timing and strength change the message. You need Arduino Nano, Vibration motor (coin type), BC547 NPN transistor, Resistor 1 kΩ, Signal Diode 1N4148, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- Motors & ActuatorsBuy
- SemiconductorsBuy
- PassivesBuyResistor 1 kΩ × 1
- SemiconductorsBuy
- SwitchesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Nano D9 | 1 kilohm resistor to the transistor base | Switch signal |
| Transistor emitter | Nano GND | Common ground |
| Motor one wire | Nano 5V | Motor supply |
| Motor other wire | Transistor collector | Switched side |
| 1N4148 diode | Across the motor, stripe (cathode) to 5V, other end to the collector | Catches the kick when the motor stops |
| Button leg 1 | Nano D2 | Pattern select |
| Button leg 2 | Nano GND | Pressing joins D2 to ground |
Code
A coin vibration motor is a tiny motor with an off-centre weight, and you feel it rather than hear it. The Nano pin cannot drive it directly, so a BC547 transistor does the switching, with a 1 kilohm resistor in the base line. A diode across the motor catches the voltage spike that appears when the motor stops, so check its stripe goes to the 5 volt side. The sketch keeps the PWM to about 3 volts average, which suits a 3 volt motor. Press the button to step through five patterns, and notice that the same motor can feel like a heartbeat, a knock or a steady buzz purely from the timing and strength. The program only moves one motor and records nothing. Tape the motor to your wrist or hold it, but never put it in your mouth or ear, and keep the wires away from anything that can pull on it. Think about which pattern would suit a quiet alert and which a stronger warning.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const uint8_t MOTOR_PIN = 9;
const uint8_t BUTTON_PIN = 2;
const uint8_t MAX_PWM = 150; // about 3 V average, kind to a 3 V coin motor
int pattern = 0;
const int PATTERNS = 5;
void buzz(uint8_t level, int ms) {
analogWrite(MOTOR_PIN, level);
delay(ms);
analogWrite(MOTOR_PIN, 0);
}
void playPattern(int p) {
switch (p) {
case 0: // heartbeat: two beats and a rest
buzz(MAX_PWM, 120); delay(120);
buzz(MAX_PWM, 120); delay(700);
break;
case 1: // ramp: gentle to strong
for (int level = 40; level <= MAX_PWM; level += 22) { buzz(level, 100); delay(20); }
delay(500);
break;
case 2: // pulse: long buzz, long rest
buzz(MAX_PWM, 500); delay(500);
break;
case 3: // knock: three quick taps
for (int i = 0; i < 3; i++) { buzz(MAX_PWM, 60); delay(100); }
delay(600);
break;
case 4: // steady buzz
buzz(MAX_PWM / 2, 800);
delay(300);
break;
}
}
void setup() {
pinMode(MOTOR_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
playPattern(pattern);
if (digitalRead(BUTTON_PIN) == LOW) {
pattern = (pattern + 1) % PATTERNS;
Serial.print("Pattern ");
Serial.println(pattern);
delay(300);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Pattern 0 | Two beats and a rest |
| Pattern 1 | Buzz that grows stronger |
| Pattern 3 | Three short taps |
| Button press | Moves to the next pattern |
| Lower MAX_PWM | A gentler buzz |
If it does not work
Motor never moves
Check the transistor leg order and the base resistor.
Motor stays on
Check the base is not wired to 5V.
Transistor feels warm
Disconnect, check the collector and emitter.
Weak buzz
Raise MAX_PWM a little.
Button skips patterns
Press briefly.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the haptic pattern sampler?
Arduino Nano, Vibration motor (coin type), BC547 NPN transistor, Resistor 1 kΩ, Signal Diode 1N4148, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the haptic pattern sampler take to build?
About 60 minutes for a beginner maker, in 7 steps.
How do I know the haptic pattern sampler works?
Pattern 0: Two beats and a rest. Pattern 1: Buzz that grows stronger. Pattern 3: Three short taps.
Motor never moves: what should I check?
Check the transistor leg order and the base resistor.
Motor stays on: what should I check?
Check the base is not wired to 5V.
Transistor feels warm: what should I check?
Disconnect, check the collector and emitter.
Weak buzz: what should I check?
Raise MAX_PWM a little.
