Arduino: Introduction To Bme
Arduino: Introduction To Bme
Lab IV
Arduino
2020-2021 Fall
24.12.2020
1 Goals:
This lab will introduce the Arduino microcontroller. In particular the following will be
covered in this lab:
Introduction to the Arduino board (hardware) and the Arduino integrated
development environment (IDE).
Basic coding in Arduino C/C++.
Activating the ports to turn LED IN OR OFF
2 Background:
The Arduino is an open-source electronics platform that consists of simple but versatile
hardware that can be coded relatively easily. Many sensors actuators and shields exist for
this platform and by using Arduino different types of projects can be easily made.
There are different types Arduino boards available, but in this experiment the simplest
Arduino will be used, which is the Arduino Uno. It consists of an 8-bit Atmel
microcontroller running at 16 MHz with 32 kB of memory for storage. The Arduino Uno
pinout consists of 14 digital pins, 6 analog inputs and it runs on 5V that can be supplied
using pc or battery.
Unlike most previous programmable circuit boards, the Arduino does not need a separate
piece of hardware (called a programmer) in order to load new code onto the board -- you
can simply use a USB cable. Furthermore, the Arduino IDE uses a simplified version of
C++ Programming language, which makes it easier to learn to program.
Finally, Arduino provides a standard form factor that breaks out the functions of the
micro-controller into a more accessible package.
Component Explanations
• Analog input pins – pins (A0-A5) that take-in analog values to be converted to be
represented with a number range 0-1023 through an Analog to Digital Converter
(ADC).
• ATmega328 chip – 8-bit microcontroller that processes the sketch you
programmed.
• Built-in LED – in order to gain access or control of this pin, you have to change the
configuration of pin 13 where it is connected to.
• Crystal Oscillator – clock that has a frequency of 16MHz
• DC Jack – where the power source (AC-to-DC adapter or battery) should be
connected. It is limited to input values between 6-20V but recommended to be
around 7-12V.
• Digital I/O pins – input and output pins (0-13) of which 6 of them (3, 5, 6, 9, 10 and
11) also provide PWM (Pulse Width Modulated) output by using the analogWrite()
function. Pins (0 (RX) and 1 (TX)) are also used to transmit and receive serial data.
• ICSP Header – pins for “In-Circuit Serial Programming” which is another method of
programming.
• ON indicator – LED that lights up when the board is connected to a power source.
• Power Pins – pins that can be used to supply a circuit with values VIN (voltage from
DC Jack), 3.3V and 5V.
• Reset Button – a button that is pressed whenever you need to restart the sketch
programmed in the board.
• USB port – allows the user to connect with a USB cable the board to a PC to
upload sketches or provide a voltage supply to the board. This is also used for serial
communication through the serial monitor from the Arduino software.
2.2 The Arduino Software (IDE):
The Arduino integrated development environment is a cross-platform application that is
written in the programming language Java. It is used to write and upload programs to
Arduino compatible boards.
To install the Arduino IDE use the following link :
(https://www.arduino.cc/en/Main/Software)
Structure
1) The setup() function 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.
2) 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.
Data Types
1) The void keyword is used only in function declarations. It indicates that the function
is expected to return no information to the function from which it was called.
2) Integers, shown by int are the most commonly used data types and they store
integers (as their name suggests).
Syntax
1) Semicolon (;) is used to end statements and must be used to end all statements.
2) Single line comments can be shown using double forward slashes (//) whereas
multiline comments begin with /* and end with */
Variables
Variables are used to store data. Since C++ is strongly typed, be very careful about what
kind of data types you use to store your data (variable). This will also affect the result of the
operations applied to the variable.
To declare a variable without assigning it a value, the syntax is:
data_type variable_name;
Example: int counter;
To instantiate a variable (declare and give a value), the syntax is:
data_type variable_name = value;
Example: int counter = 0;
Constants
There are some important constant that you should be familiar with:
Constant Description
true Boolean true. Also any number other than 0 may be interpreted as true.
false Boolean false. 0 is interpreted as false.
INPUT When an I/O (input/output) pin is set to INPUT, then Arduino reads values from it.
It gets the voltage that is currently at that pin.
OUTPUT When an I/O pin is set to OUTPUT, then Arduino writes values to it. It applies a
voltage to that pin.
HIGH HIGH shows that the value being read by an I/O pin is greater than 3.0 V (for Uno)
or that the voltage applied by a pin is 5.0 V (when pin is set to OUTPUT).
LOW LOW shows that the value being read by an I/O pin is less than 3.0 V (for Uno) or
that the voltage applied by a pin is 0.0 V (when pin is set to OUTPUT).
Proteus is a simulation and electronic design development tool developed by Lab Center
Electronics. It is a very useful tool as it ensures that the circuit design or firmware code is
working properly before you begin to physically work on it.
It has an extensive number of components in its library which can be used to virtually
design your circuit. The designs you make can be easily compiled and debugged through
Proteus’s virtual meters (voltmeter and ammeter), oscilloscope, serial monitor, and more.
We will use Proteus for Arduino project simulation because of its extensive collection of
libraries.
Figure 2.4 : Proteus software enviornment
Note: At step 02 in figure 2.4 we will use the same address which we highlighted in red color at
black screen in figure 2.3.
5 . Procedure and Analysis :
Q3) What is the maximum value that can be stored in the long data type? (1 point). What
is the difference between long and int data types (explain in your own words)?