Home   MosaicPresentation format
<http://cnfolio.com/Arduino>
Group Design Project – B202

Getting started with Arduino




"Prototyping is at the heart of the Arduino Way: we make things and build objects that interact with other objects, people, and networks. We strive to find a simpler and faster way to prototype in the cheapest possible way."

Source: Banzi, M. (2008). Getting started with arduino. Sebastopol, CA, USA: O'Reilly Media, Inc.





Preparation steps:
  1. Download and install the Arduino software
  2. Connect the Arduino board to the computer using the USB cable
  3. If necessary, install the FTDI device drivers when connecting the Arduino board





After starting the Arduino software, change the configuration to select the currently connected Arduino board.







After starting the Arduino software, change the configuration to select the serial COM port that is connected to the Arduino board.







In Microsoft Windows 7, the COM port is found by using the Device Manager in the Control Panel.







Connecting an LED to the Arduino



Sketch source code

#define LED       1     // 13 is onboard LED
#define INTERVAL  2000  // milliseconds

void setup()
{
  pinMode( LED, OUTPUT );
}

void loop()
{
  digitalWrite( LED, HIGH );
  delay( INTERVAL );
  digitalWrite( LED, LOW );
  delay( INTERVAL );
}


Comments


Use good programming practices:
  • Define macro constants to have more meaningful labels for pin connections.
  • Specifically setup the input or output mode of digital pins instead of relying upon default settings.

The setup() function runs once when the Arduino board is powered on.

The loop() function repeats continuously as long as the Arduino board is powered on.

There is a default onboard LED connected to pin 13.

An LED can also be connected directly to pin 13 and ground.





Connecting a push button and an LED to the Arduino



Sketch source code

#define LED       13
#define BUTTON    1
#define INTERVAL  50  // milliseconds

void setup()
{
  pinMode( LED, OUTPUT );
  pinMode( BUTTON, INPUT );
}

void loop()
{
  if ( digitalRead( BUTTON ) == HIGH )
    digitalWrite( LED, HIGH );
  else
    digitalWrite( LED, LOW );

  delay( INTERVAL ); // debouncing
}


Comments


The digitalRead() function only returns 2 values, HIGH when the push button is pressed down or LOW when the push button is released.

Similarly, the digitalWrite() function accepts 2 states, HIGH to turn the pin on or LOW to turn the pin off.

The delay() function at line 18 is a rudimentary method of debouncing the the noise due to the mechanical switch in the button not making perfect contact.