Professional Documents
Culture Documents
ArduinoAll
.
www.arduinoall.com
(
)
ArduinoAll
1 : Arduino LED
2 : LED 8
3 :
4 :
5 : LED IC 74HC595
6 :
7 :
8 :
9 : LDR
10 : DS18B20
11 :
12 : IC 2003
13 : Tilt
14 : LED 3
15 : 4x4
16 :
13 :
17 : SD Card Module
14 : PIR
15 : DHT11
16 :
19 : DS1302
20 : LCD
21 : RF 4
22 : Bluetooth
23 : RFID
24 :
25 :
26 : IC
:
1. http://arduino.cc/en/Main/Software
2.
3.
Desktop
4. USB Arduino
5. (
)
C
http://www.Arduino.cc
()
2 (
)
setup : void setup(){} 1
loop : void loop(){} setup
// 1 //
/**/
/* */
{}
; (
)
int (integer) 2 ( 16 )
32,768 32,768
long 4
-2,147,483,648 2,147,483,647
float 4
-3.4028235E+38 3.4028235E+38.
char (character) 1 ( A = 65)
1 (8 )
char
Boolean
1
=
x = 10*2 ( x 20)
% 12%10 ( 2)
+
-
*
/
== 12==10 false
!= 12 !=10 true
< 10 < 12 true
> 10 > 12 false
>= 12>=12 true
<= 12<=12 true
if ( )
if(){}
else if(){}
else{}
else if
else
if else
for (
)
for(int i=0;i<;i++){}
pinMode(pin,mode);
, 0
19 ( 0-5 14-19)
mode 3
INPUT, OUTPUT, INPUT_PULLUP
digitalWrite(pin,value);
HIGH 1 (5 )
LOW 0 (0 )
Int digitalRead(pin);
HIGH 1( 5 ) LOW
0 (0 )
analogWrite(pin,value);
PWM (pulse width
modulation 3,5,6,9,10,11)
value
0 255 (0% duty cycle 0 100% duty cycle
5 )
int analogRead(pin);
0-1024 (0 0 1024
5 )
- .......
Transistor ()
-
-
- 3 (Base,Collector,Emitter)
Servo ()
-
- 3 ,
DC Motor ()
-
- 2
-
Piezo Element ()
-
- 2
Integrated Circuit IC ()
-
-
- 1
Pushbutton ()
-
- 2 - 4
Potentiometer ()
-
- 3
Photo Resistor ()
-
-
- 2
Relay ()
-
- 5 2 2
01 : Arduino LED
1.
2.
3. /
LED
LEDs (light emitting diodes)
LED /
1. 1
2. 560 1
3. LED
4.
2 ()
: File>Examples>Basics>Blink
Arduino.cc
// 13 LED
// int led
int led = 13;
// setup 1
void setup() {
// led
pinMode(led, OUTPUT);
}
// loop
void loop() {
digitalWrite(led, HIGH); // LED (HIGH )
delay(1000);
// 1000 1
digitalWrite(led, LOW);
delay(1000);
// LED (LOW )
// 1000 1
3
USB
3
1. Arduino Uno
2.
3.
Parallel Programmer
Ctrl+U Done
uploading
32,256
1,084
?
1. :
usb 3 1-3
2. :
3.
> device manager
1. LED 13
/
(0-13 A0-A5 )
3. LED
PWM(pulse width modulation)
3 , 5 , 6 , 9 , 10 , 11 A0 , A1 ,
A2 ,A3 , A4 , A5 (PWM)
0 255 LED
256 0
9 LED int ledPin = 9;
analogWrite(ledPin,200); 200
0-255
Fading LED
pinMode(pin,mode);
, 0 19
( 0-5 14-19)
HIGH 1 (5 ) LOW
0 (0 )
:: digitalWrite(13, HIGH); // 13 (HIGH )
()
2 (
)
setup : void setup(){} 1
loop : void loop(){} setup
02 : LED 8
1.
2.
LED 1
LED 8
LED
for()
array()
1.
2. 560
4.
3. LED
// 1 //
/**/ /* */
{}
for ()
for(int i=0;i<;i++){}
2 ()
circuit02.ino
for
LED / (PWM) 1
03 :
LED
P2N2222A 40
600 ()
1.
2. 2.2K
3.
4. 14001
5. P2N2222AG
6.
2 () circuit03
LED
0-255
PWM (Pulse Width Modulation)
5V 0V
/
1 analogWrite(0) 0V
analogWrite(255) 5V 2
analogWrite(64) 1 25% 75%
3 50% 50% analogWrite(127) 127
255 4 ???
analogWrite(pin,value);
PWM (pulse width
modulation 3,5,6,9,10,11)
value
0 255 (0% duty cycle 0 100% duty cycle
1.
digitalWrite(motorPin, HIGH); //
analogWrite(motorPin,20) //
20 255
2.
04 :
3 ,
0-180 0-360
library
1.
2.
3.
2 ()
circuit04
1.
5 : LED IC 74HC595
Intergrated circuits IC
IC
IC 74HC595
/ 32
??? IC 74HC595
3
8
3
1.
2. LED
3. 560
4. IC 74HC595
5.
2 ()
circuit05
1.
IC 74HC595
6 :
LED ,
,
?
,
440
Twinkle
Twinkle Little Star ( )
1. 1
2.
3.
2 () circuit6
1.
int tempo
= 300; int tempo = xxx
2.
array
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
3. happy birthday ()
int length = 13;
char notes[] = {"ccdcfeccdcgf "};
int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};
7 :
?
0 5 5 0
5
0
1.
2. 10K
4. 560
3.
5. LED
6.
2
1
2 ()
3
1. 1
// LED
int inputPin1 = 3;
// 1
int inputPin2 = 2;
// 2
void setup() {
pinMode(ledPin, OUTPUT); // LED
pinMode(inputPin1, INPUT); // 1
pinMode(inputPin2, INPUT); // 2
}
void loop(){
if (digitalRead(inputPin1) == LOW) {
digitalWrite(ledPin, LOW); // LED
} else if (digitalRead(inputPin2) == LOW) {
digitalWrite(ledPin, HIGH); // LED
}
}
2.
LED
13 9 int ledPin = 13; ----> int
ledPin = 9; loop()
int value = 0;
void loop(){
if (digitalRead(inputPin1) == LOW) { value--; }
else if (digitalRead(inputPin2) == LOW) { value++; }
value = constrain(value, 0, 255);
analogWrite(ledPin, value);
delay(10);
}
3.
LED
delay(10); 10
8 :
6
0-5
0-1023 ( 10 = 2^10 = 1024 )
1.
2. LED
3. 560
4. 10
5.
1
1
1
2 ()
/*
*
*/
int sensorPin = A0;
int ledPin = 13;
// 0
// 13 LED
int sensorValue = 0; //
void setup() {
pinMode(ledPin, OUTPUT); // ledPin
}
void loop() {
// LED
//
// LED
//
1.
if
void loop() {
int threshold = 512;
if(analogRead(sensorPin) > threshold){
digitalWrite(ledPin, HIGH);}
else{ digitalWrite(ledPin, LOW);}
}
LED 512
2. LED PWM (
) 13 LED 9 int
ledPin=13; int ledPin=9;
void loop(){
int value=analogRead(potPin)/4;
analogWrite(ledPin,value);
}
4 analogWrite
0-255 0-1023
3. Servo 04 Servo
servo
9 : LDR
LDR
2
1.
3. (LDR)
2. 10K
4. 560
5.
2 ()
void loop()
{
int lightLevel = analogRead(lightPin); // lightPin
lightLevel = map(lightLevel, 0, 900, 0, 255); // map
// 0 900 0 255
1. analogWrite(ledPin,lightLevel);
analogWrite(ledPin,255-lightLevel);
2.
LDR
void loop(){
int threshold = 300;
if(analogRead(lightPin)> threshold){
digitalWrite(ledPin,HIGH);
}else{
digitalWrite(ledPin,LOW);
}
}
3. servo servo
servo 0-180
map(, , , , )
0-1023 0 179
map(val,0,1023,0,179)
10 : DS18B20
IC DS18B20 IC
1.
2. 10K
4. 560
3. (LDR)
5.
2 ()
library
Document > Arduino
libraries
library Arduino IDE
Simple
3
Serial Port
1. library
2. 9600
Serial Port Serial.begin(9600);
Serial.begin(115200);
12
11 :
220
Relay ()
5 2 2
(
)
1.
2. 2.2K
4. 14001
6. LED
3. 5
5. P2N2222AG
7.
1
1
2 ()
1.
: LED
LED
2. LED LED
3. LED LED
4. 03
5. 220
220