Please select To the mobile version | Continue to access the desktop computer version
| |

Robot Forum

 Forgot password?
View: 3074|Reply: 0

Sample code to make a DC motor play music

[Copy link]








Rank: 9Rank: 9Rank: 9

Post time: 2016-03-03 16:11:13
| Show all posts |Read mode

It may surprise you to know that you can use electric motors as speakers. You simply need to drive the rotor back and forth at the right frequencies. The rotor will not spin at these frequencies but simply vibrate back and forth. The volume will depend greatly on the size of the motor and what is attached to the motor. It can be adjusted to some extent by varying the duty cycle.

I have attached some Arduino sample code that can be used with a Mini Driver. If you are using a motor shield then you will need to change the DIR and PWM (direction and power) pins to suit the shield you are using.

This sample code does not use any hardware timers so it will work on most Arduino boards and not conflict with any other libraries you might want to use. It simply determines the number of microseconds that the motor must go forward and backward for to produce a given note and drives the motor at 100% duty cycle.

1.69 KB, Downloads: 1200


Use magic Report

You have to log in before you can reply Login | Register

Points Rules


2010-04-30 15:40 GMT+8 , Processed in 0.281896 sec., 16 queries .

Powered by Discuz! X3.2

Release 20140618, © 2004-2010 Dagurobot

Quick Reply To Top Return to the list