INTRODUCTION TO ARDUINO
• Arduino is an open-source hardware and software
company, project, and user community that designs
and manufactures single-board microcontrollers and
microcontroller kits for building digital devices
• Arduino board designs use a variety of
microprocessors and controllers.
• The boards are equipped with sets of digital and
analog input/output (I/O) pins that may be
interfaced to various expansion boards ('shields') or
breadboards (for prototyping) and other circuits.
• The boards feature serial communications interfaces,
including Universal Serial Bus (USB) on some models,
which are also used for loading programs.
• The microcontrollers can be programmed using the C and
C++ programming languages, using a standard API which is
also known as the Arduino Programming Language,
inspired by the Processing language and used with a
modified version of the Processing IDE.
• In addition to using traditional compiler toolchains, the
Arduino project provides an integrated development
environment (IDE) and a command line tool developed in
Go.
Digital Pins /Connectors
Analog Pins
• www.Arduino.cc
• Software
• Download and install
• Launch
• Plug in your Arduino Board
• www.tinkercad.com
• Login with code your Teacher shared
• Enter your nickname
• Go to your classroom
• Select circuits
Deconstructing Arduino Code
// C++ code comment
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
Functions
• We will now take a step back, and look at the first line of code.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
We see that the
pinMode statement is included in a structure like this:
void setup() {
..........
}
These structures are called functions. In an Arduino sketch, there
are the two basic sections: the setup() function and the loop()
function.
• Whatever is inside setup() executes once
in the beginning of the program
execution,
• followed by loop() which repeats over
and over.
Deconstructing Blink Statements
Void setup()
• The void setup() is the first function to be executed and it is
executed only once.
• It usually contains statements that set the pin modes on the
Arduino to OUTPUT or INPUT, for example:
pinMode (12, OUTPUT);
pinMode(11, INPUT);
Or to start the serial monitor example: serial.
pinMode(LED_BUILTIN, OUTPUT);
• You may be wondering now why we had to do this in the
first place, since we have mentioned that LEDs are
outputs.
• This is because the build-in LED is connected to a specific
digital input/output port, pin 13. When using any digital
pin in a program, we need to declare it as input or output.
loop()
• First, let's take a look at what statements are inside the
loop():
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
This is essentially the part of the program that describes blinking. We see that
blinking is actually turning a LED on, waiting for a while, turning it off, waiting for
a while again and then repeating from the top.
Let's take the statements one by one:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is
the voltage level)
In an Arduino sketch, write means to set a value.
digitalWrite() will set a value of HIGH or LOW.
For the digital output pins of the Arduino, HIGH and LOW
means turning them ON and OFF.
Notice that the way we use digitalWrite() looks similar to
pinMode() that we saw earlier.
• delay(1000); // wait for a second
• The delay() will pause the program, preventing the
Arduino from executing the next command.
• The number in the parentheses is the amount of
time it will wait in milliseconds.
• 1000 msec = 1 sec
• The next statement is very similar to the first
digitalWrite() in the program, however this time it
sets the pin to LOW, turning the LED OFF.