Arduino Electronics Electronics Design Electronics Programming Team Work XE Week 10 - Intro to Arduino and Flashing LEDs

Arduino Programming and Flashing LEDs

Choose ‘Examples ’ on the menu on the left, then ‘Basic ’ and ‘Blink ’. The Blink sketch is now displayed in the code area.Programming

I’m reliably informed that most people simply need to download the Arduino IDE to start programming (it asks you to pay but you can skip this if you are tight). I (as usual) had to find a way to work with my Chromebook. Fortunately there is a web editor and it recognised the Orange Pip when plugged in via USB (Chromebooks are notorious for lacking proper device management). I found this post that goes into more detail about connecting and programming Arduino via a Chromebook – it has troubleshooting tips and solutions that I thankfully didn’t require.

This is what the web version Arduino IDE (Integrated Development Environment) looks like, I stole it from the “getting started” Arduino page.

Arduino IDE

Section 1:

  • Your Sketchbook: a collection of all your sketches (’sketch ’ is what programs you upload on your board are called).
  • Examples: read-only sketches that demonstrate all the basic Arduino commands (built-in tab), and the behaviour of your libraries (from the libraries tab).
  • Libraries: packages that can be included to your sketch to provide extra functionalities.
  • Serial monitor: a feature that enables you to receive and send data to your board via the USB cable.
  • Help: helpful links and a glossary about Arduino terms.
  • Preferences: options to customise the look and behaviour of your editor, such as text size and colour theme.

Section 2:

  • Displays the options for each menu item (section 1).

Section 3:

  • The code area where you write code, verify it and upload it to your boards.
  • Select the board or port to use.
  • Save your sketches on the cloud and share them.

 

Coding Basics

The structure of Arduino programming is pretty simple, every program has a minimum of 2 blocks: Preparation & Execution.

Each block has a set of statements enclosed in curly brackets. The simplest programs require a ‘Setup’ and ‘Loop’ function:

setup and execution

The ‘setup’ function is executed first and only once when the program in initialised. It is used to initialise pin modes and start serial communications – it has to be included even if there are no statements to execute.

After the ‘setup’ function runs, the program moves to the execution block. The execution block used to run functions like reading inputs, triggering outputs, etc..

In the above example ‘loop’ function is a part of execution block. As the name suggests, it executes the set of statements repeatedly.

 

Flashing LED

The first thing we were task with was to program the Adruino to make an LED flash using the “Blink” example available in the IDE – I’ll walk you through that now:

  • First choose ‘Examples ’ (1) on the menu on the left, then ‘Basic ’ (2) and ‘Blink ’ (3). The Blink sketch is now displayed in the code area – example sketches come with a bunch of greyed out text that explains how to set up the hardware and what the code does. Read it and then get rid of it to tidy up the code area (4).

IDE steps

  • Second if you haven’t already, plug in your Arduino to your PC via USB cable. If it isn’t immediately recognised then select it via the drop-down menu.

Arduino selection

  • Third Verify (grey tick) and Upload (grey arrow) the code to the Arduino. The built in LEDs will flash a number of times as the program is loaded and then hopefully, as the code states, the on built in LED will flash 1 second on, 1 second off.

  • Forth understand the code and add an external LED. So the code states in the setup that the built in LED is set as an output – “pinMode(LED_BUILTIN, OUTPUT);”. But the digital pin no.13 is linked to the built in LED so if we connect an LED to pin no.13 and GND then it should flash along with the built in one.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by: Wordpress
Skip to toolbar