We then used a tone generated by Snap! to control the motor. Here's a short video of a demonstration:
The 1N4001 diode cost 15 cents, so this approach offers an inexpensive way to control a DC motor with Snap! without requiring any extensions. (We did use an amplifier to amplify the signal, but we already had those on hand from another unit in which students design and fabricate a speaker.)
I wish Scratch would have Arduino libraries or something. It would be nice. But you know, Scratch is more for kids and Arduino is more for teens of 8 and above. Or I think it is.
I love using amplified audio output plus a diode to control the motor! Did you try using pulse width modulation to change the motor speed?
@earthrulerr and @slate_technologies: You might be interested in MicroBlocks (url: microblocks.fun), a free, Scratch-like blocks language that runs in a Chrome or Edge browser (no install needed!) and works with fun, inexpensive microcontorllers like the micro:bit. Jens Mönig helped develop MicroBlocks and is still an advisor, so you'll find many similarities to Snap!.
Thanks for telling me about it! I will probably be buying a Micro:Bit and be using this program in the future! I had used Arduino and other similar products that my school had owned and attempted to use Snap! but could not get it to work properly. This seems much easier! Thank you.
Well at the time (I say this because I haven’t checked since if it still exists) I used the Arduino library and the Arduino website to help me with using Snap! and it wouldn’t work correct.
Cool! Changing the amplitude of the audio signal is simpler than what I was thinking. There's no need to use pulse width modulation since the audio output already gives you a way to vary the peak-to-peak voltage.
Looks like you're driving the amplifier at 100 Hz.
Using higher frequencies -- say, 1000 to 5000 Hz -- might allow you to use a smaller capacitor to smooth out the rectified voltage. But perhaps it wouldn't make much difference...