Sei sulla pagina 1di 33

For updated version, please click on

http://ocw.ump.edu.my

BEE1223 Computer Programming


& Applications

Chapter 10 & 11: PC Interfacing


Using ARDUINO (UNO)
by
Marlina Yakno
Faculty of Electrical and Electronics Engineering
marlinayakno@ump.edu.my

ARDUINO by
Marlina Yakno
Expected Outcome

Student should be able to:


Develop hardware interface software to solve simple
engineering problem.

ARDUINO by
Marlina Yakno
Chapter Outline

Item Sub-topic
10.1 Data Acquisition Card Type and Function
10.2 Terminal Port Testing
11.1 Hardware Connection with Interface Card
11.2 Port Selection and Configuration
11.3 Digital Input & Output
11.4 Analog Input & Output

ARDUINO by
Marlina Yakno
Arduino Uno

ARDUINO by
Marlina Yakno
Introduction to Arduino Uno

Arduinos contain an ATmega microcontroller a


complete computer with CPU, RAM, Flash memory,
and input/output pins, all on a single chip.

Its designed to attach all kinds of sensors, LEDs,


small motors and speakers, servos, etc. directly to
these pins, which can read in or output digital or
analog voltages between 0 and 5 volts.

ARDUINO by
Marlina Yakno
Introduction to Arduino Uno

The Arduino connects to your computer via USB,


where you program it in a simple language (C/C++,
similar to Java) inside the free.

Arduino IDE by uploading your compiled code to the


board.

More info at: https://id.arduino.cc/

ARDUINO by
Marlina Yakno
Training Kit:
1. LED 6 unit :
connected to Digital
pin 5-10
2. Resistor 220 ohm - 6
unit
3. Resistors 10K ohm
2 unit
4. Push button switch -
2 unit connected to
Digital pin 11 & 12
5. LM35 sensor - 1 unit
connected to A0
6. Potentiometer 1
unit connected to A1
ARDUINO by
Marlina Yakno
Download & Install Arduino IDE

ARDUINO by
Marlina Yakno
Open Arduino IDE

ARDUINO by
Marlina Yakno
Selecting the board

ARDUINO by
Marlina Yakno
Check computer port

ARDUINO by
Marlina Yakno
Select the right port

Message appear indicates


your COM port is correct. It
consists of storage space

ARDUINO by
Marlina Yakno
The Arduino
IDE

Write your program here!

Display communication
message between PC and
Arduino and list any errors
if your sketch doesn't
compile properly

ARDUINO by
Marlina Yakno
Setup() & loop() Functions

setup()

The first function executed when a sketch starts.


Use it to initialize variables, pin modes, start using libraries, etc.
The setup function will only run once, after each power up or
reset of the Arduino board.

loop()

Second function executed after setup()


Loops consecutively, allowing your program to change and
respond.
Use it to actively control the Arduino board.
ARDUINO by
Similar to main() in C Marlina Yakno
Built-in-Examples

File->Examples
ARDUINO by
Marlina Yakno
Loading Program to Arduino Board

STEP 1: COMPILING - This is the process of converting the


code that have just written in Arduino IDE to another form
which is only understood by the micro controller in Arduino
board.

In the Arduino IDE, compiling is called as verify (see the


button with tick mark just below menu bar).

When hit the verify button, the program have written in


Arduino IDE will be compiled for any errors and then
converted to another form that Avr Atmega328 understands.
ARDUINO by
Marlina Yakno
ARDUINO by
Marlina Yakno
Loading Program to Arduino Board

STEP 2: BURNING -refer to uploading a program to any micro


controller. At this step, the verified program in Arduino IDE is
upload to the Arduino board.

Press the upload button (see the button with right arrow
mark). It will begin the process of burning the compiled
program to Avr micro controller on Arduino board.

If the program has been uploaded successfully, it will display a


message Done Uploading. If the uploading process was not
successful, it will display an error message accordingly.
ARDUINO by
Marlina Yakno
ARDUINO by
Marlina Yakno
ACTIVITY 1: LED BLINKING

Objective:
Turns an LED on for one second,
then off for one second,
repeatedly.

Parts Required:
- Arduino board
- 6 LEDs (connected to Digital
pin 5-10
- 220 resistors

ARDUINO by
Marlina Yakno
ACTIVITY 1: LED BLINKING

Use this function to set up a


digital pin 5-10 to be input
or output

ARDUINO by
Marlina Yakno
pinMode()
Description: Configures the specified pin to behave
either as an input or an output.

Syntax: Pinmode(pin, mode)

Pin: the number of the pin whose mode you wish to


set

Mode: INPUT, OUTPUT, or INPUT_PULLUP.


ARDUINO by
Marlina Yakno
digitalWrite()
Description: Set a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(),


its voltage will be set to the corresponding value: (5V or 3.3V =
HIGH), (0V or ground = LOW).

If the pin is configured as an INPUT, digitalWrite()will


enable (HIGH) or disable (LOW) the internal pullup on the input pin.

Syntax: digitalWrite(pin, value)

Parameters: pin: the pin number


value: HIGH or LOW
ARDUINO by
Marlina Yakno
delay()
Description: Pauses the program for the amount of
time (in miliseconds) specified as parameter. (There
are 1000 milliseconds in a second.)

Syntax: delay(ms)

Parameters: ms: the number of milliseconds to


pause

ARDUINO by
Marlina Yakno
ACTIVITY 2: CHANGE BLINKING
PATTERN
a. Modify the blinking coding
so that now it turn ON for 3
seconds and turn OFF 1
second.

b. Modify the blinking coding,


so that it blinks rapidly (1/2
second).

ARDUINO by
Marlina Yakno
ACTIVITY 3: ADD MORE LEDs

Assign another 2 digital pins as


an output.
Let the newly added LEDs to
blink with second delay.

ARDUINO by
Marlina Yakno
ACTIVITY 4: PUSHBUTTON-
CONTROLLED LED

Objective:
Turns on and off LED when
pressing a pushbutton.

Parts Required:
- Arduino board
- LED (connected to Digital pin
5-10
- 220, 10k resistors
- Push button switch
(connected to Digital pin 11-
12)
ARDUINO by
Marlina Yakno
ACTIVITY 4: PUSHBUTTON-
CONTROLLED LED

ARDUINO by
Marlina Yakno
ACTIVITY 5: PUSHBUTTONS-
CONTROLLED LEDs
Use button 1 to control LED
1 and button 2 to control
LED 2

When buttons are pressed,


turn on the LEDs

ARDUINO by
Marlina Yakno
Analog Input

Analog sensors can be connected to Arduino through pin


A0..A5
For our training kit:
LM35 sensor - 1 connected to A0
Potentiometer 1 connected to A1

analogRead()
Reads the value from the specified analog pin.
Syntax: analogRead(pin)
Parameters:
pin: the number of the analog input pin to read from (0 to 5 on most
boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)
Returns an integer ranging from 0 to 1023
ARDUINO by
Marlina Yakno
ACTIVITY 6: LIGHT DIMMER

Objective:
The brightness of the LED is
controlled by the potentiometer.

Parts Required:
- Arduino board
- LED (connected to Digital pin
5-10
- 220, 10k resistors
- Potentiometer(connected to
Analog pin 1)

ARDUINO by
Marlina Yakno
ACTIVITY 6: LIGHT DIMMER

ARDUINO by
Marlina Yakno
ACTIVITY 7: BAR GRAPH

Use potentiometer to
control all LEDs at Arduino
board.

ARDUINO by
Marlina Yakno

Potrebbero piacerti anche