Вы находитесь на странице: 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} 8 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
Arduino x1
x1 x1

4-40 x 3/8 4-40 #4 x 1/16


x3
x3
x3





Arduino

.: Arduino :.
02 .: http://ardx.org/INTR :.
.: 02 INST
installing

( IDE) :. (
(software and hardware)

)

Arduino.
,
.

1:


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

Windows XP Mac OSX


2: 2: .dmg
()
arduino-00r r -win.zip (rr - ) arduino-00rr-mac.dmg (rr- )

c:\Program Files\

3: 3:

c:\program files\arduino-00r
r - )
\ (r
r
"Arduino" ( devices)
Arduino.exe (send to>Desktop ( ))
"Arduino"
"Applications" ()
4:
Arduino
USB- USB.
4:
.: Duemilanove:.

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

Install from a list or specific location
(Advanced)")

Duemilanove Board
c:\program files\arduino-00rr\drivers\FTDI USB Drivers\
Uno Board 5: Arduino
c:\program files\arduino-00r
r
\drivers\
Arduino USB-
Vista, Seven 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().


// ( /* */(
) ).

,

. ,
( .
.
, .
,
. ; ( )
).

{ } ( )
(
,
. ( ,
). ).


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

boolean () float ( char ()


) ,
True/False. ASCII (
. A =65).
4 (32 ) (8 ). Arduino
-3.4028235+38.
.
.

04
.:
03 PROG
:. -
http://ardx.org/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).)


if ( 1) {} for (int i=0;
else if ( 2) {} i< ;
( else {} i++) {}
) 1 (TRUE)

. . 1 (FALSE)

.
. 2. 2
,
. i
,

Arduino. . .


digitalWrite(pin, value); pinMode(pin, mode); digitalRead(pin);
,
OUTPUT, . INPUT
HIGH (
, +5) LOW 0...19 ( 14 19

( , GND). 0...5).
HIGH LOW.
INPUT ()
OUTPUT ().


analogWrite(pin,value); analogRead(pin);
Arduino - Arduino (3,5,6,9,10,11)
, (-
). INPUT,
.
.
0
(0) 1024

: 0 (0) 255 (+5).
(+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)
: :
3
. :
:
( ).
:
. http://ardx.org/SERV
: :
, 2
. :
:
, .
.
. :
06 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

: :
, 2
:
. ,
:
.
:
. http://ardx.org/PHOT


:
-- = 560
-- = 2 200 = .
2.2 :
-- = 10 000
= 10
:
10 , 7.
:
90 6

.
0 - 5 - 20% - :
1 - 6 - 10% -
2 - 7 - 5% -
3 - 8 - .
4 - 9 -
07
.: :.
CIRC-01 .:( ):.

:

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

:
:
2
CIRC-01 10
x1 x4 x1
560 O
--
x1


Arduino
13


+
LED
()

(560)
(--
)

(ground) (-)

:
.::.

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

http://ardx.org/VIDE01

08
, : 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 )
? ? ?
.

. ,
e-mail
. .

. .
, tools>serial port>
13. help@oomlout.com


: :
13,
Arduino. (
( 0 13,
). 9:
14 19).
: int ledpin = 13; int ledpin = 9;
int ledpin = 13; int ledpin = ;
loop()
Arduino (ctrl-u).
:
: analogWrite(ledPin, new number);
newnumber 0...255. 0
delay(x). , 255
= * 1000. .
:
:

:
:
File > Examples > 3.Analog > Fading
digitalWrite(ledpin,HIGH); Arduino
delay(2000); .
digitalWrite(ledpin,LOW);
delay(2000);

?
, , :

http://ardx.org/CIRC01
09
.:
CIRC-02
8 :.

:
,
! .

.
Arduino.

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

:
:
2 5,
CIRC-02
x1 x4 x8
560 O
--
x8


- - - -
2 3 4 5


560o
gnd
- - - -
6 7 8 9


560o
gnd

:
.::.

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

http://ardx.org/VIDE02

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

? (3 )


,

. .
. ,


. 2

.


: for).
loop() . :
//.
?
,
.
( ). (//) ,
Arduino
: .
//oneAfterAnotherNoLoop();
oneAfterAnotherLoop(); :
//oneOnAtATime(); - .
//inAndOut();
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)

:
:
2
CIRC-03 P2N2222AG (TO92)
x1 x4 x1
2.2k O

(1N4001) --
x1 x1 x1


Arduino P2N2222AG
9 (

)
(2.2)


P2N2222AG



(ground) (-)

+5

:
.::.

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

http://ardx.org/VIDE03

.:: rduino ,

12 :.
, CIRC-03
http://ardx.org/CODE03
( Arduino Sketch)
int motorPin = 9; // 9
void motorOnThenOffWithSpeed(){
void setup() // int onSpeed = 200;
{ // 0 () 255 ( )
pinMode(motorPin, OUTPUT); int onTime = 2500;
} int offSpeed = 50;
// 0 () 255 ( )
void loop() // int offTime = 1000;
{ analogWrite(motorPin, onSpeed);
motorOnThenOff(); //
//motorOnThenOffWithSpeed(); delay(onTime); // onTime
//motorAcceleration(); analogWrite(motorPin, offSpeed);
} //
delay(offTime); // offTime
/* motorOnThenOff() - }
(
void motorAcceleration(){
) int delayTime = 50; //
*/ for(int i = 0; i < 256; i++){
void motorOnThenOff(){ // 0 255
int onTime = 2500; analogWrite(motorPin, i); //sets the new speed
// delay(delayTime);// delayTime
int offTime = 1000; }
// for(int i = 255; i >= 0; i--){
digitalWrite(motorPin, HIGH); // 255 0
// analogWrite(motorPin, i); //sets the new speed
delay(onTime); delay(delayTime);// delayTime
// onTime }
digitalWrite(motorPin, LOW); }
//
delay(offTime);// offTime
}

? (3 )
? ? ?
Arduino
,
,

, .

5
P2N222A.

. . USB Arduino.


: Arduino.
onSpeed
Arduino. offSpeed.

. Arduino :
, (-
). ?
. .
loop()
. :
, 2,5 // motorOnThenOff();
// motorOnThenOffWithSpeed();
. motorAcceleration();
loop() ,
: ,
// motorOnThenOff(); . ,
motorOnThenOffWithSpeed(); delayTime (
// motorAcceleration(); ).

?
, , :

http://ardx.org/CIRC03
13
.:
CIRC-04
:.

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

:
:
3
2
CIRC-04

x1 x1
x4

x1


Arduino
9


()

+5v
gnd (-
(/ )
)


(ground) (-)
+5
(5V)

:
.::.

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

http://ardx.org/VIDE04

14
, : 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 )



? ?
! Arduino
,
- .
. +5
. . ,
USB.


: int pulseTime = 2100;
//
, //900 0 , 1500 90 ,
//2100 180
, File > Servo > digitalWrite(servoPin, HIGH);
Knob. delayMicroseconds(pulseTime);
digitalWrite(servoPin, LOW);
(CIRC08). delay(25);
}
: http://ardx.org/KNOB
:
:

. :
.
.
, http://ardx.org/XMAS

(
Arduino. : Arduino)
int servoPin = 9; http://ardx.org/RARM
void setup(){
pinMode(servoPin,OUTPUT);
}
void loop() { http://ardx.org/SEWA

?
, , :

http://ardx.org/CIRC04
15
.: 8
CIRC-05 (
74HC595):.

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

:
:
2
CIRC-05
x1 x4
74HC595
560 O x1
--
x8 x8

- - -

4 3 2
(560)

74HC595
(ground) (-)

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

:
.::.

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

http://ardx.org/VIDE05

16
, CIRC-05
http://ardx.org/CODE05
( Arduino Sketch)

74HC595
//74HC595 SPI */
// 3 :
int data = 2; void updateLEDs(int value){
int clock = 3;
int latch = 4;

void setup() digitalWrite(latch, LOW);


// // LOW
{
pinMode(data, OUTPUT); shiftOut(data, clock, MSBFIRST, value);
pinMode(clock, OUTPUT); // 8
pinMode(latch, OUTPUT); }

void loop() digitalWrite(latch, HIGH);


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

? (3 )
?
Arduino
?
.
,

- .
. , .

help@oomlout.com
.

.


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

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

?
, , :

http://ardx.org/CIRC05
17
.:
CIRC-06
():.

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

:
:
2
CIRC-06
x1
x1 x4

Arduino
9



(ground) (-)

:
The Internet
.::.

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

http://ardx.org/VIDE06

18
, CIRC-06
http://ardx.org/CODE06
( Arduino Sketch)
/*
* (cleft) 2005 D. Cuartielles for K3 digitalWrite(speakerPin,
* LOW);
* delayMicroseconds(tone);
* . - }
* , . }
*
* : void playNote(char note, int duration) {
* char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
* timeHigh = period / 2 = 1 / (2 * toneFrequency) int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956
*
* : };
* //
* (period) timeHigh for (int i = 0; i < 8; i++) {
* c 261 Hz 3830 1915 if (names[i] == note) {
* d 294 Hz 3400 1700 playTone(tones[i], duration);
* 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 void setup() {
* C 523 Hz 1912 956 pinMode(speakerPin, OUTPUT);
* }
* http://www.arduino.cc/en/Tutorial/Melody
*/ void loop() {
for (int i = 0; i < length; i++) {
int speakerPin = 9; if (notes[i] == ' ') {
int length = 15; // delay(beats[i] * tempo); //
char notes[] = "ccggaagffeeddc "; // } else {
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; playNote(notes[i], beats[i] * tempo);
int tempo = 300; }
//
void playTone(int tone, int duration) { delay(tempo / 2); }
for (long i = 0; i < duration * 1000L; i += tone * 2) { }
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);

? (3 )
,


?
,



. , , .
.
.


: :
'Twinkle Twinkle Little Star,
.
int tempo = 300; ---> ( - int length) .
int tempo = ( ) , notes[] ,
, beats[] . :
, . 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)
tones[]. int length = 13;
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', char notes[] = {"ccdcfeccdcgf "};
'b', 'C' };
int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};
int tones[] = { 1915, 1700, 1519, 1432, 1275,
1136, 1014, 956 };

?
, , :

http://ardx.org/CIRC06
19
.:
CIRC-07 ():.

:

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

:
:
10 kO 560 O
CIRC-07 - --
x1 -
x1
x2


2
x2 x1 x4


Arduino
2 3
Arduino +5 volts
13


(10k)


(560)


(ground) (-)

:
.::.

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

http://ardx.org/VIDE07

20
, : 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, ), .
. , 13 9 :
. : int ledPin = 13; ----> int ledPin = 9;
int ledPin = 13; loop() :
//
int inputPin1 = 3; // 1 int value = 0;
int inputPin2 = 2; // 2 void loop(){
if (digitalRead(inputPin1) == LOW) { value--; }
void setup() { else if (digitalRead(inputPin2) == LOW) { value++; }
pinMode(ledPin, OUTPUT); value = constrain(value, 0, 255);
// analogWrite(ledPin, value);
pinMode(inputPin1, INPUT); // 1 - delay(10);
pinMode(inputPin2, INPUT); // 2 - }
}
void loop(){ / :
if (digitalRead(inputPin1) == LOW) { , ,
digitalWrite(ledPin, LOW); // :
delay(10); ----> delay( );
} else if (digitalRead(inputPin2) == LOW) {
digitalWrite(ledPin, HIGH); // .
} /
} .
.

?
, , :

http://ardx.org/CIRC07
21
.:
CIRC-08
():.

:
Arduino
, .

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

.

:
:
2
CIRC-08 x4 10
x1 x1
560 O
--


x1 x1

Arduino +5
13
Arduino

2
-

(560)
(--
)


(ground) (-)

:
.::.

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

http://ardx.org/VIDE08

22
, : 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); // <sensorValue>
digitalWrite(ledPin, LOW); //
delay(sensorValue); // <sensorValue>
}

? (3 )


,

- .
2 .
. 2 (

. ).


: :
- int ledPin = 13; ----> int ledPin = 9;
( loop :
void loop() {
, int value = analogRead(potPin) / 4;
). analogWrite(ledPin, value);
}

,
:
void loop() {
int threshold = 512; . 4,
if(analogRead(sensorPin) > threshold){ 0...255
digitalWrite(ledPin, HIGH);}
else{ digitalWrite(ledPin, LOW);} (8 ) , analogRead() -
} 0...1024 (10 ).
/ :
. , .
, CIRC-04,
threshold. File>Examples>Servo>Knob, :
int potpin = 0; ----> int potpin = 2;
:
,
.
13 9 .

?
, , :

http://ardx.org/CIRC08
23
.:
CIRC-09
():.

:
,

. ,

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

:
:
2
CIRC-09 x1
x1 x4
10 kO 560 O
- --
- x1
x2 x1

Arduino
13 +5
-

- Arduino

0


(560 )
(10 )


(ground) (-)

:
.::.

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

http://ardx.org/VIDE09

24
, CIRC-09
http://ardx.org/CODE09
( Arduino Sketch)

/* pinMode(ledPin, OUTPUT);
* , // //,
* //,
* , . }
*/ /*
* loop()
//PhotoResistor Pin * setup
int lightPin = 0; // */
// . void loop()
// - {
// , int lightLevel = analogRead(lightPin);
// //

value (relative light) lightLevel = map(lightLevel, 0, 900, 0, 255);


//LED Pin // 0-900
int ledPin = 9; lightLevel = constrain(lightLevel, 0, 255);
// . // 0-255
// , analogWrite(ledPin, lightLevel);
(- //
) }

void setup()
{

? (3 )
?

,
,

.
/
. .
.

180 .
.


: , :
,
. . 9 (
:
analogWrite(ledPin, lightLevel); ----> CIRC-04). Knob File >
analogWrite(ledPin, 255 - lightLevel); Examples > Servo > Knob ( CIRC-08).
: .
,
,
,
. . ,
loop() :
void loop(){
int threshold = 300; , 0...5.
if(analogRead(lightPin) > threshold){ val =
digitalWrite(ledPin, HIGH);
}else{ map(val,0.1023,0,179);
digitalWrite(ledPin, LOW);
}
} 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

:
:

2
CIRC-10
x1 x4

TMP36
x1

Arduino +5

0


+5 TMP36 TMP36
(
)
gnd



(ground) (-)

:
.::.

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

http://ardx.org/VIDE10

26
, CIRC-10
http://ardx.org/CODE10
( Arduino Sketch)
/* ---------------------------------------------
* | Arduino |
* | CIRC-10 | temperature = (temperature - .5)
* | .: :. | * 100;
* --------------------------------------------- // 10/
* ( - 500)x100
*
Serial.println(temperature); //
//TMP36 Pin Variables delay(1000); // 1
int temperaturePin = 0; }
// ,
TMP36. - 10/ /*
( 500 * getVoltage() -
)
*/
void setup() float getVoltage(int pin){
{ return (analogRead(pin) * .004882814);
Serial.begin(9600); // 0...1024
// . 0...5 ( ~ 5 )
}
(
, )
}

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

? (3 )




.
- ,

, , .


.
,
.
.
9600 baud.


: ---->
Serial.print(temperature);
, Serial.println(" degrees centigrade");
. ,
delete the line temperature = (temperature - .5) * 100;

: .
, .
.
:


:
( F = C * 1.8) + 32 ) ,
, .
temperature = 9600
(((temperature - .5) * 100)*1.8) + 32; ,
Serial.println(temperature); . :
: Serial.begin(9600); ----> Serial.begin(115200);
, , 12
. .
, : .
Serial.println(temperature);

?
, , :

http://ardx.org/CIRC10
27
.:
CIRC-11
():.

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

:
:

CIRC-11 (1N4001) P2N2222AG (TO92) (DPDT)
x1 x1 x1 x1
2.2 O
- 560 O
- --
x1 x1
x1
x2
2

x4


Arduino
pin 2

(2.2)

P2N2222AG

P2N2222AG
(



)
+5


(ground) (-)

:
.::.

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

http://ardx.org/VIDE11

28
, : CIRC-11
File > Sketchbook > 1.Basic > Blink
( arduino.cc, )
/*
*
* : 1 , 1
, .. 13, ,
, ,
.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
int ledPin = 2; // *********** CHANGE TO PIN 2 ************
void setup() // ,
{
pinMode(ledPin, OUTPUT); //
}
void loop() //
{
digitalWrite(ledPin, HIGH); //
delay(1000); // 1
digitalWrite(ledPin, LOW); //
delay(1000); // 1
}

? (3 )
(
13,
)
,

2. .
.

. .
.



. , .
Arduino
2
CIRC03 . ,
, . (2.2)
(

560 ). P2N2222AG


.


.
. - +5
H-. DPDT .

: (ground) (-)

?
, , :

http://ardx.org/CIRC11
29
.:
CIRC-12
( RGB):.

:

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

:
:
2
CIRC-RGB RGB 5
x1 x4 x1
560 O
-- x1
x6

:
.::.

http://ardx.org/BBLS12R

30
, CIRC-12
http://ardx.org/CODE12R
( Arduino Sketch)

//RGB LED pins for(int i = 0; i < 3; i++){


int ledDigitalOne[] = {9, 10, 11}; pinMode(ledDigitalOne[i], OUTPUT);
//3 // 3
//9 = redPin, 10 = greenPin, 11 = bluePin }
}
const boolean ON = LOW;
// LOW void loop(){
// ( RGB setColor(ledDigitalOne, CYAN);
// ) +5 //
const boolean OFF = HIGH;
// HIGH //randomColor()

// }
const boolean RED[] = {ON, OFF, OFF};
const boolean GREEN[] = {OFF, ON, OFF}; void randomColor(){
const boolean BLUE[] = {OFF, OFF, ON}; int rand = random(0, sizeof(COLORS) / 2);
const boolean YELLOW[] = {ON, ON, OFF}; //
const boolean CYAN[] = {OFF, ON, ON}; setColor(ledDigitalOne, COLORS[rand]);
const boolean MAGENTA[] = {ON, OFF, ON}; //
const boolean WHITE[] = {ON, ON, ON}; delay(1000);
const boolean BLACK[] = {OFF, OFF, OFF}; }

// void setColor(int* led, boolean* color){


const boolean* COLORS[] = for(int i = 0; i < 3; i++){
{RED, GREEN, BLUE,YELLOW, CYAN, MAGENTA, digitalWrite(led[i], color[i]);
WHITE, BLACK}; }
}

void setup(){

? (3 )
,
?
RGB

RGB . . RGB.

.
R. .




. .
: ,
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/by-
sa/3.0/ Creative Commons :
171 Second Street, Suite 300, San Francisco, California 94105, USA.

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