0% found this document useful (0 votes)
39 views

01 - Laboratory - Exercise - 1 (15) Arduino-1

Abcd

Uploaded by

taarakmehtuspubg
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)
39 views

01 - Laboratory - Exercise - 1 (15) Arduino-1

Abcd

Uploaded by

taarakmehtuspubg
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/ 7

01 Laboratory Exercise 1

Arduino Basics
Objectives:

At the end of the exercise, the students should be able to:

▪ Perform programming, code-compiling, and interfacing of MCUs via Arduino IDE.


▪ Examine the programming and hardware side of Arduino.

Materials: Precaution:
▪ Breadboard
▪ Dupont wires (male-to-male)
▪ Power supply (preferably 3.3v to 5v)
▪ 6 pcs. 110Ω resistors, ¼ watt (add for spare)
▪ 6 pcs. Assorted LEDs (add for spare)
▪ Arduino UNO or any variant clone
▪ Digital Multimeter (for testing purposes of wires, LEDs and resistors)
▪ Computer with Installed Arduino IDE (Latest)

Basic Principles:
Arduino is a prototype platform (open-source) based on easy-to-use hardware and software. It consists of a
circuit board, which can be programed (referred to as a microcontroller), and a ready-made software called
Arduino IDE (Integrated Development Environment), which is used to write and upload the computer code to
the physical board.
Features:
• Arduino boards are able to read
analog or digital input signals from
different sensors and turn it into an
output such as activating a motor,
turning LED on/off, connecting to
the cloud, and many other actions.
• You can control your board
functions by sending a set of
instructions to the microcontroller
via Arduino IDE (referred to as
uploading software).
• Arduino IDE uses a simplified
version of C++, making it easier to
learn to program.
• Arduino provides a standard form
factor that breaks the functions of
the microcontroller into a more
accessible package.

To install and initialize Arduino IDE:

1. Download and Install Arduino IDE from https://www.arduino.cc/.


2. Run the Arduino IDE and plug Arduino UNO into the USB port.
3. Select the board and COM port from the dropdown.
• Go to Tools. Hover to Board and click Arduino/Genuino Uno from the selection.
• Again, go to Tools, then hover to Port and click the active port where Arduino/Genuino UNO
is located. (Usually, the default device is under COM3 port).
To compile code and upload instructions into the device:

1. Perform the following:

• Click the check button. • Go to Sketch and click • Alternatively, you can
Verify/Compile to check for use the keyboard
errors. shortcut, Ctrl + R.

2. If no errors are encountered, perform the following:

• Click the arrow button. • Go to Sketch, then click • Alternatively, you can
Upload to check for errors. use the keyboard
shortcut, Ctrl + U.

3. Press the board’s reset button near the USB port.

Hardware Part:

• Power USB - Arduino board can be


powered by using the USB cable from your
computer. All you need to do is connect the USB
cable to the USB connection
• Power (Barrel Jack) - Arduino boards can
be powered directly from the AC mains power
supply by connecting it to the Barrel Jack.
• Voltage Regulator - The function of the
voltage regulator is to control the voltage given to
the Arduino board and stabilize the DC voltages
used by the processor and other elements.
• Crystal Oscillator - The crystal oscillator
helps Arduino in dealing with time issues. It tells us
that the frequency is 16 MHz.
• Arduino Reset - You can reset your Arduino
board, i.e., start your program from the beginning.
• Pins (3.3, 5, GND, Vin) - Most of the components used with Arduino board works fine with 3.3 volts and
5 volts.
o GND (Ground): There are several GND pins on the Arduino, any of which can be used to ground
your circuit.
o Vin: This pin also can be used to power the Arduino board from an external power source, like AC
mains power supply.
• Analog pins - The Arduino UNO board has five analog input pins A0 through A5. These pins can read
the signal from an analog sensor like the humidity sensor or temperature sensor and convert it into a
digital value that can be read by the microprocessor.
• Main microcontroller - Each Arduino board has its own microcontroller. You can assume it as the brain
of your board. The main IC (integrated circuit) on the Arduino is slightly different from board to board.
• ICSP pin – It is an AVR, a tiny programming header for the Arduino consisting of MOSI, MISO, SCK,
RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral Interface), which could be
considered as an "expansion" of the output. Actually, you are slaving the output device to the master of
the SPI bus.
• Power LED indicator - This LED should light up when you plug your Arduino into a power source to
indicate that your board is powered up correctly. If this light does not turn on, then there is something
wrong with the connection.
• TX and RX LEDs - On your board, you will find two labels: TX (transmit) and RX (receive). They appear
in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins responsible
for serial communication. Second, the TX and RX led (13). The TX led flashes with different speed while
sending the serial data. The speed of flashing depends on the baud rate used by the board. RX flashes
during the receiving process.
• Digital I / O - The Arduino UNO board has 14 digital I/O pins (of which 6 provide PWM (Pulse Width
Modulation) output. These pins can be configured to work as digital input pins to read logic 14 values (0
or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The pins labeled “~” can be
used to generate PWM.
• AREF stands for Analog Reference. It is sometimes used to set an external reference voltage (between
0 and 5 Volts) as the upper limit for the analog input pins.

Programming Part:

Every Arduino sketch has two (2) main parts to the program:
• void setup()– called when the program starts. It is used to initializes variables and pin modes.
void setup() //The setup begins here
//A program part begins here
pinMode(13, OUTPUT); //Pin 13 is supposed to be an output.
//A program part is ending here.
• The setup function itself calls two built-in functions, pinMode and digitalWrite.
o The function digitalWrite needs to know which pin to set and whether to set that pin HIGH or
LOW.
o The function pinMode sets a particular pin to be either an input or an output.

void setup() //The setup begins here

pinMode(13, OUTPUT); //Pin 13 is supposed to be an output.


digitalWrite(13, HIGH); //Set Pin 13 to light-up.
pinMode(14, INPUT); //Pin 14 is supposed to be an output.
digitalWrite(14, LOW); //Set Pin 14 to not light-up.
• void loop() – Contains the instructions that get repeated over and over until the board is turned off.
It is were the main program resides.

void loop() //The main part of the program begins here


//program part begins here
digitalWrite(13, HIGH); //Turn on the voltage on pin 13 (LED on)
delay(1000); //Wait for 1000 milliseconds (one second)
digitalWrite(13, LOW); //Turn off the voltage on pin 13 (LED off)
delay(1000); //Wait for 1000 milliseconds (one second)
//Program ends here

These are the other componenta that can be of use in writing a program:
• Serial Monitor - It shows data or values from your program and it can be used to debug Arduino
programs. It needs to have the Arduino device connected to your PC in order to use it.

• Variables - It shows data or values from your program and it can be used to debug Arduino programs.
It needs to have the Arduino device connected to your PC in order to use it.

Basic Data Types Description


int Integers are the primary data-type for number storage. int stores a 16-bit (2-byte)
value.
double Double precision floating-point number occupies four bytes. That is, the double
implementation is exactly the same as the float, with no gain in precision.
float A floating-point number is a number that has a decimal point. Floating-point numbers
are often used to approximate the analog and continuous values because they have
greater resolution than integers.
char A data type that takes up one byte of memory that stores a character value. Character
literals are written in single quotes like this: 'A' and for multiple characters, strings use
double quotes: "ABC".
bool A Boolean holds one of two values, true or false. Each Boolean variable occupies one
byte of memory.
byte A byte stores an 8-bit unsigned number, from 0 to 255.
long Long variables are extended size variables for number storage, and store 32 bits (4
bytes), from -2,147,483,648 to 2,147,483,647.
Procedure: Activity #1
1. Configure the circuit with based on this diagram.
Connections:

• LED1 to PIN 13
• LED2 to PIN 12
• LED3 to PIN 11
• LED4 to PIN 10
• LED5 to PIN 9
• LED6 to PIN 8

• Ground to GND Pin

• All 110 Ohm resistors to cathode part of LEDs

• USB connection to Arduino USB Type A port.

2. Type in the following code.

// global declarations here delay(25);


int led1 = 13; digitalWrite(led3, LOW);
int led2 = 12; delay(25);
int led3 = 11; digitalWrite(led5, HIGH);
int led4 = 10; delay(25);
int led5 = 9; digitalWrite(led4, LOW);
int led6 = 8; delay(25);
digitalWrite(led6, HIGH);
// initialize digital pins as outputs. delay(25);
void setup() { digitalWrite(led5, LOW);
pinMode(led1, OUTPUT); delay(25);
pinMode(led2, OUTPUT); digitalWrite(led6, HIGH);
pinMode(led3, OUTPUT); delay(25);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT); //second part
pinMode(led6, OUTPUT); digitalWrite(led5, HIGH);
} delay(100);
digitalWrite(led6, LOW);
// the loop routine runs forever. delay(100);
void loop() { digitalWrite(led4, HIGH);
//first part delay(100);
digitalWrite(led1, HIGH); digitalWrite(led5, LOW);
delay(25); delay(100);
digitalWrite(led6, LOW); digitalWrite(led3, HIGH);
delay(25); delay(100);
digitalWrite(led2, HIGH); digitalWrite(led4, LOW);
delay(25); delay(100);
digitalWrite(led1, LOW); digitalWrite(led2, HIGH);
delay(25); delay(100);
digitalWrite(led3, HIGH); digitalWrite(led3, LOW);
delay(25); delay(100);
digitalWrite(led2, LOW); digitalWrite(led2, LOW);
delay(25); delay(100);
digitalWrite(led4, HIGH); }
3. Compile and upload. Reset the Arduino device and see results.
4. Show the output to your instructor.

Procedure: Activity #2

1. Connect the Arduino device to the USB port of the computer.


2. Type in the following code below. Afterward, click the Serial Monitor button
in the upper right of the Arduino IDE window.

int myValue = 0; // declarations

void setup()

Serial.begin(9600); // passes the value 9600 to the speed parameter.


// This tells the Arduino to get ready to exchange
// messages with the Serial Monitor at a data rate
// of 9600 bits per sec.

void loop()

myValue = random(100); // random number generator between 0-100


Serial.print("The Value is "); // display text
Serial.println(myValue); // displays the RNG value
delay(1000); // Wait for 1000 milliseconds (one second)

3. Compile and upload to see results.


4. Show the output to your instructor.

Conclusion:

Guide questions:
1. What do you think are the important commands used in this activity? Why did you say so?
2. What have you observed in the two (2) activities?

GRADING RUBRIC:

Activities 1 and 2 (2 items x 20 points)


Criteria/Scoring Indicator Score
Hardware Part Organized and clean implementation of components and wires 10
Programming Part No errors found in the code. 10
Total 20

Conclusion (10 points)


Criteria/Scoring Indicator Score
Content Provided supporting details and factual scenarios 5
Organization of Ideas Expressed clear points and arranged ideas 5
Total 10

You might also like