Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino Development Cookbook

You're reading from   Arduino Development Cookbook Over 50 hands-on recipes to quickly build and understand Arduino projects, from the simplest to the most extraordinary

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781783982943
Length 246 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Cornel M Amariei Cornel M Amariei
Author Profile Icon Cornel M Amariei
Cornel M Amariei
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Power on – Arduino Basics FREE CHAPTER 2. Blinking LEDs 3. Working with Buttons 4. Sensors 5. Motor Control 6. More Output Devices 7. Digital Communication with Arduino 8. Hacking A. Electronics – the Basics Index

Uploading code to Arduino

It's time to power on the Arduino board and make it do something. In this recipe, we will connect the Arduino to the computer and upload an example sketch from the Arduino IDE.

Getting ready

To execute this recipe, the following are the components required:

  • A computer with the Arduino IDE installed
  • An Arduino board connected to the computer via USB

How to do it…

Follow these steps:

  1. Connect the Arduino to the computer using a USB cable. If everything is properly connected, the green LED light will turn on.
  2. If this is the first time the Arduino has been connected to the computer, driver installation might be required. Please follow the Connecting Arduino recipe to properly set up the Arduino board.
  3. Start the Arduino IDE and, in the Menu Bar, go to File | Examples | 01. Basics and click on the Blink example. This will load the Blink sketch.
  4. Make sure your Arduino board is selected in the Board menu. The menu can be found in the Menu bar in Tools | Board.
  5. We need to check whether the correct serial port is selected. Under Tools | Serial Port, we can see all available serial port devices connected to the computer. On Windows, each port will be labeled as COM followed by a number. Usually, Arduino installs on COM3, but not always. A fast way to check which serial port the Arduino is connected to is to unplug the cable and see which COM port disappears in the menu. That will be our Arduino board. In the Mac, the port should be called something beginning with /dev/tty.usbmodem or /dev/tty.usbserial.
  6. Click on the Upload button on the Tool Bar. If everything runs properly, the TX RX LEDs on the Arduino board will begin blinking for a short time until the upload is done. After this, one LED light on the Arduino Board should slowly blink.

How it works…

When we upload a sketch to the board, the Arduino software first compiles the code. If there is an error in the code, it will write it in the Status Display area and will stop the upload. If no errors are found, it will begin writing the compiled code to the board. Errors will appear if the board or serial port is not properly selected. When everything is correctly set up, the TX RX LEDs will blink, meaning data is being transferred between the computer and the Arduino board. When the transfer is done, the board will reset and the code will immediately begin executing.

The code is stored in the Arduino board until it is erased or replaced by another code. We can take the board and plug it into a battery or to another computer, and it will still execute this blinking.

You have been reading a chapter from
Arduino Development Cookbook
Published in: Apr 2015
Publisher:
ISBN-13: 9781783982943
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime