Arduino

1 Introduction - Getting connected/LED control

  • Arduino is an open source physical computing platform based on a simple input/output (I/O) board and a development environment that implements the Processing language.
  • Arduino can be used to develop standalone interactive objects or can be connected to software on your computer.
  • The Arduino boards come in many different variations,
  • Here are some examples:
  • The Arduino Uno

Arduino_uno.jpg

  • The Arduino nano (this is the one we will use).

Arduino_nano.jpg

  • Like all microcontrollers, including the Genie microcontroller. All will have a pinout diagram, explain which pins will be connected to which input or output pins.
  • Below is the pinout diagram for the Arduino Nano.

Nano_pinout.png

Learn It

  • In this project, you will learn to code basic Arduino projects, called 'Sketches'.
  • You can download the Arduino IDE by clicking on this link.
  • To do this you will need to use the Adruino IDE (Integrated Development Environment).
  • This can be found in the S&C and Computing file on your desktop.
  • Once you have opened the Arduino file, you will see the program below.
  • The program is divided into 3 main sections,
    1. The variable declaration section.
    2. The setup section.
    3. The loop section

Arduino_start.jpg

  • Variable declaration section. Another important choice that programmers face is where to declare variables. The specific place that variables are declared influences how various functions in a program will see the variable. This is called variable scope.
  • The setup() function/section is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup() function will only run once, after each powerup or reset of the Arduino board.
  • The loop() section. After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

Try It

  • You will first need to connect your Arduino Nano to the computer and ensure it is setup correctly.
  • Connect the Arduino as shown below.

Arduino_connect.jpg

  • You then need to ensure the Arduino is connected to your computer.
  • Check the following options are correct.
  • You are using the correct Arduino

arduino_select.jpg

  • Select the communications port (COM port)

comm.jpg

  • Select the correct microcontroller type.

processor.jpg

  • You can click on upload button with a blank sketch to check if it is connected and everything will work.

upload_button.jpg

  • When it has uploaded, it will say done uploading at the bottom of the IDE, you then know the Arduino is connected and working.

done_uploading.jpg

  • You are now ready to start programming.

Build It

  • We are going connect an LED to one output and start programming.
  • Connect the LED to output D2 as shown below.

Wiring_LED.jpg

  • Bring up the the Arduino IDE and we are going to start writing out first code.
  • First we want to declare the intereger variable ledPin (or any name you want) in the variable declaration section.

declare_pin.jpg

  • We then need to setup the pin D2 as an OUTPUT so the Arduino know to use this pin as an output.
  • We declare it a ledPin as we have chosen to use as the variable name.

output_declare.jpg

  • Now we need to add the code to get the LED to flash.
  • This requires a code to turn the LED on and off as well as a delay between the on and off sequence.

Flashing_loop.jpg

  • Once you have written the code, you can click on the Upload button to and see if the program works.

upload_button.jpg Done_uploading.jpg

Badge It