Вы находитесь на странице: 1из 36

ARDX

arduino


Arduino

ARDX
Arduino

Document Revision: May 15 2012




. -

. ,
. -
, ,
help@oomlout.com.


.:oomlout:. . ? , ,
, .

. ? ,
Creative Commons. , , .:oomlout:.,
. ?
,
().
Creative Commons
http://ardx.org/CCLI

.: OOMLOUT :.
,

:

http://www.oomlout.com

SOLARBOTICS
BEAM 15
(-!),
http://www.solarbotics.com/


. ,
, , .

help@oomlout.com / help@solarbotics.com
( .)

, .:oomlout:.
( Solarbotics)

.: :.

TBCN

/
{ASEM}

02

{INST}

03

{PROG}

04

{ELEC}

06

{CIRC01}

( )

08

{CIRC02}

10

{CIRC03}

, ( )

12

{CIRC04}

()

14

{CIRC05}

8 ( 74HC595) 16

{CIRC06}

()

18

{CIRC07}

()

20

{CIRC08}

()

22

{CIRC09}

()

24

{CIRC10}

( 36)

26

{CIRC11}

()

28

{CIRC12}

( RGB)

30

01

01 ASEM

.: :.

Arduino
x1

x1

Arduino
x1

4-40 x 3/8
x3

4-40
x3

#4 x 1/16

x3





Arduino

02

.: Arduino :.
.: http://ardx.org/INTR :.

.:

( IDE) :.

02 INST
installing

(software and hardware)


)

Arduino.
,
.

1:


http://arduino.cc/en/Main/Software

Windows XP
2:

r
r
- )
arduino-00r
-win.zip (r

c:\Program Files\

3:

r
\ (r
r
- )
c:\program files\arduino-00r


Arduino.exe (send to>Desktop ( ))

Mac OSX
2: .dmg
()
arduino-00r
r
-mac.dmg (r
r
- )

3:

"Arduino" ( devices)

"Arduino"
"Applications" ()

4:
Arduino
USB- USB.

5:


( next )

4:
.: Duemilanove:.

"Arduino" device
, :
r
FTDI Drivers for Intel Macs (r
_r
_r
).pkg
r
(FTDI Drivers for PPC Macs (r
_r
_r
).pkg

Install from a list or specific location


(Advanced)")


Duemilanove Board
c:\program files\arduino-00r
r
\drivers\FTDI USB Drivers\
Uno Board

c:\program files\arduino-00r
r
\drivers\

Vista, Seven

5: Arduino
Arduino USB-
USB

5:

Device Manager
Start > Run > devmgmt.msc
Arduino
Other Devices > Arduino Uno (Uno)

.: ? :.
.: ? Linux? :.
.: http://ardx.org/LINU :.

Update Driver


Browse My Computer for Driver Software
c:\program files\arduino-00r
r
\drivers\

03

03 PROG

.:
:.

Arduino
Arduino . ,
,
Arduino. , ,
.
arduino.cc.

Arduino
( )

(
).

void setup(){

void loop(){

,
,
,
.



,

setup().

// (
)


. ,

.


.

/* */(





(
,
,

).

,
.

{ } ( )


(
).

).
,


.

.

( )


(

,
).



.

.

boolean ()

True/False.


.

04

int ()
,

(16
).
-32 768
32 767.

float (
)

.
4 (32 )
-3.4028235+38.

long ()
,
int.
4 (32
) -2 147
483 648 2 147 483 647.

char ()
,
ASCII (
A =65).
(8 ). Arduino

.

.:
:.
http://ardx.org/PROG

03 PROG

() - -(
=10*2 20).
% ). 12%10 2.
+ ()
()
* ()
/ ()


,

.

== () ( 12==10 (FALSE), 5==5 (TRUE).)


!= ( ) ( 12!=10 (TRUE), 5!=5 (FALSE).)
< () ( 12<10 (FALSE), 12<12 (FALSE),
12<14 (TRUE).)

>

()

( 12>10 (TRUE), 12>12 (FALSE),


12>14 (FALSE).)



(
)
.
.


Arduino.

if ( 1) {}
else if ( 2) {}
else {}

for (int i=0;


i< ;
i++) {}

1 (TRUE)

. 1 (FALSE)
2. 2
,
,

.



.

. i

.


digitalWrite(pin, value);

OUTPUT,
HIGH (
, +5) LOW
( , GND).

pinMode(pin, mode);
,
.

0...19 ( 14 19
0...5).
INPUT ()
OUTPUT ().

digitalRead(pin);

INPUT


HIGH LOW.


Arduino -
,

analogWrite(pin,value);

analogRead(pin);

Arduino (3,5,6,9,10,11)
( ).

.



0 (0) 255 (+5).


INPUT,
.

0
(0) 1024
(+5).

05

04 ELEC

.:

:.


.
,
, . -

help@oomlout.com


LED
()

:

.
.

:
.

:

.
.

:


( ,

: 2
( ()
)

:

.
.
:
http://ardx.org/LED
: 2
:

. ,
,
.

:
http://ardx.org/DIOD

).

:
,
.
:

.

: 2
:
.
.

:
http://ardx.org/RESI

(
).

:

.
:

.
(

:
3 (, , )
:
.
.

:
http://ardx.org/TRAN

P2N2222AG)

:

.
:


.

06

.
:
, .

.

:
3
:

( ).
:
http://ardx.org/SERV
:
2
:


.
:
http://ardx.org/MOTO

04 ELEC
()

:
.

.
:
.
.

: 2
:
.
:
http://ardx.org/PIEZ

IC ( )
:

.
TMP36 3 74HC595 16
.

:

(
).

:
.

:
http://ardx.org/ICIC

:
.
:

.

:
4
:
,
90 .
:
http://ardx.org/BUTT

:
,
.
:

.

:
3
:

.
:
http://ardx.org/POTE

:
,

.
:


.


:
-- = 560
-- = 2 200 =
2.2
-- = 10 000
= 10

0
1
2
3
4

5
6
7
8
9

20% -
10% -
5% -

:
2
:
,

.
:
http://ardx.org/PHOT



.
:
:
10 , 7.
:
90 6
.
:


.

07

CIRC-01

.: :.
.:( ):.

:

, .
- ,
.
, ,
. , .
Arduino USB.
Tools>Serial Port>(, Arduino).
File>Upload to I/O Board (ctrl+U). ,
!
: http://ardx.org/TRBL

:
:

2
CIRC-01

x1
x4
560 O
--
x1

Arduino
13

LED
()

(560)
(-)

(ground) (-)

:
.::.

http://ardx.org/BBLS01
.::.

http://ardx.org/VIDE01

08

10
x1

CIRC-01

, :

File > Examples > 1.Basic > Blink


( arduino.cc, )
/*
* 1 , 1 ,
*
* Created 1 June 2005 By David Cuartielles
* http://arduino.cc/en/Tutorial/Blink
* based on an orginal by H. Barragan for the Wiring i/o board
*/

int ledPin =

13;

// 13

// setup() 1
void setup()
{
// 13 :
pinMode(ledPin, OUTPUT);
}
// loop()
// Arduino
void loop()
{
digitalWrite(ledPin, HIGH);
//
delay(1000);
// 1
digitalWrite(ledPin, LOW);
//
delay(1000);
// 1
}

? (3 )
?


.

.

.
,
13.

?
.

e-mail

tools>serial port>

help@oomlout.com


:
13,
Arduino.
( 0 13,
14 19).
:
int ledpin = 13; int ledpin = ;

Arduino (ctrl-u).
:

delay(x).
= * 1000.
:

:
digitalWrite(ledpin,HIGH);
delay(2000);
digitalWrite(ledpin,LOW);
delay(2000);

:

(

). 9:
int ledpin = 13; int ledpin = 9;
loop()
:
analogWrite(ledPin, new number);
newnumber 0...255. 0
, 255
.
:
:
File > Examples > 3.Analog > Fading
Arduino
.

?
, , :

http://ardx.org/CIRC01

09

CIRC-02

.:
8 :.

:
,
! .

.
Arduino.

.
for() loops - ,
.
arrays[] - (
).

:
:

CIRC-02
x1

x4

560 O
--
x8

- - - 2 3 4 5

560o

gnd
- - - 6 7 8 9

560o

gnd

:
.::.

http://ardx.org/BBLS02
.::.

http://ardx.org/VIDE02

10

5,

x8

CIRC-02

http://ardx.org/CODE02
( Arduino Sketch)
//
int ledPins[] = {2,3,4,5,6,7,8,9};
//,
//
//, 0 -
//2
void setup()
{
for(int i = 0; i < 8; i++){
// 8
pinMode(ledPins[i],OUTPUT);
// ,
//,
}
}
void loop()
//
{
oneAfterAnotherNoLoop();
//
//
//oneAfterAnotherLoop();
// oneAfterAnotherNoLoop
//
//oneOnAtATime();
//inAndOut();
}
/*
* oneAfterAnotherNoLoop() -

,
delayTime,
,

void oneAfterAnotherNoLoop(){
int delayTime = 100;
//
//
digitalWrite(ledPins[0], HIGH);
// 0
// 2
delay(delayTime);
// delayTime
//( )
...
...
digitalWrite(ledPins[7], HIGH);
// 7 9
delay(delayTime);
// delayTime ( )
//
digitalWrite(ledPins[7], LOW); //
7
delay(delayTime);
// delayTime
//( )
...
----- ------

? (3 )



. ,

2

.

.

.



,
.


:
loop() .
//.
,
( ).

:
//oneAfterAnotherNoLoop();
oneAfterAnotherLoop();
//oneOnAtATime();
//inAndOut();

Arduino
, .
,
,
(

for).
:
?
.
(//) ,
Arduino
.
:
- .

digitalWrite(pinNumber,HIGH);

digitalWrite(pinNumber,LOW);
, ,
, !

?
, , :

http://ardx.org/CIRC02

11

.: ,
CIRC-03
:.
.: :.
:
Arduino -
( ).
, (
)
. ,

. . NPN
, ( ).
( HIGH Arduino),
, .
, .
P2N2222AG. ,
, 40, 600 .
.
: http://ardx.org/2222).
1N4001. : http://ardx.org/4001)

:
:

CIRC-03
x1

x4

P2N2222AG (TO92)
x1

x1

(1N4001)
x1

2.2k O
--
x1

Arduino
9

(2.2)


P2N2222AG
(

)

P2N2222AG


(ground) (-)

+5

:
.::.

http://ardx.org/BBLS03
.::.

http://ardx.org/VIDE03

12

.:: rduino ,
:.

CIRC-03

http://ardx.org/CODE03
( Arduino Sketch)
int motorPin = 9; // 9
void setup() //
{
pinMode(motorPin, OUTPUT);
}
void loop()
//
{
motorOnThenOff();
//motorOnThenOffWithSpeed();
//motorAcceleration();
}
/* motorOnThenOff() -
(
)
*/
void motorOnThenOff(){
int onTime = 2500;
//
int offTime = 1000;
//
digitalWrite(motorPin, HIGH);
//
delay(onTime);
// onTime
digitalWrite(motorPin, LOW);
//
delay(offTime);// offTime
}

void motorOnThenOffWithSpeed(){
int onSpeed = 200;
// 0 () 255 ( )
int onTime = 2500;
int offSpeed = 50;
// 0 () 255 ( )
int offTime = 1000;
analogWrite(motorPin, onSpeed);
//
delay(onTime);
// onTime
analogWrite(motorPin, offSpeed);
//
delay(offTime);
// offTime
}
void motorAcceleration(){
int delayTime = 50; //
for(int i = 0; i < 256; i++){
// 0 255
analogWrite(motorPin, i);
//sets the new speed
delay(delayTime);// delayTime
}
for(int i = 255; i >= 0; i--){
// 255 0
analogWrite(motorPin, i);
//sets the new speed
delay(delayTime);// delayTime
}
}

? (3 )
?


,


P2N222A.

.

Arduino

USB Arduino.


:

Arduino.

. Arduino
, (-
).
.

.
, 2,5

.
loop()
:
// motorOnThenOff();
motorOnThenOffWithSpeed();
// motorAcceleration();

Arduino.
onSpeed
offSpeed.
:

?
.
loop()
:
// motorOnThenOff();
// motorOnThenOffWithSpeed();
motorAcceleration();
,
,
. ,
delayTime (
).

?
, , :

http://ardx.org/CIRC03

13

CIRC-04

.:
:.

:
,
, ,
- .
. ,
,
. ( )
( ).
0 180 .
, 1.25 (0 ) 1.75 (180 , 1.5
90 ). .
25...50 , .
Arduino
, (
9 10).

:
:

CIRC-04
x1

x1

Arduino
9

()

+5v
gnd
(/
)

()


(ground) (-)

+5
(5V)

:
.::.

http://ardx.org/BBLS04
.::.

http://ardx.org/VIDE04

14

x4

x1

CIRC-04

, :

File > Examples > Servo > Sweep


( arduino.cc, )

// (by BARRAGAN <http://barraganstudio.com>)


#include <Servo.h>
Servo myservo; //
int pos = 0;
//
void setup() {
myservo.attach(9);
}

// 9

void loop() {
for(pos = 0; pos < 180; pos += 1)// 0 180 1
myservo.write(pos);
//
// 'pos'
delay(15);
// 15 for the servo to reach the
position
}
for(pos = 180; pos>=1; pos-=1) // 180 0
{
myservo.write(pos);
//
// 'pos'
delay(15);
// 15
}
}

? (3 )

?



-
.
.

!


+5
.


Arduino
,
.

,
USB.


int pulseTime = 2100;
//
//900 0 , 1500 90 ,
//2100 180
digitalWrite(servoPin, HIGH);
delayMicroseconds(pulseTime);
digitalWrite(servoPin, LOW);
delay(25);

:
,
, File > Servo >
Knob.
(CIRC08).
: http://ardx.org/KNOB
:

:

. :

.
.
,

Arduino. :
int servoPin = 9;
void setup(){
pinMode(servoPin,OUTPUT);
}
void loop() {


http://ardx.org/XMAS
(
Arduino)
http://ardx.org/RARM


http://ardx.org/SEWA

?
, , :

http://ardx.org/CIRC04

15

CIRC-05

.: 8
(
74HC595):.

:
.
. ,
Arduino ,
. ATMega
, 74HC595
. - ,
(http://ardx.org/74HC595),
. (
) 8 ( -
) Arduino. ,
,
Arduino.
.
: .
,
. ,
. :
http://ardx.org/SHIF.

:
:
2

x4

74HC595
560 O
x1
--
x8


CIRC-05
x1

x8

:
.::.

http://ardx.org/BBLS05
.::.

http://ardx.org/VIDE05

16

(ground) (-)

+5 0
1
2
data 3
clock 4
latch
5
6
gnd 7

74HC595

(560)

- -
4
3
2

CIRC-05

http://ardx.org/CODE05
( Arduino Sketch)

//74HC595 SPI
// 3 :
int data = 2;
int clock = 3;
int latch = 4;

74HC595
*/
void updateLEDs(int value){

void setup()
//
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT); }

digitalWrite(latch, LOW);
// LOW
shiftOut(data, clock, MSBFIRST, value);
// 8

void loop()
//
{
int delayTime = 100;
//
for(int i = 0; i < 256; i++){
updateLEDs(i);
delay(delayTime);
}
}

digitalWrite(latch, HIGH);
// -
}
----- ------

/*
* updateLEDs() -

? (3 )

Arduino



.


.

,
- .

.

?

.

, .
help@oomlout.com


:
Arduino
.
- .
(
).
:
updateLEDs(i); updateLEDslong(i);
,
.
updateLEDslong(i); ,
(
http://ardx.org/SPI).
:

CIRC02.
(8 ). Arduino

.

http://ardx.org/BITW.
:
int delayTime = 100;
//
for(int i = 0; i < 8; i++){
changeLED(i,ON);
delay(delayTime);
}for(int i = 0; i < 8; i++){
changeLED(i,OFF);
delay(delayTime);
}
Arduino.
.
:

CIRC02
digitalWrite(led,state) changeLED(led,state).

?
, , :

http://ardx.org/CIRC05

17

CIRC-06

.:
():.

:
,
. .
, , .
Arduino?
,
. ,
.
( 440 ),
.
Arduino - .

:
:

CIRC-06
x1

Arduino
9

(ground) (-)

The
:
Internet
.::.

http://ardx.org/BBLS06
.::.

http://ardx.org/VIDE06

18

x4

x1

CIRC-06

http://ardx.org/CODE06
( Arduino Sketch)
/*
* (cleft) 2005 D. Cuartielles for K3
*
*
* . -
* , .
*
* :
*
*
timeHigh = period / 2 = 1 / (2 * toneFrequency)
*
* :
*
*
(period)
timeHigh
* c
261 Hz
3830
1915
* d
294 Hz
3400
1700
* e
329 Hz
3038
1519
* f
349 Hz
2864
1432
* g
392 Hz
2550
1275
* a
440 Hz
2272
1136
* b
493 Hz
2028
1014
* C
523 Hz
1912
956
*
* http://www.arduino.cc/en/Tutorial/Melody
*/
int speakerPin = 9;
int length = 15; //
char notes[] = "ccggaagffeeddc "; //
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);

digitalWrite(speakerPin,
LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956
};
//
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); //
} else {
playNote(notes[i], beats[i] * tempo);
}
//
delay(tempo / 2);
}
}

? (3 )





.




, ,

,

.



int tempo = 300; --->
int tempo = ( )

'Twinkle Twinkle Little Star,


.
( - int length) .
, notes[] ,
, beats[] . :


, .
:
, -
, .

tones[].
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a',
'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275,
1136, 1014, 956 };

Twinkle Twinkle Little Star


int length = 15;
char notes[] = {"ccggaagffeeddc "};
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
1, 1, 2, 4 };

Happy Birthday (first line)


int length = 13;
char notes[] = {"ccdcfeccdcgf "};
int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};

?
, , :

http://ardx.org/CIRC06

19

.:
CIRC-07 ():.
:

. Arduino ,
. .
.
, . , Arduino
. ,
.
(LOW) , ,
(HIGH). , Arduino
.
: .

:
:
10 kO
-
-
x2


CIRC-07
x1

x2


x1

Arduino
2

Arduino

+5 volts

13

(560)


(ground) (-)

:
.::.

http://ardx.org/BBLS07
.::.

http://ardx.org/VIDE07

20

(10k)

560 O
-
x1

2
x4

CIRC-07

, :

File > Examples > 2.Digital > Button

( arduino.cc, )
/*
*
* by DojoDave <http://www.0j0.org>
*
* .
* http://www.arduino.cc/en/Tutorial/Button
*/
int ledPin = 13;
//
int inputPin = 2;
// ,
int val = 0;
//
void setup() {
pinMode(ledPin, OUTPUT);
// , ,
pinMode(inputPin, INPUT);
// , ,
}
void loop(){
val = digitalRead(inputPin); //
if (val == HIGH) {
//
digitalWrite(ledPin, LOW); //
} else {
digitalWrite(ledPin, HIGH); //
}
}

? (3 )

()

90 .

13

9 .

?
,

,
.



.


:
(,
Arduino, ),
. ,
. :
int ledPin = 13;
//
int inputPin1 = 3;
// 1
int inputPin2 = 2;
// 2
void setup() {
pinMode(ledPin, OUTPUT);
//
pinMode(inputPin1, INPUT); // 1 -
pinMode(inputPin2, INPUT); // 2 -
}
void loop(){
if (digitalRead(inputPin1) == LOW) {
digitalWrite(ledPin, LOW); //

} else if (digitalRead(inputPin2) == LOW) {


digitalWrite(ledPin, HIGH); //
}
}

/ :

.
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);
}

/ :
, ,
:
delay(10);

----> delay( );

.
/
.

?
, , :

http://ardx.org/CIRC07

21

.:

CIRC-08

():.

:
Arduino
, .

0...5 0...1023
( 10 ).
( ) ,
.
+5,
0...5, ( ).
2.5.

.

:
:

CIRC-08
x1


x1

Arduino

+5

13

Arduino

(560)
(-)

(ground) (-)

:
.::.

http://ardx.org/BBLS08
.::.

http://ardx.org/VIDE08

22

2
x4
560 O
-
x1

10
x1

CIRC-08

, :

File > Examples > 3.Analog > AnalogInput


( arduino.cc, )
/*
* , 0
* , 13.
* , analogRead().
* Created by David Cuartielles
* Modified 16 Jun 2009
* By Tom Igoe
* http://arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = 0;
int ledPin = 13;
int sensorValue = 0;

//
//
// ,

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

// , ,

void loop() {
sensorValue = analogRead(sensorPin);//
digitalWrite(ledPin, HIGH);
//
delay(sensorValue);
//
digitalWrite(ledPin, LOW);
//
delay(sensorValue);
//
}



<sensorValue>

<sensorValue>

? (3 )

-

.

.

,


2
2 (

).



.
.


:
-
(
,
).

:

:
int ledPin = 13; ----> int ledPin = 9;

loop :
void loop() {
int value = analogRead(potPin) / 4;
analogWrite(ledPin, value);
}

/
.
,
threshold.

,

. 4,
0...255
(8 ) , analogRead() -
0...1024 (10 ).
:
, .
CIRC-04,
File>Examples>Servo>Knob, :

:

.
13 9

,

.

void loop() {
int threshold = 512;
if(analogRead(sensorPin) > threshold){
digitalWrite(ledPin, HIGH);}
else{ digitalWrite(ledPin, LOW);}
}

int potpin = 0; ----> int potpin = 2;

?
, , :

http://ardx.org/CIRC08

23

CIRC-09

.:
():.

:
,

. ,

.
. Arduino . Arduino
( ),
(http://ardx.org/VODI).
,
. .
, .

:
:

CIRC-09
x1
10 kO
-
-
x2

Arduino
13

+5

(560 )

Arduino

(10 )


(ground) (-)

:
.::.

http://ardx.org/BBLS09
.::.

http://ardx.org/VIDE09

24

x4
560 O
-
x1

x1


x1

CIRC-09

http://ardx.org/CODE09
( Arduino Sketch)
/*
* ,
*
* , .
*/

pinMode(ledPin, OUTPUT);
// //,

//PhotoResistor Pin
int lightPin = 0; //
// .
// -
// ,
//

//,
}
/*
* loop()
* setup
*/
void loop()
{
int lightLevel = analogRead(lightPin);
//

value (relative light)


//LED Pin
int ledPin = 9;
// .
// ,
(-
)

lightLevel = map(lightLevel, 0, 900, 0, 255);


// 0-900
lightLevel = constrain(lightLevel, 0, 255);
// 0-255
analogWrite(ledPin, lightLevel);
//
}

void setup()
{

? (3 )


180 .

?
,
,

.
/
.


.


:
,
.
:
analogWrite(ledPin, lightLevel); ---->
analogWrite(ledPin, 255 - lightLevel);
:
,
,
.
loop() :
void loop(){
int threshold = 300;
if(analogRead(lightPin) > threshold){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
}

, :

. 9 (
CIRC-04). Knob File >
Examples > Servo > Knob ( CIRC-08).
.
,
. ,

, 0...5.
val =
map(val,0.1023,0,179);

http://arduino.cc/en/Reference/Map.

?
, , :

http://ardx.org/CIRC09

25

CIRC-10

.:
( 36):.

:
Arduino? !

,
P2N222AG.
: , +5. 10/
(
500 , . . 25 = 750 , 0 = 500 ).
Arduino.
Arduino.
.
.
Arduino,
:
TMP36: http://ardx.org/TMP36

:
:

CIRC-10
x1

TMP36
x1

x4

Arduino

+5

TMP36
+5
(
)
gnd

(ground) (-)

:
.::.

http://ardx.org/BBLS10
.::.

http://ardx.org/VIDE10

26


TMP36

CIRC-10

http://ardx.org/CODE10
( Arduino Sketch)
/*
*
*
*
*
*
*

--------------------------------------------| Arduino
|
| CIRC-10
|
| .: :.
|
--------------------------------------------

//TMP36 Pin Variables


int temperaturePin = 0;
// ,
TMP36. - 10/
( 500
)
void setup()
{
Serial.begin(9600);
// .

(
, )
}

temperature = (temperature - .5)


* 100;
// 10/
( - 500)x100
Serial.println(temperature); //
delay(1000);
// 1
}
/*
* getVoltage() -

*/
float getVoltage(int pin){
return (analogRead(pin) * .004882814);
// 0...1024
0...5 ( ~ 5 )
}

void loop()
//
{
float temperature = getVoltage(temperaturePin);
/*
*/

? (3 )


- ,


.

9600 baud.

.

,

.


, .

,
.


:
,
.
delete the line

temperature = (temperature - .5) * 100;

:
,
.

:
( F = C * 1.8) +

32 )


temperature =
(((temperature - .5) * 100)*1.8) + 32;
Serial.println(temperature);

:
,
.
, :
Serial.println(temperature);

---->
Serial.print(temperature);
Serial.println(" degrees centigrade");

,

.
.
:

,
, .
9600
,
. :
Serial.begin(9600); ----> Serial.begin(115200);

, 12
.
.

?
, , :

http://ardx.org/CIRC10

27

CIRC-11

.:
():.

:
-
.
(CIRC03) . -
- .
,
( ).
( ,
). ,
. Arduino -
.

:
:

CIRC-11
x1
2.2 O
-
-
x1
2

x4

(1N4001)
x1

560 O
-
x2

P2N2222AG (TO92)
x1

x1

(DPDT)
x1

x1

Arduino
pin 2

(2.2)

P2N2222AG

+5


(ground) (-)

:
.::.

http://ardx.org/BBLS11
.::.

http://ardx.org/VIDE11

28


P2N2222AG
(

)

CIRC-11

, :

File > Sketchbook > 1.Basic > Blink


( arduino.cc, )

/*
*
* : 1 , 1
, .. 13, ,
, ,
.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
int ledPin = 2;

// ***********

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

// ,

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}

CHANGE TO PIN 2 ************

//
//
//
//
//
//


1

1

? (3 )

13,


2.



. , .

Arduino
2


CIRC03 . ,

(2.2)

, .
(
560 ).


.
. -
H-. DPDT .
:

P2N2222AG

+5


(ground) (-)

?
, , :

http://ardx.org/CIRC11

29

.:
CIRC-12

( RGB):.
:

.
,
( RGB
).
RGB R , G B
.
.
RGB ,
.

:
:

CIRC-RGB
x1

x4

560 O
--
x6

:
.::.

http://ardx.org/BBLS12R

30

RGB 5
x1


x1

CIRC-12

http://ardx.org/CODE12R
( Arduino Sketch)
//RGB LED pins
int ledDigitalOne[] = {9, 10, 11};
//3
//9 = redPin, 10 = greenPin, 11 = bluePin
const boolean ON = LOW;
// LOW
// ( RGB
// ) +5
const boolean OFF = HIGH;
// HIGH
//
const boolean RED[] = {ON, OFF, OFF};
const boolean GREEN[] = {OFF, ON, OFF};
const boolean BLUE[] = {OFF, OFF, ON};
const boolean YELLOW[] = {ON, ON, OFF};
const boolean CYAN[] = {OFF, ON, ON};
const boolean MAGENTA[] = {ON, OFF, ON};
const boolean WHITE[] = {ON, ON, ON};
const boolean BLACK[] = {OFF, OFF, OFF};
//
const boolean* COLORS[] =
{RED, GREEN, BLUE,YELLOW, CYAN, MAGENTA,
WHITE, BLACK};

for(int i = 0; i < 3; i++){


pinMode(ledDigitalOne[i], OUTPUT);
// 3
}
}
void loop(){
setColor(ledDigitalOne, CYAN);
//
//randomColor()
}
void randomColor(){
int rand = random(0, sizeof(COLORS) / 2);
//
setColor(ledDigitalOne, COLORS[rand]);
//
delay(1000);
}
void setColor(int* led, boolean* color){
for(int i = 0; i < 3; i++){
digitalWrite(led[i], color[i]);
}
}

void setup(){

? (3 )
,



RGB .

.



RGB

.


R.


?


RGB.


.


.
:

setColor(ledDigitalOne, CYAN); ---->


setColor(ledDigitalOne, **NEW COLOR**);


,
.

:


,
.
:
http://ardx.org/MABE12R

void loop(){
//setColor(ledDigitalOne, CYAN);
randomColor()
}

?
, , :

http://www.solarbotics.com

31

32

.: :.

.: :.

33

ARDX
arduino

www.oomlout.com

Creative Commons
Attribution-Share Alike 3.0 Unported License.
, : http://creativecommons.org/licenses/bysa/3.0/ Creative Commons :
171 Second Street, Suite 300, San Francisco, California 94105, USA.

Вам также может понравиться