Showing posts with label piezo sounder. Show all posts
Showing posts with label piezo sounder. Show all posts

Friday, 6 December 2013

Arduino Starter Kit - Chapter 11 and 12


I'm sorry, I cannot keep some scheduled post method, I post when I can.
Today I'll explain the chapter 11 and 12 of the Arduino Starter Kit

11 CRYSTAL BALL a mystical tour to answer all your tough question
12 KNOCK LOCK tap out the secret code to open the door

Chapter 11:
In this project we'll use an LCD screen, that can be used to display alphanumeric characters.




In the code section they explain how to use the switch case statement and the random() function.
The switch() statement execute different code depending on the value you give it in input.
Each of these code is called case.
Syntax:

switch (controllVariable){
     case 1:
     //..
     case 2:
     //..
     case N:
     //...
}

The random() function returns a number based on the argument you provide it.

I really wanted to do some modification to this project, or also create some project by myself with the lcd screen, but this time the problem is pretty physical: as you can see in the opening pic the breadboard is pretty full, and sadly I do not own a bigger one. When I can afford to buy some more pieces I post an update.




Chapter 12:
In this chapter we'll going to use the piezo as input: When plugged into 5V, the piezo can detect vibration, that can be read by the Arduino's analog input.





In the code section this time they introduce how to declare you own function. When you declare your own function you must indicate if it going to return value or not, in the first case you must indicate the type (int, long, float, etc...) otherwise you indicate the type as void, I.E. like you see in the basic function setup() and loop().
Next you indicate the name of the function and after that, inside round bracket, indicate the argument of the function.
Syntax:
[type/void] functionName (argtype arg) {
//..
}

Here a video demonstration of this project:



Next time I'll post all the three remaining chapter, and then I finally concluded the Starter Kit and so I can finally try something that run on my mind from some time.

Ygy Freezone

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.