THE IOT ACADEMY
Compile Upload to controller
Text Output (Serial Data)
Code Editor
Serial
Monitor
Arduino
IDE
Window
Arduino IDE
Try It: Connect the USB Cable
Arduino IDE
See:
http://arduino.cc/en/Guide/Environment
for more information
Select Serial Port and Board
Status Messages
Add an External LED to pin 13
• File > Examples > Digital > Blink
• LED’s have polarity
– Negative indicated by flat side of the housing
and a short leg
www.instructables.com
A Little Bit About Programming
• Code is case sensitive
• Statements are commands
and must end with a semi-
colon
• Comments follow a // or
begin with /* and end with
*/
• loop and setup
Our First Program
Terminology
Getting up and running
 The power mode must be selected before you plug the board into
anything.
 When powering from the USB cable (5 volts) the jumper should be
closest to the USB input, for DC supplythe jumper should be closest to
the DC input.
Getting up and running
 Plug it into the USB port and install the USB drivers that come with the
IDE.
 Open up the Arduino IDE and select the COM port, usually COM1 or
COM2 on a Windows machine.
 Within the IDE, select the BAUD rate (communication speed for serial
connections)
 Set BAUD rate to 9600 on Windows, (?) for Mac?
Basic Process
Design the circuit:
 What are electrical requirements of the sensors or actuators?
 Identify inputs (analog inputs)
 Identify digital outputs
Write the code
 Build incrementally
 Get the simplest piece to work first
 Add complexity and test at each stage
 Save and Backup frequently
 Use variables, not constants
 Comment liberally
Writing and Downloading Code
Running Code While Tethered
Running Code Stand-Alone
Arduino IDE
IDE =
Integrated
Development
Environment
http://www.arduino.cc/en/Guide/Environment
Demonstration
Start up the Arduino software
and open up the Blink sketch.
For the most basic kind of program you’ll need a simple actuator, an
LED with the long leg (+) pushed into pin 13 and the short leg (-) in the
adjacent ground pin (GND). Pin 13 is special, in the sense that it has a
built in resistor to correctly control the voltage going into a testing LED
just like this.
Example 1
Code Structure: Header
Header provides information
Example 1
Code Structure: setup function
setup function is executed
only once at the start
Example 1
Code Structure: loop function
loop function is
repeated indefinitely
Example 1
Code
Digital I/O Functions:
pinMode
digitalWrite
digitalRead
pinMode(13, Output)
prepare pin 13 for
outputs of voltage
Example 1
Code
digitalWrite(13, HIGH)
Sets pin 13 to a voltage
that
means “on”
Digital I/O Functions:
pinMode
digitalWrite
digitalRead
Example 1
Code
Digital I/O Functions:
pinMode
digitalWrite
digitalRead
delay(1000);
Tells microcontroller to
do nothing for 1000 ms =
1 s
Example 1
Code
digitalWrite(13, LOW)
Sets pin 13 to voltage
that means “off”
Digital I/O Functions:
pinMode
digitalWrite
digitalRead
Example 1
The connections
Example 1
Upload a program
 At this stage we just programmed the LED to blink on and off at a set time
interval.
 Press the reset button on the board and then click ‘Upload to I/O board’ in the
IDE. If all goes well lights should flicker on the board and the IDE will confirm
success.
The IoT Academy IoT training Arduino Part 2 Arduino IDE

The IoT Academy IoT training Arduino Part 2 Arduino IDE