I was in a local surplus store and was pleasantly surprised to find a little section full of Arduino related electronics.
I bought a pack of two vibration motors like this
https://whadda.com/product/vibration-motor-module-2pcs-wpm458/
I'm anxious to figure out how to incorporate them into a project.
I'm still new to all this but they have an example code on GitHub.
I'm not really sure how the if statement works. It looks like it counts how many vibrations have occured and if it's less then 16 it keeps going? Then there's a delay and it runs again?
I'm not sure what if(index %2 == 0) does.
Once I figure out how it works I'll try putting it into another project and post that code.
I haven't really tried to code anything with more then one if statement so it's a bit of a learning curve.
The project I want to add it to has servo motors and is powered by a bench power supply. I was thinking I'd run this motor off of a usb power bank. It's 5 volts but it seems like most people advise a "better safe then sorry" approach to this.
const int vibrationPin = 13; // Set connection pin to signal pin of vibration module
// Set the duration of vibration pulses and pauses array in ms, produces ... -- ... (SMS) vibration from old Nokia Phones
const unsigned int melody[] = {125, 125, 125, 125, 125, 325, 250, 250, 250, 325, 125, 125, 125, 125, 125, 125};
void setup() {
pinMode(vibrationPin, OUTPUT); // Set pin as output
digitalWrite(vibrationPin, LOW); // Set pin low to make sure vibration motor is off
}
void loop() {
// For index 0->15 (indexes of melody array)...
for(int index=0; index < 16; index++) {
if(index %2 == 0) digitalWrite(vibrationPin,HIGH); // If index is even, melody duration is pulse, switch vibration motor on
else digitalWrite(vibrationPin, LOW); // Else, index is odd, melody duration is pause, switch vibration motor off
delay(melody[index]); // Wait for number of ms of current melody index
}
delay(2000); // Wait for 2s (= 2000 ms)
}
https://github.com/WhaddaMakers/Vibration-motor-module/blob/main/WPM458_example/WPM458_example.ino