An Introduction to An Introduction to Arduino PDF GUIDE: http://antoinettejcitizen.com/files/AICCM_Arduino.pdf

Michelle Woulahan Antoinette J. Citizen Creative media facilitator at City of Melbounre Electronic media artist Events listing: http://bit.do/techEvents Website: antoinettejcitizen.com A is a very small computer on a single integrated circuit (IC). All computers have several things in common:

• CPU (central processing unit) that executes programs. • RAM (random-access memory) where it can store variables. • Input and output devices for interaction.

Desktop computers are “general purpose computers” that can run any of thousands of programs. Microcontrollers are “special purpose computers.” Microcontrollers do one thing well.

Microcontrollers are often embedded onto a single printed circuit board. This board provides all of the circuitry necessary for a useful control task. The intention is that the board is immediately useful to an application developer, without them needing to spend time and effort in developing the controller hardware.

BASIC Stamp Microcontroller: • PIC • Parallax SX processor.

mbed Microcontroller: • ARM Cortex

IOIO OTG Microcontroller: • Microchip Technology PIC

Arduino Microcontroller: Atmel AVR microcontroller • ATmega8 • ATmega168 • ATmega328 • ATmega1280 • ATmega2560 Arduino Single board microcontrollers like the Arduino are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. Arduino is an open-source prototyping platform based on easy-to-use hardware and software.

Examples: http://www.creativeapplications.net/category/arduino-2/

There are lots of different types of Arduino boards. UNO is currently the most common and easily the best documented and best supported of the .

Micro- Input System Clock Digital Analog Flash Item Controller Voltage Voltage Speed I/O Inputs PWM Space Arduino Uno - R3 ATmega328 7-12V 5V 16MHz 14 6 6 32Kb

Arduino Leonardo ATmega32U4 7-12V 5V 16MHz 20* 12 7 32Kb

Arduino Pro ATmega328 3.35 -12V 3.3V 8MHz 14 6 6 32Kb 5V

Arduino Yun ATmega32u4 5V 5V 16MHz 20 12 7 32Kb Atheros AR9331 3.3V 16MB

Arduino Mega ATmega2560 7-12V 5V 16MHz 54 16 14 256Kb

Arduino Pro Mini ATmega328 5 - 12V 5V 16MHz 14 8 6 32Kb

Arduino Fio ATmega328P 3.35 -12V 3.3V 8MHz 14 8 6 32Kb

LilyPad ATmega32U4 3.8V-5V 3.3V 8MHz 9 4 4 32Kb Arduino-compatible

DF Robot Freetronics

ArduPhone Barebones

Cheapduino Lillypad Single-board Computers

Single board computers like the use application processors rather than microcontrollers. These boards operated more like most computers you would normally use - you can plug in a display, keyboard and mouse, and run an operating system and applications.

Beagle board Raspberry Pi 3

• AM335x 1GHz ARM® Cortex-A8 • 1.2GHz 64-bit quad-core ARMv8 CPU • 512MB DDR3 RAM • 1GB RAM • 4GB 8-bit eMMC on-board flash storage • Micro SD card slot • 3D graphics accelerator • VideoCore IV 3D graphics core • 1 USB host • 4 USB ports • 2x 46 pin headers • 40 GPIO pins • Mini HDMI port • Full HDMI port • Ethernet port • Ethernet port • NEON floating-point accelerator • Combined 3.5mm audio jack and • 2x PRU 32-bit microcontrollers Connectivity composite video • Camera interface • Display interface • 802.11n Wireless LAN • Bluetooth 4.1

Arduino uno: board layout Sidekick components

• Breadboard x 1 • Photo resistor x 1 • Green LED x 5 • Diode x 1 • Red LED x 5 • Buzzer x 1 • RGB Common Anode LED x 1 • Button x 5 • Ceramic Capacitor(10nF x 10+100nF x 10) • Switch x 5 • Aluminum capacitor(100uF x 5) • Mini Servo x 1 • Resistor(330R x 10+1k x 10+10k x 10) • Potentiometer with knob x 1 • Tilt switch x 1 • Breadboard jumper wire x 25 (5x long, 20 x • Thermistor x 1 short) Breadboards A breadboard is a solderless device for temporary prototype with electronics and test circuit designs. Electronic components can be interconnected by inserting their leads or terminals into the holes and then making connections through wires where appropriate. The breadboard has strips of metal underneath the board and connect the holes on the top of the board. The metal strips are laid out as shown below.

Rows of the same number in colums A-E and rows in columns F-J are connected.

Power rail often used for positive and negative(GND) voltage First sketch: Blink

330 OHM Resistor Negative Positive (longer leg) (orange, orange, brown)

• Open sketch: File > Examples > Basic > Blink • Create an “int” variable called LED, set it to the corresponding arduino digital pin number. • Change LED_BUILTIN to LED

int LED = 7;

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

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

Now try changing the delay number to make LED blink faster or slower. Resistor colour code arduino intergrated development enviroment (ide)

1. Verify: Compiles and approves your code. It will catch errors in syntax (like missing semicolons or parentheses). 2. Upload: Sends your code to the 101 board. 3. New: This buttons opens up a new code window tab. 4. Open: This button will let you open up an existing sketch. 5. Save: This saves the currently active sketch. 6. Serial Monitor: This will open a window that displays any serial information your 101 board is transmitting. It is very useful for debugging. 7. Sketch Name: This shows the name of the sketch you are currently working on. 8. Code Area: This is the area where you compose the code for your sketch. 9. Message Area: This is where the IDE tells you if there were any errors in your code. 10. Text Console: The text console shows complete error messages. When debugging, the text console is very useful. 11. Board and Serial Port: Shows you what board and the serial port selections. Select Your Board: Arduino/Genuino UNO

Before we can start jumping into the experiments, there are a few adjustments we need to make.

This step is required to tell the Arduino IDE which of the many Arduino boards we have. Go up to the Tools menu. Then hover over Board and make sure Arduino/Genuino UNO is selected.

Select a Serial Port

Next up we need to tell the Arduino IDE to which of our computer’s serial ports the 101 is connected. Again,, go up to Tools, hover over Port, and select your 101’s serial port. This will have Arduino 101 next to the port number in parentheses.

Window Users: This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). If there are multiple COM ports available, the UNO is likely the highest numbered port in the list. To be certain, you can also disconnect your UNO and reopen the menu; the entry that disappears should be the UNO. Reconnect the board and select that serial port.

Mac Users: Select the serial device of the UNO from the Tools, then hover over Port. On the Mac, this should be something with /dev/tty.usbmodem or /dev/tty.usbserial in it. Multiple BlinKs

We will edit the previous sketch to add two more LED variables.

Add two new int for the two int LED = 9; added LEDs. int LED2 = 10; int LED3 = 11;

void setup() {

pinMode(LED, OUTPUT); Add pinMode for the two pinMode(LED2, OUTPUT); added LEDs. pinMode(LED3, OUTPUT);

} void loop() {

digitalWrite(LED, HIGH); digitalWrite(LED2, HIGH); digitalWrite(LED3, HIGH); Add digitalwrite HIGH and LOW sequence for all LEDs delay(1000);

digitalWrite(LED, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW);

delay(1000); } fade

We use anaologWrite(pin number,0-255) rather than digitalWrite(pin number,HIGH/LOW) in order to change the brightness of the LED. 0 being off and 255 being the brightess. AnalogWrite only works with PWM pins - on the Arduino UNO PWM are pins 3,5,6,9,10,11.

Learn more about PWM here - https://www.arduino.cc/en/Tutorial/PWM

Make sure you connect to a PWM pin!

• Open sketch: File > Examples > Basic > Fade

int led = 9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by

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

void loop() {

analogWrite(led, brightness); // set the brightness of pin 9:

brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } delay(30); } button input

• Open sketch: File > Examples > Digital > Button

const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }

void loop() {

buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } SHields

Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities.

Ethernet Shield GPS shield

Audio Shield

Motor Shield

Proto Shield Library Manager

Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays. There are hundreds of additional libraries available on the Internet for download.

To install a new library into your Arduino IDE you can use the Library Manager (available from IDE version 1.6.2). Open the IDE and click to the “Sketch” menu and then Include Library > Manage Libraries.

You can also manually install libraries that are not available in the manager by copying the library folder into Documents > Arduino > libraries servo

Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. As the servo motor already contains a driver circuit, it is easy to control with an Arduino - no other circuitry required!

Applications: • Robotics • Animatronics • Radio Control Cars/Boats/Planes

Advantages: • Low cost • Variety - There is a wide range of sizes and torque ratings • Simple to control using Arduino • Up to 12 servos can be connecting using the Arduino servo library

Limitations: • Limited range of motion - Most servos are limited to 180 degrees of motion. • Moderate precision - Positioning accuracy and repeatability of +/- 1 degree is typical. • Jitter - The feedback mechanism in the servo will actively try to correct any drift from the target position. This constant adjustment can create annoying twitches while trying to hold a steady position. If this is a problem for your application, consider a stepper motor instead. Some interesting projects using servos:

The Plot Clock - https://www.youtube.com/watch?v=NiGG9Lcrni8 Arduino Hexapod - https://www.youtube.com/watch?v=4a5R4umrRpA Robotic Arm - https://www.youtube.com/watch?v=B2fl8-L6xcA Teaching Robot - https://www.youtube.com/watch?v=bLnAJ-mSElE

Connecting to Arduino:

Servo motors have three wires: power, ground, and signal.

The power wire is typically red, and should be connected to the 5V pin on the Arduino board.

The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board.

The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board.

Ground (GND) 180° Power (5V) Signal (digital pin) Controlling a servo: The sketch below is an example from the Arduino IDE. EXAMPLES > SERVO > SWEEP

This code uses the Servo library, you can learn more about this library here - https://www.arduino.cc/en/Reference/Servo

This sketch will “sweep” the servo motor by going through every position (0 - 180) and back again with 15 millisecond delay between each position.

#include

Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }

void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable ‘pos’ delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable ‘pos’ delay(15); // waits 15ms for the servo to reach the position } }

Try replacing the void loop function with the following:

void loop() { myservo.write(0); // tell servo to go to position ‘0’ delay(500); // wait 500ms myservo.write(100); // tell servo to go to position ‘100’ delay(500); // wait 500ms }

Instead of sweeping through every position as per the previous example, the above code will make the servo go from position 0 to position 100 as fast as it can. A longer delay is required as the servo needs time to get to its position before the next position signal is sent; otherwise the new position will overwrite the previously sent position and it servo will behave erratically. Controlling a servo with a potentiometer:

A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. By turning the shaft of the potentiometer, we change the amount of resistance on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative “closeness” of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Learn more about potentiometers here - http://fddrsn.net/pcomp/examples/potentiometers.html

The sketch below is an example from the Arduino IDE. EXAMPLES > SERVO > KNOB

In this sketch we use a 10K potentiometer to control the position of the servo. The analog input will return a value from 0 - 1023, and the servo needs a position of 0 -180. We can use the map() function to scale the value from 0 - 1023 to 0 - 180, and send this value to the servo.

The map function takes data like this: map(valueToMap, fromLow, fromHigh, toLow, toHigh)

#include Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin

void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { val = analogRead(potpin); // reads the value of the potentiometer val = map(val, 0, 1023, 0, 180); // map pot value to servo value myservo.write(val); // sets the servo position delay(15); // waits for the servo to get there } Using multiple servos with external power:

5V

Servos draw considerable power, so if you need to drive more than one or two, you’ll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). The above circuit digram examples how to connect multiple servos to external power.

You can use a 1 amp 5V DC power pack to drive about 5 servos or 10 servos with a 2 amp power pack. Whenever you connect external power remember you always need to connect the grounds of the Arduino and external power supply together!

Upload the sketch below to make the two servos rotate in opposite directions.

#include Servo myservo; // 1st servo Servo myservo2; // 2nd servo

void setup() { myservo.attach(9); // attach 1st servo myservo2.attach(8); // attach 2nd servo } void loop() { myservo.write(0); // 1st servo to position 0 myservo2.write(180); // 2nd servo to position 180 delay(500); myservo.write(180); // 1st servo to position 180 myservo2.write(0); // 2nd servo to position 0 delay(500); } buzzer + photoresistor

Photoresitor measures ambient light . The light changes the resistance like a potentiometer. This sketch will change the buzzer tone in response to the reading of the light.

int lightLevel; int piezo = 8; int duration = 300;

void setup() { pinMode(piezo, OUTPUT); } void loop() { lightLevel = analogRead(A0); tone(piezo, lightLevel, duration); delay(duration); } essential information Type Description Notes

Soft copy of the Program code that can be compiled in File format: Arduino Sketch Arduino IDE. .ino .pde (format used prior to IDE 1.0)

Arduino board type What is the board? Datasheet in PDF format are What version? often available online. What is the arduino-compatible type?

Libraries What libraries are used in the sketch? File format: .h

NB. You can check what librar- ies are used as they will be listed like this at the top of the sketch:

#include #include “library_name.h”

Libraries must be placed in the Arduino libraries folder under: Document > Arduino > Libraries > library_name_folder

Arduino IDE version Which version was the Arduino sketch eg. Arduino IDE 1.6.13 compiled and uploaded from? Changes in the IDE versions can result in a sketch being unable to complie.

Circuit schematics Diagrams or schematics for circuitry. Fritzing is an easy to use software to create visual schematics.

Details for any components used. Datasheet in PDF format are often available online.

EEPROM Does the sketch use eeprom? Eeprom is limited to 100000 If so how often does it write to writes. eeprom? Tutorial LINKS

• https://www.arduino.cc/en/Tutorial/HomePage • https://learn.adafruit.com/category/learn-arduino • https://learn.sparkfun.com/tutorials/tags/arduino • http://bildr.org/ • https://itp.nyu.edu/physcomp/ • https://www.robomart.com/blog/category/arduino/ • https://vimeo.com/channels/pcomp • http://fritzing.org/home/ • http://www.allaboutcircuits.com/ • http://wiki.seeed.cc/Sidekick_Basic_Kit_for_Arduino_V2/

Where to buy Arduino products

In Australia: • http://tronixlabs.com.au/ • http://littlebirdelectronics.com.au/ • http://www.freetronics.com.au/ • https://www.pakronics.com.au

Overseas: • https://www.adafruit.com/ • https://www.sparkfun.com/ • https://www.seeedstudio.com/

Where to buy electronic components

• http://au.element14.com/ • http://www.digikey.com.au/ • https://www.jaycar.com.au/