Sie sind auf Seite 1von 38

ECE SEMINAR

2016
DAY 1:

ARDUINO
MICROCONTROLLER
Polytechnic University of the Philippines, Santa Rosa | Aljhon Abila, 4 th Year BSECE

HISTORY:
Hernando Barragan created the development
platform Wiring at the Interaction Design
Institute Ivrea in Italy.
Massimo Banzi and Casey Reas known for
their work on Processing
GOAL: To create low cost, simple tools for nonengineers to create digital projects. The Wiring
platform consisted of a hardware PCB with an
ATmega128 microcontroller, an IDE based on
Processing and library functions to easily
program the microcontroller.
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

HISTORY:
2005 Banzi, Mellis, and Cuartielles added
support for the cheaper ATmega8
microcontroller to Wiring.
Then, started running a separate project called
ARDUINO.
Arduinos Initial core Team:
Massimo Banzi
David Cuartielles
Tom Igoe
Gianluca Martino
David Mellis
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

HISTORY:
The name ARDUINO comes from a bar in Ivrea,
where some of the founders of the project
used to meet. (Arduin of Ivrea)

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Hardware:
A microcontroller board based on
the ATmega328.
It has 14 digital input/output
pins, and 6 analog inputs.
Consists of a 16 MHz ceramic
resonator, a USB connection, a
power jack, an ICSP header, and a
reset button.
The board features serial
communications interfaces,
including USB on some models,
for loading
from
ARDUINO programs
Microcontroller Programming
| ECE Summer Workshop 2016

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

The microcontroller on the board is


programmed using the Arduino
programming language (based on
Wiring) and the Arduino
Development environment (based on
Processing).
The Arduino platform provides an
Integrated Development Environmen
t
(IDE) based on theProcessing
project, which includes support forC
, C++andJavaprogramming
languages.
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Arduino programs are written in


C or C++.
Users only need to define two
functions to make a runnable
cyclic executive program:
setup(): a function run once at
the start of a program that can
initialize settings.
loop(): a function called
repeatedly until the board
powers off.
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Documentation section consists of a set of


comment lines giving the name of the program,
author and other details.
Preprocessor Commands tells a C compiler to
include the library used before compilation
Definition Section defines all symbolic constants.
(A symbolic constant is a constant value given to a
name which cant be changed in program)
Global declaration section (variables used in
more than one function). This section also declares
all the user-defined functions.
Main Function where the program execution
begins.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ECE SUMMER
WORKSHOP
2016
ACTIVITY
LED|LCD|7Segment
Polytechnic University of the Philippines, Santa Rosa | Aljhon Abila, 4 th Year BSECE

1. LED Light Emitting Diode


- Blink: digitalWrite()
function
- Fade: analogWrite()
function
- LED with Pushbutton
2. LCD Liquid Crystal
Display
- Print: Hello World!
- Display and No Display
- Scroll
3. 7-Segment LED Display
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ECE SUMMER
WORKSHOP
2016
LED

Light Emitting
Diode

Polytechnic University of the Philippines, Santa Rosa | Aljhon Abila, 4 th Year BSECE

Blink: digitalWrite()
function
Turns on an LED on for one
second, then off for one second,
repeatedly.
Most Arduinos have an on-board
LED you can control. On the Uno
and Leonardo, it is attached to
digital pin 13.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

// the setup function runs once when you press reset or


power the board
void setup() {
pinMode(13, OUTPUT); // initialize digital pin 13 as an
output.
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is
the voltage level)
delay(1000);
// wait for a second
digitalWrite(13, LOW); // turn the LED off by making
the voltage LOW
delay(1000);
// wait for a second
}
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Diode)
Fade: analogWrite()
function
This example shows how to
fade an LED on pin 9 using the
analogWrite() function.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Sample CODE:
int led = 9;
int brightness = 0;
int fadeAmount = 5;

// the pin that the LED is attached to


// how bright the LED is
// how many points to fade the LED by

void setup() {
pinMode(led, OUTPUT);
}

// declare pin 9 to be an output:

void loop() {
analogWrite(led, brightness);
// set the brightness of pin 9:
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

LED (Light Emitting Diode)


LED with Pushbutton
Turns on and off a light emitting diode(LED) connected
to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Sample CODE:
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;
// the number of the pushbutton pin
const int ledPin = 13;
// the number of the LED pin
// variables will change:
int buttonState = 0;
// variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(buttonPin, INPUT);
// initialize the pushbutton pin as an input:
}
void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ECE SUMMER
WORKSHOP
2016
LCD

Liquid Crystal
Display

Polytechnic University of the Philippines, Santa Rosa | Aljhon Abila, 4 th Year BSECE

It is aflat-screendisplayinwhichanarrayofliquid
-crystalelementscanbeselectivelyactivatedtogenera
teanimage,an
electricfieldappliedtoeachelementalteringitsoptical
properties.
A flat-panel display that is
madeofanarrayofcellscontainingliquid
crystalsthataligntoblockortransmitlight
inresponsetoan electriccurrent.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

How it Works?
Nematic Phase Liquid Crystals.
- is the most commonly used in LCDs

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

How it Works?
1.Polarizing filter vertical
2.Glass substrate with Indium
Tin Oxide(ITO) electrodes.
3. Twisted nematic liquid
crystal.
4.Another substrate
5.Polarizing filter horizontal
6.Reflective Surface
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

D Pins and Functions

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

LiquidCrystal() setting up the pins in arduino


Syntax: LiquidCrystal lcd(rs, enable, d4, d5,
d6, d7)
Begin() initialize the size of the LCD
Syntax: lcd.begin(cols,rows)
Clear() clear the screen
Syntax: lcd.clear()
setCursor() position the LCD cursor
Syntax: lcd.setCursor(col,row)
print() display the text in the LCD
Syntax: lcd.print(TypeYourTextHere)
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Simulation (Proteus):

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
Potentiometer:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

LCD (Liquid Crystal


Display)
Print: Hello World!
Demonstrates the use of 16x2
LCD display.
This sketch prints "Hello
World!" to the LCD and shows the
time.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

#include <LiquidCrystal.h>
// include the library code:
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and
rows:
lcd.print("hello, world!"); // Print a message to the LCD.
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print(millis() / 1000); // print the number of seconds since
reset:
}
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

LCD (Liquid Crystal Display)


Display and No Display
This sketch prints "Hello World!" to the LCD
and uses the display() and noDisplay()
functions to turn on and off the display.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

LCD (Liquid Crystal Display)


Scroll
This sketch prints "Hello World!" to the LCD
and uses the
scrollDisplayLeft() and scrollDisplayRight()
methods to scroll
the text.

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ECE SUMMER
WORKSHOP
2016
7-Segment LED
Display

Polytechnic University of the Philippines, Santa Rosa | Aljhon Abila, 4 th Year BSECE

7-Segment LED
Display
A common type of display device using
LEDs is the seven-segment display.
By forward-biasing selected
combinations of segments, any decimal
digit and a decimal point can be
formed.
Two type of led circuit arrangements
are the common anode and common
cathode
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

PINS

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Sample CODE:
First, initialize all variables.
Declare the pins to be used.

int
int
int
int
int
int
int

l0=2;
l1=3;
l2=4;
l3=5;
l4=6;
l5=7;
l6=8;

Then, declare whether it is an


input, or an output in the void setup.

void setup()
{
pinMode(l0,OUTPUT);
pinMode(l1,OUTPUT);
pinMode(l2,OUTPUT);
pinMode(l3,OUTPUT);
pinMode(l4,OUTPUT);
pinMode(l5,OUTPUT);
pinMode(l6,OUTPUT);
}

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

In the void loop, set the necessary pins to high to make a digit-0. Give it a second, then reset
the pins to make a digit-1. Do this for the rest of the digits (from 0-9).

void zero()
{
//make a digit-0.
digitalWrite(l0,HIGH)
;
digitalWrite(l1,HIGH)
;
digitalWrite(l2,HIGH)
;
digitalWrite(l3,HIGH)
;
digitalWrite(l4,HIGH)

void nine()
{
//make a digit-9.
digitalWrite(l0,HIGH)
;
digitalWrite(l1,HIGH)
;
digitalWrite(l2,HIGH)
;
digitalWrite(l3,HIGH)
;
digitalWrite(l4,LOW);

ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

END
ARDUINO Microcontroller Programming | ECE Summer Workshop 2016

Das könnte Ihnen auch gefallen