mao arduino
DESCRIPTION
TRANSCRIPT
阿爾杜伊諾Arduino: Lv. 1
�CęąĤó 2014.5.2
Mutienliao.com ¸hu�Cğĝ·Œ3P
MAO
Sunday, May 4, 14
Sunday, May 4, 14
Sunday, May 4, 14
ArduinoIntroduction
Sunday, May 4, 14
What is Arduino?
Sunday, May 4, 14
Arduino Hardware Arduino Software ŭ Open Source
Physical Computing Platform & Groupŭ
Sunday, May 4, 14
• ª�Ķ6Ķ1414ü ű Digital Pins 0-13
• Digital Pins 0-1/Serial In/Out - TX/RX
- Ē�¶â;Serial portĎŗĊ÷-ĶŪ�ħ: â Pin 0,1.
• ŠÉĶ146ü ű Analog Input Pins A0-A5
• ŠÉĶ6 Analog Output * (Digital Pins 3,5,6,9,10,11)
• Reset �ʼn- S1
• ŞeŗÔĶ1
• NĺŁJumper7¢ãUSB#ŗ�DCŗÔĶ1 (Duemilanove�ČC7¢)
• USBN ó�ãŗĊõĶ1;»�ç²ÜŪ�ĉRŲ#þŗ • ŗÔ#�Vin, 5V, 3.3V (Diecimila�ç»n �·)
Sunday, May 4, 14
各式各樣的Arduino........族繁不及備載
Sunday, May 4, 14
Digital Out Digital In Analog In Analog Out Communication
Sunday, May 4, 14
Digital Out
Sunday, May 4, 14
Analog Out
Sunday, May 4, 14
Digital In
Sunday, May 4, 14
Analog In
Sunday, May 4, 14
Communication
Sunday, May 4, 14
Digital In Digital Out
Analog In Analog Out
Communication
Emotion Experience
Sunday, May 4, 14
Getting started w/ Arduino on your Computer
Sunday, May 4, 14
1 | Get an Arduino & USB cable
Sunday, May 4, 14
| Prepare to test Arduino board
- aėArduinoó�
- ōYLED Blinkø"ÂFile > Examples > Basic > Blink
Sunday, May 4, 14
| Set up your board
• ń¤�� âç»n: Tools > Board
[ Mac OS X ]
[ Mac OS X ]
• ń¤Arduino�_çserial port: Tools > Serila Port
Macçݹè¶�/dev/tty.usbserial- ōś*
[ Windows ]
[ Windows ]
Sunday, May 4, 14
| Upload the program
Ătó�
Vertify
Update to board*
* Arduino NG ç âćŪ\Öď»nË·ČCReset?ĉŪ_�Updateʼn>Ū�ř0��Arudino »n�çResetʼnŪ 5_�*��C�çß��Ū�ĕ_¦ōResetʼn�ŪŢ���UpdateʼnŪ�ĉÆî�-ó�ũ
TX/RXçLEDß�Ù¶�ŋŌÛ
ä-Ķýº�Ū÷ù2~3òŪPin13çpinċ¶ŌÛ(\Ö�'�-çó�)
• ōY File > Examples > Basic > Blink
• Ġĕ�ØOŅçÐóŪvó��-;»n�G
• Ē�?....»n�çÙ¶Èŕ�ò��Äũ
Sunday, May 4, 14
# | Troubleshooting
ĒË�-�?Ū;�¶±�ŧXŝBŰ
• ý�±Sń¤Æîç»nĎSerial portŪŇğr�Äũ
• ĢÍ·XŝŪ%ÆĢÍ�zN� ũ
• Serial Port ÆĘ�â�Ūŏ�5�Æ_âÇSerila portçó�
• »n�çŗÔJump·Ë·ğrÆîŪ·Æ~#ŗūDuemilanove/UNO ¶ČC7¢Ŭ
• »nÆ_åà�í�Ū��»n�çResetŪ 59mEŪ×�_¦ōResetŲŪŢ���IJťõçUpdateũ
• ��çŗı �ArudinoĬĴŁŦŪČC$Ĩ®�USBũ
• ��iNĉç±Ū�ç»n�-Ķād ũ
Sunday, May 4, 14
ŗc(Voltage)
ŗÐ (Current)
Sunday, May 4, 14
āıð�^ ŗı^
• �&ŗıNěÖ�&ĸ]ŪĒĚ+ÅŪ=LĚvŗı��®ıFNũ
• ��çLEDāıņ±ãÇ��çŮŗÔŨLEDŨŗÐŒ</�(ÇÖŗő)ũ• þ´gçŗőŪīÿŁLEDçŗÐĪyŪ=���¶ÒyůI�ŪŗőijyŪ=��Īgũ• RÀçłáŪþçŗįgŪLED�¶į�(> ±�Ú�)ũ
s�Çŗı
Digital Outupt Circuit
Sunday, May 4, 14
Digital Outupt Circuit
Sunday, May 4, 14
Digital Outupt Circuit
Sunday, May 4, 14
breadborad
Sunday, May 4, 14
breadborad
Sunday, May 4, 14
Digital Outª�Ķ6
Digital Out
Sunday, May 4, 14
#1 | Blink
Sunday, May 4, 14
�ŧ±ª�Ű
• Only 1 or 0 / High or LOW / ON or OFF
HIGH
LOW
1
0
Sunday, May 4, 14
int ledPin = 13; // LED connected to digital pin 3
void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}
void loop(){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}
pinMode(pin, Mode) digitalWrite(pin, value) delay(ms)
#1çăĆó�Ū_ File > Examples > Basic > Blink
Sunday, May 4, 14
LED ¡�
W&pin ?
(ó��) �ĚâW&pin?pinMode(who, ?)
(ó��) Ķ6digitalWrite(who,?)
Sunday, May 4, 14
輸入才是互動的精華
Sunday, May 4, 14
Digital Inputª�Ķ1
Digital In
Sunday, May 4, 14
#6 | Button
Sunday, May 4, 14
#6 | Button #6çăĆó�Ū_ File > Examples > Digital > Button
Sunday, May 4, 14
const int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);
// 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); }}
#6çăĆó�Ū_ File > Examples > Digital > Button
Sunday, May 4, 14
Sunday, May 4, 14
#7 | StateChangDetection #7çăĆó�Ū_ File > Examples > Digital > StateChangDetection
Sunday, May 4, 14
Analog OutŠÉĶ6
Analog Out
Sunday, May 4, 14
Analog Output
PWM (Pulse Width Modulation)
ŗĊĎ�ųá[±�NĉsŖĶ6ŠÉçŗc(.ĉ0~5V)ũ
��'N�)ľ6Š�稼ũĒ�Ľ_2&ŗc�*7¢Ū�'N��;�&�`(Ů
Output Voltage = High_time(%) * Max_Voltage
Arduino çPWM pinL·3,5,6,9,10,11
Sunday, May 4, 14
Arduino çPWM pinL·3,5,6,9,10,11
ŠÉĶ60~5Vx�çª(Ö0~255analogWrite( pin, val )
Sunday, May 4, 14
#4 | Fade s�UTÙ稼#4çăĆó�Ū_ File > Examples > Basic > Fade
Sunday, May 4, 14
int brightness = 0; // how bright the LED isint fadeAmount = 5; // how many points to fade the LED by
void setup() { // declare pin 9 to be an output: pinMode(9, OUTPUT);}
void loop() { // set the brightness of pin 9: analogWrite(9, brightness);
// 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); }
#4çăĆó�Ū_ File > Examples > Basic > Fade
Sunday, May 4, 14
Servo
Sunday, May 4, 14
伺服馬達跟DC馬達比較不同,DC馬達是供電就不停地轉動,而伺服馬達是透過PWM訊號供給的時間長短來決定,而伺服馬達有分兩種:
(1) 360度不停轉的,會依照PWM時間長短,決定轉動快慢與轉動方向(2) 定角度的,會依照PWM時間長短,在0~180度角間,精準地控制要擺到那個角度
Sunday, May 4, 14
坊間買得到的伺服馬達會有兩種顏色配對的接線:
(紅.黑.白)~ 對應 V+. GND . 訊號pin
(紅.棕.橘)~ 對應 V+. GND . 訊號pin
#ø"ó� File> Example> Servo> Sweep
Sunday, May 4, 14
輸入才是互動的精華
Sunday, May 4, 14
Analog InputŠÉĶ1
Analog In
Sunday, May 4, 14
Potentiometer
Sunday, May 4, 14
Photocell
get value get value
get value
Sunday, May 4, 14
Arduino çŠÉĶ1 âA0~A5
ŠÉĶ10~5Vx�çª(Ö0~1023analogRead( pin )
Sunday, May 4, 14
#10 | analog_control
#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde
Sunday, May 4, 14
int ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;
void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}
void loop(){ val = analogRead(analogPin); // read the value from the sensor if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50); }
#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde
Sunday, May 4, 14
int ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;
void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output Serial.begin(9600);}
void loop(){ val = analogRead(analogPin); // read the value from the sensor Serial.println(val); if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50); }
%¥#10çăĆó�ŪJ�analogReadŀ!çª(#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde
Sunday, May 4, 14
�'N�0âArduino Software #çSerial Monitor!0ÓĠArduino»nõ-!çĞ�ũ
546756456575456745674567447
baud rate ğr
�Ě-çĞ�Ķ1
-Ĺ!çĞ�
Sunday, May 4, 14
#11 | AnalogInOutSerial #11çăĆó�Ū_ File > Examples > Analog > AnalogInOutSerial
Sunday, May 4, 14
const int analogInPin = A0; // Analog input pin that the potentiometer is attached toconst int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the potint outputValue = 0; // value output to the PWM (analog out)
void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }
void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue);
// wait 10 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(10); }
#11çăĆó�Ū_ File > Examples > Analog > AnalogInOutSerial
Sunday, May 4, 14
CommunicationÕļ
Communication
Sunday, May 4, 14
Arduino ��±ìçĺŁUSB!İŗĊÕļŪĈ±ĺŁRS-232 Serialç¯�ũ
ĺŁ�ĿHIGH / LOWçĂïĞĖŪN�ķ¢��'ĚçĞ�Ů
�ĥŗĊõâ�ŧIJťŪLĚĉĺŁSerial port-ĹĞ�ŪzN�İArduinoÕļũ§�'N�â C/C++, VB, MAX/MSP, VVVV, Processing �±FLASH(ŘĚö�¯IJťç�A)
Sunday, May 4, 14
#12 | PC to Arduino #12çăĆó�Ū_File > Example > Communication > PhysicalPixel
Sunday, May 4, 14
RGBSunday, May 4, 14
RGB LED
Sunday, May 4, 14
RED5V
Blue
Green
4Ŕ�đLED
Sunday, May 4, 14
Arduino
pin 9
5V
pin 10pin 11
RED
BlueGreen
#13çăĆó�Ū_ http://code.mutienliao.tw/arduino/common_anode_RGB.pde
#13çăĆó�Ū_ http://code. mutienliao.tw/arduino/Serial_common_anode_RGB.ino
Sunday, May 4, 14
�ŧs�ÑđŰ
#13çăĆó�Ū_ http://code.mutienliao.tw/arduino/common_anode_RGB.pde
#13çăĆó�Ū_ http://code. mutienliao.tw/arduino/Serial_common_anode_RGB.ino
Sunday, May 4, 14
RGB sensor
Sunday, May 4, 14
VCCS1S0
LEDGND
VCCS3S2OUTGND
5Vpin 7pin 6
GND
pin 5pin 4pin 3
[Arduino] _ http://code.mutienliao.tw/arduino/LightSensing_Simple.ino
Sunday, May 4, 14
[Arduino] _ http://code.mutienliao.tw/arduino/LightSensing_showcolor.ino
FŲJşđčŗĊñ6!
[Processing] _ http://code.mutienliao.tw/processing/show_color.pde
Sunday, May 4, 14