Wednesday 23 October 2013

Arduino Starter Kit - Chapter 06 Light Theremin


Hi, I'm Troy McClure Ygy Freezone. You may remember me from such tutorial as Arduino Starter Kit Explanation, and this is nothing more than another chapter of my Explanation! -big noise of hand clapping-

Today I'll display you the next chapter of the manual:

06 LIGHT THEREMIN create a musical instrument you play by waving your hands



In this chapter we will try to reproduce a Theremin (an instrument that make sound based on the movements of a musician hand around  the instrument, here for more info).
While the Arduino can't exactly replicate the sound, nor the operation behind this instrument, it is only possible to emulate them using the tone() function and a piezo sounder.
Furthermore, here the author explain an helpful method to calibrate your sensor, using a while loop in the setup() function.
Our beloved/hated wikipedia about the while loop say "The while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition". I can't explain better than this.
Syntax: 
while (booleanCondition) {
//..
}
Into the booleanCondition in this case the author choose to put the millis() function.
The millis() function return the number of millisecond from when the Arduino is on.
Syntax:
int millis()
For play sound on a piezo you need the tone() function. Let see this function:
Syntax:
void tone(pin,freqPlay,timePlay)
Where pin is the pin which you had connected to the piezo; freqPlay is the frequency for play obtained using the map() function, we talk about that in the previous chapter, to change the range of the sensor(0-1023) to the range of the piezo (50-4000); timePlay is the time in millisecond you want to play that frequency.

As ever I don't put the entire code, because you can find it easily into the IDE.

My modification this time is not mine, or rather, I followed the advise on the manual:


So here we are, I first try to put a potentiometer:
But the sound was really to low, and I don't really like this solution.



Then I try to change the potentiometer with another photoresistor:
Built like this the operation of our Theremin is more like a real Theremin.



Unfortunately for the second photoresistor I do not put any function for modulate the voltage level like it was the volume. Because the tone() function, in her internal code, use the same condition of the analogWrite() I don't really know if these two work in the same pin.

Maybe it is possible, but I need to know how both functions work in their internal code and try to mix they together for changing both frequency and pwm.


For today it's over, next post next week.

Ygy Freezone.

3 comments:

  1. Hey great to see you made the same attempt to use the potentiometer! Im just starting on the kit now and I too wanted to regulate the volume but couldnt understand how to do it. Someone suggested to use a 10k(ohm) resistor and that lowered the volume but wasnt what I was looking for.

    Any chance you've learned how to code the resistor since this post?

    ReplyDelete
    Replies
    1. Hey Aleksandr,

      Searching for the same thing as you, I found this post with your question. I found out how to change the volume: - to the left or right pin of the potentiometer, middle pin to the piezo, piezo to port 8. So one of the potentiometers pins is not connected. Then you can control the volume.

      I didn't find out how to do this with the photoresister.

      Delete
  2. Hi ... I'm just starting to work with Arduino, and I'd like to see if you can share your code, where do you try it with the potentiometer, I still understand it well what were your functions

    ReplyDelete