element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Tutorials
  • Products
  • Arduino
  • Arduino Tutorials
  • More
  • Cancel
Arduino Tutorials
Blog Getting to Know Arduino : Part 1 : Hello, World!
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Tutorials to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: cstanton
  • Date Created: 28 Mar 2014 9:24 AM Date Created
  • Views 9702 views
  • Likes 15 likes
  • Comments 33 comments
  • tutorial
  • min
  • 10
  • arduino uno
  • arduino-uno
  • ardunio
  • microcontrollers
  • 10minarduino
  • programming
  • getting-to-know
  • atmega328
  • tutorials
  • atmega328p
  • microcontroller
  • minute
  • 10minutearduino
  • uno
  • getting_to_know
  • getting to know
  • c++
  • arduino
  • feature tutorial
  • feature_tutorial
  • atmel
Related
Recommended

Getting to Know Arduino : Part 1 : Hello, World!

cstanton
cstanton
28 Mar 2014

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Next Guides:

Getting to Know Arduino : Part 2 : Hello, Again!

Getting to Know Arduino : Part 3 : Taking your Temperature

 

I recorded a video to introduce the Arduino UnoArduino Uno and how to get started with it. The premise was that you didn't need to add anything extra, except for an A to B USB cableA to B USB cable (always check the type you need for the Arduino you have) because although you can connect an external power supply it can be powered purely from the USB, and you could get code running with a few simple steps on Microsoft Windows to make an LED (Light Emitting Diode) start to flash on your board.

image

The Arduino I showed in the video was a revision 3 board, there have been a few versions so far, in the image (from zenbike.co.uk) you can see an earlier version, but it nicely maps out the connectors on the board. I think in the recent version the reset button has moved, but that makes little difference overall. What it doesn't note on the image is that any socket with the ~ (tilde) symbol next to it can be used as a Pulse Width Modulation output. This is a way of having a digital signal pretend that it's analogue but typically you don't need to worry about this until you've got some hardware that you need to output to which needs it.

 

The first instruction we can make the Arduino perform is to flash an LED, which is often considered the "Hello, World!" of getting started. The example code 'Blink' will do this for you, it flashes the LED marked 'L' on the board. This LED is also linked up with the breakout pin '13' like many connections on the board, some go through components and others do not, but they ultimately connect to the ATMega328 micro-controller processor on the board, which is the brains of it all.

 

We'll need to tell the Arduino what we want it to do and for that we can use the Arduino Integrated Development Environment (IDE), this environment contains a text editor and a console window which shows you any error messages and how successful the software has been when communicating with the Arduino. You can get the IDE for more than just Microsoft Windows, there are Mac OS and Linux variants. You might want to check your package manager and software repository for whether or not there is a version pre-packaged for your version of Linux. For example you can use apt-get on Ubuntu to "apt-get install arduino" from a terminal.

 

It's often best to get the latest non-beta version of the Arduino IDE, but if you have a board that is newer then usually this isn't supported in the 'stable' builds and a beta or nightly build is required.

 

After installing the Arduino IDE in Microsoft Windows, you'll need to connect your Arduino Uno if you haven't already. It may help to reconnect it so that it re-detects the device and installs the driver. Then you can run the IDE. To be able to upload code to the device you will need to know what COM port it is running on.

 

To do this, open your Start menu, navigate to Control Panel, once the window appears, open System and then navigate around the tabs/options until you find Device Manager. With this window open, click the + symbol next to "Ports (COM & LPT)" and the Arduino should be listed along with its COM and a number.

 

In the IDE, go to the Tools menu and then expand Board and choose your Arduino, then do the same, but go to Serial Port and choose the one that it stated in Device Manager.

 

Now to get the LED flashing, choose the File menu, go to Examples and then 01.Basics, under this menu navigate to Blink. To get this running on your Arduino you can now either click on the arrow next to the tick icon or choose the Sketch menu and click Verify/Compile. Now the 'L' LED on your board should be blinking!

 

Feel free to change the code, copy and paste bits to see what works and what doesn't.

 

This will open a new window with the following code in it:

 

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {        
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
       

 

This is what is referred to as a 'sketch' in IDE terms, however it is actually using a low level programming language called C++ which has been around for a notable amount of time, most of the software you use is written with C++ including Microsoft Windows and parts of Linux.

 

Line 01 and 06 in the code uses text that the IDE recognises as a special arrangement so that it knows to ignore anything typed between them (it denotes that whatever is between them is a comment. On line 08 it shows the line starting with a similar arrangement that means to ignore that entire line as a comment.

 

int led = 13;
       

 

This line is literally mathematical, it could be said that programming is inherently mathematical because processors are just doing calculations and moving numbers around. So this line in particular is declaring that the english word, led is a certain type of variable (kinda like a bucket that can only contain something of a particular thing and its contents can vary) and that is called an integer, which means a whole number. As opposed to a number with a decimal (or a real number). We're then making the contents of the variable (or bucket) equal to the number 13. What then terminates the line is a semicolon and this is required by the IDE to know that we're finished putting commands on the line.

 

The IDE, or specifically the part of it that changes our near-english (sketch/programming) into a language that the Arduino can understand typically operates on a line by line basis, which is like how old typewriters used to work where by you normally couldn't go back and change what you had just created/read and had to continue (probably a bad analogy).

 

void setup() { }
      

 

The setup declaration is called a function, anything within { } is processed by the IDE, 'setup' is a reserved name for the function and it means that it is ran before anything else within the sketch. Like the variable led is of a type int, the setup function is of a type void. We don't have to worry about that for now. pinMode() is another function that is referred to and you can read up about it.

 

void loop() { }
      

 

The loop function is another reserved name that means anything within { } is ran again from the first { when it reaches the last line or instruction before the final }. The speed of this is governed by how fast the microprocessor, for example the ATMega328 can get through the instructions per second. The digitalWrite() and delay() functions can also be read up about on the Reference section of the Arduino site.

 

Hopefully you have found this useful to get started with your Arduino and it has introduced you to some new concepts for programming for micro-controllers. The best way to learn is trial and error, so don't be afraid to mess around with the code or read up about it.

 

If you have any questions, problems or otherwise please leave a comment! You can also find more information in The specified item was not found. community group!

  • Sign in to reply

Top Comments

  • cstanton
    cstanton over 11 years ago in reply to Former Member +5
    Yep. SPI is broken out onto the header sockets and also the ISCP header (one of the block of 6 pins). You can read more here: http://arduino.cc/en/Reference/SPI and there's a schematic for the Uno R3 here…
  • mcb1
    mcb1 over 11 years ago +4
    Nice work. I bet the newbies here don't search for it and still ask, but at least there is a good place to point them to. Mark
  • Former Member
    Former Member over 11 years ago in reply to cstanton +3
    Thank you for the very prompt and helpful response. I'll probably use my Rasberry Pi for experimentation and prototyping and then transfer to Arduino for a more permanent solution.
Parents
  • Former Member
    Former Member over 11 years ago

    A very useful and succinct introduction.  I have a Rasberry Pi but the Arduino is probably better for embedded jobs. I guess that the general IO ports can be configured for SPI and so on?

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    While the Raspberry Pi is a completely different processor, at the core it is really just another make of processor but on steroids. The only thing that makes the Arduino better in your comparison is that the Pi is running Linux as it's operating system where as the Arduino is running no OS to speak of. If you grab a book on C++ or C and another on the particular processor used on the Pi there's nothing stopping you from doing 10 times more on the Pi than you could ever hope to do on the Arduino. Don't get me wrong, Linux is great if you want or need to display windows and handle disk drives and WiFi etc. but all I'm saying is that there is no real obstacle to making the Pi put the Arduino to shame in most aspects. Why do I say most? Only because there is less groundwork to do on the Arduino to set it up and configure but only because it has so much less hardware on board than the Pi. I could probably write a book on the ins and outs of why they both survive in the market place, but in a nutshell if you want to do comparatively very little then the Arduino will get you there faster and if you want do a lot of really complex stuff then it takes a lot of skill to squeeze it out of an Arduino so the Pi is the path of least resistance. I recently completed a project that used an Arduino class processor to do networking, data accumulation and a whole lot of other stuff and it was only possible because I wrote all of the code as highly optimised my self except for a few libraries and it was for various reasons the way to go, but it does demonstrate that there is a lot of overlap in the usage cases for either Arduino or Pi.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to Former Member

    Very well put and totally agree, long gone are the days that I would even contemplate creating a device driver on windows, just way to darn hard. Give me a USB connection and an external device any day and it would be way quicker to a good solution. The abstraction that windows and linux puts over the hardware is excellent for the audience it is aimed at. That audience is not the hardware engineer.

     

    But Windows, Linux and Android (Really Linux under the sheets) etc do make great master controllers, gateways and processor intensive engines, off loading the real IO to those devices that are better suited to handling it

     

    So as much as knowing what your software and libraries are doing is very important, so is understanding your underlying hardware and runtime environment

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Robert Peter Oakes

    I have used the filling a pool example to explain to total newcomers.

    You can either stand there and hold the hose, until it fills (ie Delay() )

    or you can prop it up and come back every so often to check on it (ie the Millis() timer )

     

    In the first you can't do anything else, but fill the pool, in the later you can do other things.

     

     

    The C64 and Amiga were great as they had dedicated Graphics and Sound processors ...

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to mcb1

    Excellent analogy, I'm a firm believer in using real world examples of things that are often more intuitive for a newbie than programmer's speak. I'm hopeful we as educators all learn from each other on how to impart the correct "feel" for what is a good approach or not. Sound embedded programming is becoming a dying art as we distance ourselves from the nitty gritty. Well maybe not so much dying, but certainly a select club of tried and tested old salts when really it's all just logical and really at the level that a lot of children could do given the right encouragement. Kids are logical (in a programmers sense), but then as they become older and more set in their ways their past experiences affect their ability to stand out side looking in to develop an understanding.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Former Member

    Thanks

    I used another example for libraries.

    Ask the volunteer to Sit on the Chair.

     

    Once they have, ask them how they knew what to do.

    In order to do this you already knew to approach the chair, turn around and lean forward to balance, while lowering yourself until your backside was resting on the chair.

    So in this case Sit was an instruction using the Sit Library and Chair was the object to apply it to, compared with desk or even the floor.

     

    Again these are simplistic real world examples that kids can relate to, or at least match and move forward.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to Former Member

    This is true for RPI, but one thing stands out. If I wanted real time execution, I could use an external clock  chip programmed to interrupt a little before the event and get almost real time execution. This is better than my PC Windoze.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • clem57
    clem57 over 10 years ago in reply to Former Member

    This is true for RPI, but one thing stands out. If I wanted real time execution, I could use an external clock  chip programmed to interrupt a little before the event and get almost real time execution. This is better than my PC Windoze.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube