Friday, 31 October 2014

Play With Buzzers

Arduino Based buzzer projects

     Components Required:     1. Arduino Board

                                                  2. One crystal 27c 313


     The buzzers so called crystal buzzers to are fascinating in a sense they can be used in various projects like the projects having the requirement of sound system, like say some alarm system or so. Since I m a so called maverick in my approach I wanted to do my first experiment on buzzer with some out of the box techniques. So I happen to pick up one of the buzzer I bought from Guwahati during the last diwali holidays and I started to look into the possibilities of using it with my arduino duemilanove. Interestingly in arduino's standard library we can access some functions which are meant to be used for speakers. Cool enough you can set the frequencies of yopur choice while using it. So it came to my mind why cant we use it to play the notes of classical Indian music, Sa Re Ga Ma Pa Dha Ni Sa (as Do Re Mi Fa So La Ti in English).
       Well, guys, I m not so good in music though. While I was in 2nd grade, my mom tried her best to teach me tabla, an indian instrument which you can associate with Ustad Zakir Hussain. I screwed it up badly. Well, so I guess if my mom gonna see this post I m quite sure she will go goosebumps for the first time. 
        Well, so what I did, is I googled about the frequencies of the notes mentioned about. As the seniors of our college taught me, that google is your best friend. Use it to advantage. And indeed here, for this project itself, google quintessentially acted like my best friend. Just google "sa re ga ma frequencies" and in the first page of the search result you will get the frequencies of the notes So what was left was just to use in it my code. So here I m. 
          And as you can see that I have used the arduino's serial monitor to feed my command and play sa re ga ma pa. But if you have an eight key keypad, you can make a personalised piano with it. So guys just check out the code below and make your own pianos. 

int buzzer = 8;
char tune;

void setup()
{
  Serial.begin(9600);             // Setting up baud rate. We keeep the standard to be 9600
  pinMode(buzzer, OUTPUT);     
}

void loop()
{
  if(Serial.available() > 0)             // Checking for the buffer for input value
  {
    tune = Serial.read();                 // Reading one character command from the buffer
    
    if(tune == 'a')                      // here is the play. All the note of Sa re ga ma has some frequencies
    {                                    // I have used some of them after some search in google
      tone(buzzer,240);                  // Sa: 240 hz
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 's')                      // Re: 270 Hz
    {
      tone(buzzer,270);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'd')                       // Ga; 300Hz
    {
      tone(buzzer,300);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'f')                       // Ma: 320 Hz
    {
      tone(buzzer,320);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'g')                        // Pa: 360 Hz
    {
      tone(buzzer,360);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'h')                        // Dha: 400 Hz
    {
      tone(buzzer,400);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'j')                       // Ni: 450 Hz
    {
      tone(buzzer,450);
      delay(1000);
      noTone(buzzer);      
    }
    if(tune == 'k')
    {
      tone(buzzer,240);
      delay(1000);
      noTone(buzzer);      
    }
  
    Serial.print(tune);                         // printing command
    Serial.print(" ");
  }

}

  
 
    
       And guys it will be totally unjustified if I don't mention here that I didn't make these videos. My friend Prashant Maroti, who not only gives me his valuable suggestions and ideas to proceed with my work but also helps me with my projects, has made this videos of the buzzer systems I have designed. An amazing personality he is.

Monday, 27 October 2014

Creating A Command prompt In Arduino

Using an Arduino for turning on and off an LED is not a very big deal, I guess. But how about this:
You are basically telling your microcontroller to plain English statements to turn the green led on, turn the blue led on and so on. For it you simply require to know some few functions available in the arduino development environment. It is really cool. I personally believe that this is more futuristic than just commanding your arduino board with just a key on your keyboard. In real life we use command prompt in our desktop computers to workout our stuffs and there we use meaningful english commands like print run etc to make things work. people dont want a robot who has been design to raise his hands when say some number in the num [pad is pressed. Instead you might find your bot more humanistic if it works on commands like "Raise_Left_Hand". That sounds more mature from.automation point of view. So here is a small code for the arduino developers who wants a personalised small command prompt. This small code is just a quintessance of a bigger picture I just talked about. 
You basically require a breadboard, two leds, one green, one blue, some hook up wires and an arduino. 

int ledGreen = 7;            
int ledBlue = 8;

void setup()
{
  Serial.begin(9600);             // Setting up baud rate. We keeep the standard to be 9600
  pinMode(ledGreen, OUTPUT);      // LED Green pin set to output
  pinMode(ledBlue, OUTPUT);      // LED Blue pin set to output
}

void loop()
{
  if(Serial.available() > 0)             // Checking for the buffer for input value
  {
    String command;                      // Creating a string variuable
    while(Serial.available() > 0)         // creating a while loop for reading buffer
    {
      command += char(Serial.read());    // creating the string   
      delay(250);
      
      if (command == "GREEN_ON")              // Creting condition
      {
        digitalWrite(ledGreen, HIGH);
      }
      if (command == "GREEN_OFF")
      {
        digitalWrite(ledGreen, LOW);
      }
      if (command == "BLUE_ON")
      {
        digitalWrite(ledBlue, HIGH);
      }
      if (command == "BLUE_OFF")
      {
        digitalWrite(ledBlue, LOW);
      }
    }
  
  Serial.print(command);                         // printing command
  }
}