Buzz like a UPS

This is yet another simple test of a new hardware component that I haven’t played with before. Buzzer is an audio device which may be mechanical, electromechanical, or piezoelectric. It can generate from quite awful UPS-like siren to melodious tone; it really depends on how you want to use it. I just wanted to make noise like that of a UPS does when electricity goes off.

The rest of the post can be found here.

Blinking BiPolar LED

BiPolar LEDs have 3 three legs. One goes to ground, and the other 2 represents two different colors in the same LED. In my case, they are green and red. I have also used a variant of Arduino Nano in order to reduce the size of the experiment. Here’s the list of connections that I have made:

LED’s ground leg 220 ohm resistor
220 ohm resistor Arduino’s ground
LED’s one leg Arduino’s Digital Pin 12
LED’s other leg Arduino’s Digital Pin 13

My intention was to blink the colors alternatively. Green, red, green, red, green… with a 1-second delay in between. The code is as simple as one can imagine. There’s really nothing novel going on here:

int green = 12;
int red = 13;

void setup() {                
  pinMode(green, OUTPUT);     
  pinMode(red, OUTPUT);
}

void loop() {
  digitalWrite(green, HIGH);
  digitalWrite(red, LOW);
  delay(1000);           

  digitalWrite(green, LOW);
  digitalWrite(red, HIGH);
  delay(1000);   
}

Here’s the final outcome:

WP_20141105_21_04_47_Pro

Hello Blinking LED

Apparently the post title here is the universal Hello World for physical computing. I am a newbie and had no prior knowledge in electronics. I will try to write a few posts which will serve as a work log for me so that I can revert to these when needed/forgotten due to focusing on other priorities of life over time.

Wiring up an Arduino

I’m using a Seeeduino ADK (a Arduino Mega 2560 variant) for this post. I have simply plugged it to the computer via Micro-USB cable. I have also used a breadboard and connected a LED and a 220 ohm resistor between ground and pin 15. The register here prevents the LED from taking a damage due to 5V on which Arduino runs on.

LEDblink_bb-cropped   

WP_20141104_18_46_01_Pro

You will notice that without doing anything the LED blinks randomly along with another LED which is in-built.

Blinking from a Program

How about we write a program that can systematically after each second blinks the LED? Download and install the Arduino software from here which comes with a minimal yet effective IDE. I’ve written the following code which is quite self-explanatory:

 Untitled

I’ve pressed Control + U, then it took a few seconds to upload to the processor, and voila! The program that I have written is now successfully making the LED blink every accurate second.

Blinking Two LEDs in a Particular Order

Now I would like to exercise more power of code and blink 2 LEDs, red twice each 2 seconds and green just once when red is done. I have organized the circuit in a slightly different way now:

DoubleLEDblink_bb-cropped I have used pin 13 and pin 12 now in order to blink green and red in turn, and written the following code:

int green = 13;
int red = 12;

void setup() {                
  pinMode(green, OUTPUT);     
  pinMode(red, OUTPUT);     
}

void loop() {
  digitalWrite(red, HIGH);
  delay(1000);           
  
  digitalWrite(red, LOW);
  delay(1000);   

  digitalWrite(red, HIGH);
  delay(1000);           
  
  digitalWrite(red, LOW);
  delay(1000);           

  digitalWrite(green, HIGH);
  delay(1000);               
  
  digitalWrite(green, LOW);
  delay(1000);               
}

Here’s the final outcome:

WP_20141104_19_46_02_Pro