Sie sind auf Seite 1von 31

Introduction to Arduino

Jiang Jiang
TVETI at A.A. 2019
Why Was Arduino Developed?
• Physical Computing – using components that can interact with people
and with the world around us
• The Arduino was originally developed for artists and designers to
prototype interactive displays
• Developed for non-scientists
• Minimalist programming
• “Forgiving” circuitry that can handle a wide variety of wiring errors
Different Varieties of Arduino
Arduino Uno Digital Input / Digital output
Revision 3 (PWM on pins 3, 5, 6, 9, 10, 11)

USB
connection

7-12 volt ATmega328P


input power
(9v is
common) Power Analog input /
pins Digital input or
output
Getting Started with Arduino
• 1. Connect the board
Connect the Arduino board to your computer using the USB cable. The
green power LED (labelled PWR) should go on.
Getting Started with Arduino
• 2. Download and install the Arduino application
Go to https://www.arduino.cc/en/Main/Software and download Arduino
IDE
Getting Started with Arduino
• 3. Launch the Arduino application
• 4. Open the blink example

File > Examples >01.Basics >


Blink.
• 5. Select your board
You'll need to select the entry in the Tools > Board menu that corresponds to
your Arduino.
• 6. Select your serial port
Select the serial device of the Arduino board from the Tools | Serial Port menu.
• 7. Upload the program
Click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the
board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar.
Arduino Reference
You can find reference in the
Help > Reference menu
Sketch Structure
• setup() function is called when a sketch
starts. Use it to initialize variables, pin modes,
start using libraries, etc.
• setup() function will only run once, after each
powerup or reset of the Arduino board.

After creating a setup() function, which initializes and sets the initial values,
the loop() function loops consecutively, allowing your program to change and
respond. Use it to actively control the Arduino board.
Ex 1 Bi_color_LED
• A bi-color LED is capable of emitting two different
colors of light, typically red and green.
• It has 3 leads; common cathode and two LED terminals,
or pins.
• Positive voltage can be directed towards one of the
LED terminals, causing that terminal to emit light of the
corresponding color.

Principle
Control the LED brightness by the digital port. The
color of the LED changes from red to green as well
as flashes a mixed color.
Build circuit

Bi color LED UNO

GND GND

Red 11

Green 10
Sketch
Explanation
1. The const keyword stands for constant. It is a variable qualifier that modifies
the behavior of the variable, making a variable “read-only”. This means that
the variable’s value cannot be changed.
2. Data types bits Range 3. You should give your variables
byte 8 0 ~ 255 descriptive names, so as to make your code
int 16 -32,768 ~ 32,767 more readable. Variable names like
-2,147,483,648 ~ tiltSensor or pushButton
long 32
2,147,483,647
help you (and anyone else reading your
unsigned int 16 0 ~ 65,535
code) understand what the variable
unsigned long 32 0 ~ 4,294,967,295
represents.
1. The void keyword is used only in function
declarations. It indicates that the function is 3. Serial.begin sets the data rate in
expected to return no information to the bits per second (baud) for serial data
function from which it was called. transmission.

2. pinMode configures the specified pin to


behave either as an input or an output.
2. analogWrite writes an analog value
(PWM wave) to a pin. Can be used to
light a LED at varying brightnesses or
drive a motor at various speeds.

3. Serial.println prints data to the


serial port as human-readable ASCII
text followed by a carriage return
character and a newline character.

4. delay pauses the program for the


amount of time (in milliseconds)
1.The for statement is used to repeat a specified as parameter.
block of statements enclosed in curly
braces. An increment counter is usually
used to increment and terminate the loop.
Serial monitor

Click Tools > Serial Monitor

You see result as following figure.


Ex 2 RGB_LED
• RGB LED modules can emit various colors of light.
Three LEDs of red, green, and blue are packaged into a
transparent or semitransparent plastic shell with four
pins led out.

Principle
We input any value between 0 and 255 to the
three pins of the RGB LED to make it display
different colors.
Build circuit

RGB LED UNO

GND GND

Red 11

Green 10

Blue 9
Sketch

The color function generates


color by RGB value.
Simulations in Proteus
1 Download Arduino.idx and
Arduino.lib

2 Copy them to
C:\Program Files (x86)\Labcenter
4 No PCB
Electronics\Proteus 8
Professional\LIBRARY
Simulations in Proteus
3 Create new project

4 Name project
Simulations in Proteus
5 Pick ‘Arduino ONO RX’ device

Finish picking, you see Arduino Uno


board
Simulations in Proteus 7 Select “Arduino RGB Common
6 Import Project Clip Cathode LED”
Simulations in Proteus
8 delete default pins

9 Reconnect circuit 10 In Arduino, click ‘File > Preferences’


and check ‘compilation’
Simulations in Proteus
11 Verify
sketch and
copy hex file
location.
Simulations in Proteus
12 Double
click Arduino
Uno and
paste in
‘Program
File’.
Simulations in Proteus

13 click ‘Run’ to see result of simulation

Das könnte Ihnen auch gefallen