0% found this document useful (0 votes)
76 views11 pages

Arduino: Introduction To Bme

The document provides an introduction to using the Arduino microcontroller. It discusses the Arduino board hardware, the Arduino IDE software for coding, and basic C/C++ coding concepts for Arduino. It also describes two example tasks - making an LED blink using a single pin, and turning an LED on/off using a push button. The goals are to familiarize the user with the Arduino environment and basic coding to control inputs and outputs.

Uploaded by

Youssef Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views11 pages

Arduino: Introduction To Bme

The document provides an introduction to using the Arduino microcontroller. It discusses the Arduino board hardware, the Arduino IDE software for coding, and basic C/C++ coding concepts for Arduino. It also describes two example tasks - making an LED blink using a single pin, and turning an LED on/off using a push button. The goals are to familiarize the user with the Arduino environment and basic coding to control inputs and outputs.

Uploaded by

Youssef Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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.

Figure 2.1 : Arduino UNO Pinout

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)

Figure 2.2 : The Arduino IDE

Figure 2.3 : Arduino IDE compilation mode


2.3 Basics of Arduino Coding (C/C++)
Arduino microcontrollers are programed using C++ language.

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).

Useful Built-in Functions


The following functions will come in handy:
Function syntax Description
pinMode(pin, Configures the specified pin to behave either as an input or
mode) an output.
delay(ms) Pauses the program for the amount of time (in milliseconds)
specified as parameter.
Serial.begin(speed) Sets the data rate in bits per second (baud) for serial data
transmission. This needs to be in the setup() section. It sets
the Arduino to communicate with the PC using the USB
cable.
Serial.println(val) Prints the value on the Serial Monitor. It adds a newline at the
end.

4.Equipment Needed for the Lab:

- Proteus For Simulating Arduino Projects

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

Figure 2.4 : Configuring Arduino UNO

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 :

5.1 Blinking LED :


1. Open Arduino IDE
2. Write the following code

Figure 2.5: Code for Task1

3. Build the code and copy the path of HEX file.


4. Open Proteus simulator software.
5. Place the arduino and configure its properties as shown in figure 2.4.
6. Build up the following Circuit using resistors and Led’s:
(Using pin 0,1,2,3,4 and GND )
7. Run the proteus software.
Figure 2.6 : Proteus simulation of Task1

5.2 Turning led on/off using BUSH BUTTON:


1. Open Arduino IDE
2. Write the code shown in figure 2.7.
3. Build the code and copy the path of HEX file.
4. Open proteus simulator software.
5. Place the Arduino and configure its properties as shown in figure 2.8
6. Build up the following circuit using resistor, button and Led.
(Using pin 3, 4 and ground)
7. Run the proteus software.
Figure 2.7 : Code for Task2

Figure 2.8 : Proteus simulation of Task2

Figure 5.2 : Second project


6 .Questions for Post-Lab Report

Use your own words, the answers should not be long.

Q1) What are the advantages and disadvantages of using Arduino ?

Q2) what are the differences between microprocessor and microcontroller ?

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)?

You might also like