Saturday, April 2, 2011

Project 1 – LED Flasher – Code Overview

Posted by rinson

Open up your Arduino IDE and type in the code from Listing 2-1.
Listing 2-1. Code for Project 1
// Project 1 - LED Flasher
int ledPin = 10;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
Press the Verify/Compile button at the top of the IDE to make sure there are no errors in your code.
If this is successful, click the Upload button to upload the code to your Arduino. If you have done
everything right, you should now see the red LED on the breadboard flashing on and off every second.
Let’s take a look at the code and the hardware to find out how they both work.
Read More

Project 1 – LED Flasher

Posted by rinson

You are now going to work your way through the first four projects. These projects all use LED lights in
various ways. You will learn about controlling outputs from the Arduino as well as simple inputs such as
button presses. On the hardware side, you will learn about LEDs, buttons, and resistors, including pull
up and pull down resistors, which are important in ensuring that input devices are read correctly. Along
the way, you will pick up the concepts of programming in the Arduino language. Let’s start with a “Hello
World” project that makes your Arduino flash an external LED



For the first project, you are going to repeat the LED blink sketch that you used during your testing stage.
This time, however, you are going to connect an LED to one of the digital pins rather than using LED13,
which is soldered to the board. You will also learn exactly how the hardware and the software for this
project works, learning a bit about electronics and coding in the Arduino language (which is a variant of
C) at the same time.



Parts Required
Breadboard
5mm LED
100 ohm Resistor*
Jumper Wires

Connecting Everything


First, make sure your Arduino is powered off by unplugging it from the USB cable. Now, take your
breadboard, LED, resistor, and wires and connect everything as shown in Figure 2-1.



It doesn’t matter if you use different colored wires or use different holes on the breadboard as long
as the components and wires are connected in the same order as in the picture. Be careful when
inserting components into the breadboard. If your breadboard is brand new, the grips in the holes will
be stiff. Failure to insert components carefully could result in damage.
Make sure that your LED is connected correctly with the longer leg connected to Digital Pin 10. The
long leg is the anode of the LED and must always go to the +5v supply (in this case, coming out of Digital
Pin 10); the short leg is the cathode and must go to Gnd (ground).
When you are sure that everything is connected correctly, power up your Arduino and connect the
USB cable.




Read More

Upload Your First Sketch

Posted by rinson

Now that you have installed the drivers and the IDE and you have the correct board and ports selected,it’s time to upload an example sketch to the Arduino to test that everything is working properly before
moving on to the first project.
First, click the File menu (Figure 1-10) and then click Examples.

SELECT A PROGRAM BLINK IN EXMPLE
Next, click the Upload button (sixth button from the left) and look at your Arduino. (If you have anArduino Mini, NG, or other board, you may need to press the reset button on the board prior to pressingthe Upload button.) The RX and TX lights should start to flash to show that data is being transmittedfrom your computer to the board. Once the sketch has successfully uploaded, the words “Doneuploading” will appear in the IDE status bar and the RX and TX lights will stop flashingAfter a few seconds, you should see the Pin 13 LED (the tiny LED next to the RX and TX LEDs) start

to flash on and off at one second intervals. If it does, you have just successfully connected your Arduino,installed the drivers and software, and uploaded an example sketch. The Blink sketch is a very simplesketch that blinks LED 13 shown in Figure 1-12, the tiny green (or orange) LED soldered to the board(and also connected to Digital Pin 13 from the microcontroller).Before you move onto Project 1, let’s take a look at the Arduino IDE. I’ll explain each part of the
program.



Read More

Getting Started with Arduino

Posted by rinson

This section will explain how to set up your Arduino and the IDE for the first time. The instructions forWindows and Macs (running OSX 10.3.9 or later) are given. If you use Linux, refer to the Getting Startedinstructions on the Arduino website at www.arduino.cc.playground/Learning/Linux. I will also presumeyou are using an Arduino Uno. If you have a different type of board, such as the Duemilanove (see Figure
1-4), then refer to the corresponding page in the Getting Started guide of the Arduino website.You will also need a USB cable (A to B plug type) which is the same kind of cable used for mostmodern USB printers. If you have an Arduino Nano, you will need a USB A to Mini-B cable instead. Donot plug in the Arduino just yet, wait until I tell you to do so.


Next, download the Arduino IDE. This is the software you will use to write your programs (orsketches) and upload them to your board. For the latest IDE go to the Arduino download page athttp://arduino.cc/en/Main/Software and obtain appropriate the version for your OS.
  



Windows XP Installation
Once you have downloaded the latest IDE, unzip the file and double-click the unzipped folder to open it.You will see the Arduino files and sub-folders inside. Next, plug in your Arduino using the USB cable andensure that the green power LED (labeled PWR) turns on. Windows will say “Found new hardware:Arduino Uno” and the Found New Hardware Wizard will appear. Click next and Windows will attempt toload the drivers.This process will fail. This is nothing to worry about; it’s normal.Next, right-click on the My Computer icon on your desktop and choose Manage. The Computer
Management window will open up. Now go down to Event Manager in the System Tools list and click it.In the right hand window, you’ll see a list of your devices. The Arduino Uno will appear on the list with ayellow exclamation mark icon over it to show that the device has not been installed properly. Right clickon this and choose Update Driver. Choose “No, not this time” from the first page and click next. Thenchoose “Install from a list or specific location (Advanced)” and click next again. Now click the “Includethis location in the search” and click Browse. Navigate to the Drivers folder of the unzipped Arduino IDEand click Next. Windows will install the driver and you can then click the Finish button.The Arduino Uno will now appear under Ports in the device list and will show you the port numberassigned to it (e.g. COM6). To open the IDE double-click the Arduino icon in its folder


Read More

What Exactly is an Arduino? 3rd post

Posted by rinson

The Arduino can also be extended with the use of shields, which are circuit boards containing otherdevices (e.g. GPS receivers, LCD Displays, Ethernet modules, etc.) that you can simply connect to the topof your Arduino to get extra functionality. Shields also extend the pins to the top of its own circuit boardso you still have access to all of them. You don’t have to use a shield if you don’t want to; you can make
the exact same circuitry using a breadboard, Stripboard, Veroboard, or by making your own PCB. Mostof the projects in this book are made using circuits on a breadboard.
There are many different variants of the Arduino. The latest version is the Arduino Uno. Theprevious version, the very popular Duemilanove (Italian for 2009), is the board you will most likely seebeing used in the vast majority of Arduino projects across the Internet. You can also get Mini, Nano, andBluetooth variations of the Arduino. Another new addition to the product line is the Arduino Mega 2560;
it offers increased memory and number of I/O pins. The new boards use a new bootloader calledOptiboot, which frees up another 1.5k of flash memory and enables faster boot up.Probably the most versatile Arduino, and hence the reason it is the most popular, is the Uno, or itspredecessor, the Duemilanove. This is because it uses a standard 28-pin chip attached to an IC(Integrated Circuit) socket. The beauty of this system is that if you make something with an Arduino andthen want to turn it into something permanent, instead of using a relatively expensive Arduino board,
you can simply pop the chip out of the board and place it into your own circuit board in your customdevice. By doing so, you have made a custom embedded device, which is really cool.Then, for a couple of quid or bucks, you can replace the AVR chip in your Arduino with a new one.Note that the chip must be pre-programmed with the Arduino Bootloader (software programmed ontochip to enable it to be used with the Arduino IDE), but you can either purchase an AVR Programmerto burn the bootloader yourself or you can buy a chip ready programmed; most of the Arduino partssuppliers provide these. It is also possible to program a chip using a second Arduino; instructions are
available online for this.
Read More

What Exactly is an Arduino? 2nd post

Posted by rinson

The Arduino board is made up of an Atmel AVR Microprocessor, a crystal or oscillator (a crude clockthat sends time pulses at a specified frequency to enable it to operate at the correct speed), and a 5-voltlinear regulator. Depending on what type of Arduino you have, it may also have a USB socket to connectto a PC or Mac for uploading or retrieving data. The board exposes the microcontroller’s I/O(input/output) pins so that you can connect those pins to other circuits or to sensors.The latest Arduino board, the Uno, differs from the previous versions of the Arduino in that it doesnot use the FTDI USB-to-serial driver chip. Instead, it uses an Atmega8U2 programmed as a USB-toserial
converter. This gives the board several advantages over its predecessor, the Duemilanove. First,the Atmega chip is a lot cheaper than the FTDI chip, bringing the prices of the boards down. Secondly,and most importantly, it enables the USB chip to have its firmware reflashed to make the Arduino showup on your PC as another device, such as a mouse or game controller. This opens up a whole array ofnew uses for the Arduino. Unfortunately, moving over to this new USB chip has made it a lot more
difficult for clone manufacturers to make Arduino Uno clones.To program the Arduino (make it do what you want it to) you use the Arduino IDE (Integrated
Development Environment), which is a piece of free software in which you write code in the languagethat the Arduino understands (a language called C). The IDE lets you to write a computer program, whichis a set of step-by-step instructions that you then upload to the Arduino. Your Arduino will then carryout these instructions and interact with whatever you have connected to it. In the Arduino world,programs are known as sketches.The Arduino hardware and software are both open source, which means that the code, schematics,design, etc. can be taken freely by anyone to do what they like with them. Hence, there are many cloneboards and other Arduino-based boards available to purchase or to make from a schematic. Indeed,there is nothing stopping you from purchasing the appropriate components and making your ownArduino on a breadboard or on your own homemade PCB (Printed Circuit Board). The only caveat thatthe Arduino team imposes is that you cannot use the word “Arduino.” This name is reserved for theofficial board. Hence, the clone boards have names such as Freeduino, Roboduino, etc.
As the designs are open source, any clone board is 100% compatible with the Arduino and therefore any software, hardware, shields, etc. will also be 100% compatible with a genuine Arduino.
Read More

What Exactly is an Arduino ?

Posted by rinson

Figure 1-1. An Arduino Uno


Wikipedia states “An Arduino is a single-board microcontroller and a software suite for programming it.The hardware consists of a simple open hardware design for the controller with an Atmel AVR processorand on-board I/O support. The software consists of a standard programming language and the boot loader
that runs on the board.”To put that in layman’s terms, an Arduino is a tiny computer that you can program to process inputs
and outputs between the device and external components you connect to it (see Figure 1-1). TheArduino is what is known as a Physical or Embedded Computing platform, which means that it is aninteractive system that can interact with its environment through the use of hardware and software. Forexample, a simple use of an Arduino would be to turn a light on for a set period of time, let’s say 30seconds, after a button has been pressed. In this example, the Arduino would have a lamp and a button
connected to it. The Arduino would sit patiently waiting for the button to be pressed; once pressed, theArduino would turn the lamp on and start counting. Once it had counted for 30 seconds, it would turnthe lamp off and then wait for another button press. You could use this setup to control a lamp in ancloset, for example.You could extend this concept by connecting a sensor, such as a PIR, to turn the lamp on when ithas been triggered. These are some simple examples of how you could use an Arduino.
The Arduino can be used to develop stand-alone interactive objects or it can be connected to acomputer, a network, or even the Internet to retrieve and send data to and from the Arduino and thenon that data. In other words, it can send a set of data received from some sensors to a website, whichcan then be displayed in the form of a graph.The Arduino can be connected to LEDs, dot matrix displays (see Figure 1-2), buttons,switches,motors, temperature sensors, pressure sensors, distance sensors, GPS receivers, Ethernet modules, orjust about anything that outputs data or can be controlled. A look around the Internet will bring up awealth of projects where an Arduino has been used to read data from or control an amazing array of devices.
Read More