Here we are. The time has come to build our first projects. We’ll meet the components in our disposal, figure out how to connect them, and then all we have to do is code. Code. Code… Code something useful that can make our everyday lives easier, or perhaps something fun that can entertain us. There is no stopping you from building anything… from the silliest children’s toy to the next spaceship that will travel to Mars!
Normally, inside setup we make the initial configuration of the uC and any libraries we may be using. Then, in the loop function we write the main code we want being executed over and over again, checking conditions and taking actions.
Before we move on with examining electronic components, we have to get introduced to the single most useful tool in our workbench that will be present in all of our projects. This is the breadboard. The breadboard will be the basis for our circuits. We will place the various components in the holes and then use extra wires to make the interconnections.
From inside, the breadboard has the structure shown above.
The inner holes are connected together vertically. So, a group (column) of 5 holes in the breadboard represents a node in the circuit. We place the leads of a component in different columns, and connect the leads of different components together with wires. The holes in the middle are not connected together. These holes have a special purpose. This is where we place ICs, so that two opposite pins are not short-circuited.
The outer holes are connected together horizontally. These interconnected holes form the power lines. This is where we bring the and voltage references. From there we take those voltages with wires to the components. Attention must be payed, since some breadboards break these power lines in the middle (red parts shown in the figure). In that case, left and right sides are created on the power lines and are not connected together.
The first component we will see is the Light Emitting Diode (`LED`). LEDs are devices that when you run a current through them, they emit light. They can emit light of different frequencies, so we can encounter LEDs of a number of colors. They come in different forms and sizes. Common LEDs being used widely are the 5 mm round ones (shown to the left). There is a wide array of applications with the LEDs. We can use them to give visual indications, light up a room, or even transfer information wirelessly (like with the IR LED in your TV remote).
LEDs have a specific voltage (a.k.a. forward voltage) on which they like to be operated. On the forward voltage, they light up in full brightness. If we give them a smaller voltage, they will still work, but they will just be less bright. We can’t operate an LED directly on voltages bigger than the forward voltage. If we can’t supply the (forward) voltage needed, we can still make use of a higher voltage by adding a current limiting resistor.
Different LEDs, in size and color, have different forward voltages. Though, we don’t necessarily have to look for the forward voltage of every LED we use. For the 5 mm (or 3 mm) round LEDs (of any color) and a supply, a resistor will always be a safe choice.
If we connect the anode of an LED to an output pin of an Arduino, we can turn the LED on by writing HIGH to the pin. If we connect the cathode of an LED to an output pin of an Arduino, we can turn the LED on by writing LOW to the pin.
Let’s write some code now. We’ll start with the famous blink example. This example uses an LED and an output pin on an Arduino to control the LED. In the code, we turn the LED on for a second, then we turn it off for another second, and then we repeat.
A buzzer has polarity. The positive side always goes to a higher voltage than the negative side. You should normally use a buzzer with a resistor at .
The example below is basic demonstration of the operation of a buzzer. It just plays a series of beeps, repeatedly.
If you want to do something more interesting with a buzzer, look at the [`tone()`](http://arduino.cc/en/Reference/tone#.UyJPyIUcKpe) and [`noTone()`](http://arduino.cc/en/Reference/NoTone#.UyJ31YUcKpc) functions that let you excite the buzzer at different frequencies, thus creating notes and being able to compose music. Check them out!
In this tutorial you’ve learned about LEDs and buzzers. At this point, you know how to connect them and how to use them. Now clone the examples to your account, try out some variations in the code, and see how it all works out. We’ll get back next time with some new components!
The Schematics were based on fritzing.
Images are CC BY-NC-SA 3.0.