You are on page 1of 52

Arduino

mctsaione@gmail.com

Agenda

Arduino UNO IDE


( )
IC
( + + IC)

Motoduino
: +
2

: 2005
Massimo Banzi, David , Mellis , Martino , Tom

Arduino UNO IDE

Arduino UNO

1. USB ( )
2. Power Jack USB
7V_12V 9V 1 2

3. USB IC: Arduino USB

Arduino UNO

4. Voltage Regulator:
5. RX/TX LED RX TX

LED LED
7 0 1
6. LED 7 13

Arduino UNO

7. :
7-1 0 13
10 10 PWM (Pulse Width
Modulation) (analog) , LED
7-2 GND:
7-3 AREF AREF Analogue REFerence

Arduino
3.3V

Arduino UNO

8. RX(0) TX (1): UART( )

arduino RX ( 0 ; TX (
1
: USB
USB
0 1

Arduino UNO

9. LED
10.
11. ICSP Header: In-circuit serial programming
bootloader ATmega
12 Microcontroller: (ATmega328)

Arduino UNO

13. a0,a1,a2,a3,a4,a5
14.
14-1: Vin ( )
14-2/3: Gnd ( )
14-4: 5V (5V )
14-5: 3V3 (3V )
14-6: RESET ( )
14-7: IOREF( ): 5V , MCU

Arduino IDE

1. Arduino IDE (Integrated Development Environment)


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

2. USB (USB driver)


a. Arduino IDE , USB Arduino PC

(arduino ->[drivers] )
b. -> -> -> -> ( )
->

LED

( )

IC

IC

( )

( )
( ) :

IC TA7291


P10

P5

P11

P6


( + +
IC)
7

P6

P1
1

P5

P1
0

PWM
PWM (Pulse Width Modulation)

RGB LED
/
PWM
~~~~

-- -- -- -- -- -- --
-- ~

PWM

PWM
Duty Cycle = Ton/Toff(%) ON OFF

V = Vonx duty cycle (%)


duty cycle OFF
duty cycle = 100% V = Von

Arduino PWM

analogWrite(pin, value)

pin PWM pin


pin 3/5/6/9/10/11
value duty cycle 0~255
0 = 0% 127 = 50% 255 =
100%
analog(3,127) pin 3
duty cycle 50%
VCC=5V, Pin3 2.5V

PWM
sketch
int ledPin = 3; // LED PWM pin3
void setup()
{
pinMode(ledPin, OUTPUT); // pin 3
}
// loop LED
void loop()
{
analogWrite(ledPin, 0); // LED
delay (1000);
analogWrite(ledPin, 64); // LED 1/4
delay (1000);
analogWrite(ledPin, 175); // LED 1/2
delay (1000);
analogWrite(ledPin, 255); // LED
delay (1000);
}


(Motor_Test_by_serial_port.ino)

//IR Sensor
#define L 8
#define R 7
//Right
#define MA1 5
#define MA2 6
//Left
#define MB1 10
#define MB2 11
int i,SP_R,SP_L;
char val ;
void setup()
{
Serial.begin(9600); //for arduino serial port mointor
pinMode(MA1,OUTPUT);
pinMode(MA2,OUTPUT);
pinMode(MB1,OUTPUT);
pinMode(MB1,OUTPUT);
SP_R=200; //150~255
SP_L=200; // 150~255
}
void loop()
{
if(Serial.available())
{
val = Serial.read();
Serial.println(val);
switch (val) {
case 'F' :
forward();
break;
case 'L' :
right();
break;
case 'R' :
left();
break;
case 'B' :
backward();
break;
case 'S' :
motorstop();
break;
}
}
}

void forward(){
analogWrite(MA1,SP_R);
digitalWrite(MA2,LOW);
analogWrite(MB1,SP_L);
digitalWrite(MB2,LOW);
}
void right(){
analogWrite(MA1,SP_R);
digitalWrite(MA2,LOW);
digitalWrite(MB1,LOW);
digitalWrite(MB2,LOW);
}
void left(){
digitalWrite(MA1,LOW);
digitalWrite(MA2,LOW);
analogWrite(MB1,SP_L);
digitalWrite(MB2,LOW);
}
void backward(){
digitalWrite(MA1,LOW);
analogWrite(MA2,SP_R);
digitalWrite(MB1,LOW);
analogWrite(MB2,SP_L);
}
void motorstop(){
digitalWrite(MA1,LOW);
digitalWrite(MA2,LOW);
digitalWrite(MB1,LOW);
digitalWrite(MB2,LOW);
delay(5000);
}

(Passive_IR, )

(5~14um)

CdS PbS

LED

CNY70

: CdS) PbS)

( )

TCRT5000

IR

IR
<=2cm
1. IR
2. IR (1,2 )

IR V+(5V) UNO 5V
IR G(GND) UNO
GND
IR S Pin 7
IR S Pin 8

IR
IR_CAR.ino
Vin( )
IR
2cm

-1
IR

-2
IR

-3
IR

IR
voidSTATE_L
loop(){
= digitalRead(L);

//IR Sensor test


#define L 8
#define R 7
//Right
#define MA1 5
#define MA2 6
//Left
#define MB1 10
#define MB2 11
//LED
#define LED 13
// Music
#define Buzzer 2
int
i,STATE_L,STATE_R,SP_R,SP_L;
void setup(){
Serial.begin(9600);
pinMode(R,INPUT);
pinMode(L,INPUT);
}

STATE_R = digitalRead(R);
i= STATE_L*10 + STATE_R;
//Serial.println(i);
// delay(500);
switch (i){
case 0: //Forward
forward();
break;
case 1: //Turn Left
left();
break;
case 10: //Turn Right
right();
break;
case 11: //STOP
motorstop();
break;
}
}


IR_CAR.ino
Vin( )
:
SP_R=170; // 150~255
SP_L=170; // 150~255
:
1.IR ( )
2.
3. IR

Motoduino

motoduino Arduino(ATMEGA328),
Arduino , , .

Motoduino
:
1. 7V ~ 12 V
2. channel <= 600mA
3. PIN 5, PIN 6, PIN 7 PIN 8
4. PWM
5. Arduino Duemilanove
6. DC LED
7. ATMEGA328P IC Socket IC
8.

Motoduino
motoduino 2 D5+D8
D6+D7 , , :

D8
=true
=false

D5
0~255

D7
=true
=false

D6
0~255

Motoduino IR_CAR

:
1.S4A for IR_CAR
2. +


GPIO

USB


A. app : innoSCar.apk
: https://app.box.com/s/ukuur9tn062bfiqeqorp
B.Arduino_UNO :
1.
2. (VCC 5V,GND GND;TXD Pin3,RXD
Pin4)
3. USB
3. BT_For_UNO_CAR.inb
5.
C. :
1. Connect Device (Scan)
2.Device : HC-06
3.ID =1234

You might also like