I recently created an Arduino Theremin using a Parallax PING sensor and a pushbutton.
You can find more info at Alberto Bietti's projects: Arduino Theremin.
There’s also some videos of me playing Jingle Bells and Tetris.
If you read this and watch the Jingle Bells video before christmas then Merry Christmas!
I’d also like to improve it in some ways: first I’d like to add a second rangefinder for volume control, but I wouldn’t know how to lower the speaker volume digitally. Maybe a digital potentiometer? And I would also like to make better sound quality, maybe with a better circuit and PWM to make a sine wave instead of square wave… Anybody knows how I could do this? I heard of using a low-pass filter. Can the Arduino handle higher frequencies to allow me to do that?
If you have any ideas or suggestions, please let me know!
To make the sound more "sine wave like" you could try to make a simple lopass filter on the output, just a resistor and a capacitor. You could even use at pot and a capacitor to make an adjustable filter.
Will try that, when I can. And the code would be the same.
But I think that if you want to do more advanced waves, to play music or more than one note at the same time, you would need to do some PWM with a low pass circuit, that would do kindof like that:
But I'm not sure how I could do something similar with the Arduino since it probably isn't fast enough... But maybe there are counters allowing that...
I was looking at this article, and it looks like the Arduino actually does use the ATmega168's timers. Those are used with the PWM pins. That means that when you use the analogWrite() function, it actually uses these timers, so what I said before is probably possible.
Here's what the article says:
Timers on the Arduino
I contacted David Mellis of the Arduino development team and learned that the library makes use of all three timers on the ATMega168.
Timer0 (System timing, PWM 5 and 6)
Used to keep track of the time the program has been running. The millis() function to return the number of milliseconds since the program started using a global incremented in the timer 0 ISR. Timer 0 is also used for PWM outputs on digital pins 5 and 6.
Timer1 (PWM 9 and 10)
Used to drive PWM outputs for digital pins 9 and 10.
Timer2 (PWM 3 and 11)
Used to drive PWM outputs for digital pins 3 and 11.
to generate sound, which is ok, but is quite restricted.
But the article I linked to, which is the next one in the series - Arduino Interrupts - explains how to generate sound with a more advanced technique, which is using the built in timers/counters. And they say they'll write new articles on sound using this, so we'll just hope it's coming soon!