multi sensory communication 2/2

60
Sensor and Actuator Ueki Atsuro Satoru Tokuhisa 2011.11.29

Upload: satoru-tokuhisa

Post on 16-Apr-2017

59 views

Category:

Design


2 download

TRANSCRIPT

Page 1: Multi Sensory Communication 2/2

Sensor and Actuator

Ueki AtsuroSatoru Tokuhisa

2011.11.29

Page 2: Multi Sensory Communication 2/2

Parts

• Arduino UNO x1• USB cable x1• GROVE - Starter Bundle x 1pkg ※Please keep these parts until 12/20

Multi Sensory Communication 2

Page 3: Multi Sensory Communication 2/2

Additional Parts

• 3 axis Gyro x 1• 3 axis Accelerometer x 1• Sound Sensor x1• Vibrator x1• Rotary Angle Sensor x 1

Multi Sensory Communication 3

Page 4: Multi Sensory Communication 2/2

Download

• Source code– http://dl.dropbox.com/u/

326446/msc/02/source.zip

Multi Sensory Communication 4

Page 5: Multi Sensory Communication 2/2

Reference

• GROVE system– http://www.seeedstudio.com/wiki/GROVE_System

• Language Reference– http://arduino.cc/en/Reference/HomePage

• Tutorial– http://arduino.cc/en/Tutorial/HomePage

Multi Sensory Communication 5

Page 6: Multi Sensory Communication 2/2

Outline

• How to use Sensor– Rotary Angle Sensor – 3 axis Accelerometer – 3 axis Gyro

• How to use Actuator– Piezo Buzzer– Vibrator– Servo Morot

Multi Sensory Communication 6

Page 7: Multi Sensory Communication 2/2

Practice with GROVE

Multi Sensory Communication 7

Page 8: Multi Sensory Communication 2/2

GROVE Starter Kit

Multi Sensory Communication 8

Page 9: Multi Sensory Communication 2/2

Pack List

• Buttons X1• LEDs X1• Tilt X1• Buzzer X1• Rotary Angle Sensor X1• Temperature Sensor (Analog) X1

9Multi Sensory Communication

Page 10: Multi Sensory Communication 2/2

Pack List

• Smart Relay X1• Protoshield X1• LCD1602 Baseshield + LCD X1• Stem  Base Shield X1• GROVE Cable X10

10Multi Sensory Communication

Page 11: Multi Sensory Communication 2/2

Additional Parts

• 3 axis Gyro x 1• 3 axis Accelerometer x 1• Sound Sensor x1• Vibrator x1• Rotary Angle Sensor x 1

Multi Sensory Communication 11

Page 12: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

Analog InputA0-A5

Digital Input / OutputD1- D13

A1

A0

A2

A3

A4

A5

D1D2D3D4D5D6

D7D8D9D10D11D13 D12

12

I2C

Page 13: Multi Sensory Communication 2/2

Review

Multi Sensory Communication 13

Page 14: Multi Sensory Communication 2/2

digitalWrite/analogWrite

Multi Sensory Communication

LED Twig

14

Page 15: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

D13

15

Page 16: Multi Sensory Communication 2/2

Hello World!

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); }

void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second}

16Multi Sensory Communication

Page 17: Multi Sensory Communication 2/2

Change the Blink Interval

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); }

void loop() { digitalWrite(13, HIGH); // set the LED on delay(100); // wait for a second digitalWrite(13, LOW); // set the LED off delay(100); // wait for a second}

17Multi Sensory Communication

Page 18: Multi Sensory Communication 2/2

Change the Blink Ratio

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); }

void loop() { digitalWrite(13, HIGH); // set the LED on delay(5); // wait for a second digitalWrite(13, LOW); // set the LED off delay(5); // wait for a second}

18Multi Sensory Communication

Page 19: Multi Sensory Communication 2/2

Change the Blink Ratio

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); }

void loop() { digitalWrite(13, HIGH); // set the LED on delay(1); // wait for a second digitalWrite(13, LOW); // set the LED off delay(9); // wait for a second}

19Multi Sensory Communication

Page 20: Multi Sensory Communication 2/2

Practice

• analogWrite(PWM)• http://arduino.cc/en/Reference/AnalogWrite

20Multi Sensory Communication

Page 21: Multi Sensory Communication 2/2

PWM

• PWM(Pulse Width Modulation)

D = τ/ TD : duty cycleτ: pulseT : transition

Multi Sensory Communication

ex: 0.25(D) = 1(τ)/4(T)

Pulse

time

21

Page 22: Multi Sensory Communication 2/2

PWM

Multi Sensory Communication

Analog Input x 6

Digital Input and Output x 14

3.3VGround

Ground

5V

Power Indicator

External Power

22

PWM~3, 5, 6, 9, 10, 11

Page 23: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

D11

23

Page 24: Multi Sensory Communication 2/2

Practice

void setup() { pinMode(11, OUTPUT); // 3, 5, 6, 9, 10, 11,}

void loop() { analogWrite(11, 255); // 0-255}

• analogWrite• http://arduino.cc/en/Reference/AnalogWrite

24Multi Sensory Communication

Page 25: Multi Sensory Communication 2/2

Sensor

Multi Sensory Communication 25

Page 26: Multi Sensory Communication 2/2

Practice 01

Multi Sensory Communication

Potentiometer Twig (Rotary angle sensor)

26

Page 27: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

A0

27

Page 28: Multi Sensory Communication 2/2

Arduino IDE

Multi Sensory Communication

Serial Monitor

Opens the serial monitor.

28

Page 29: Multi Sensory Communication 2/2

Practice 01 const int analogInPin = 0; int sensorValue = 0;

void setup() { Serial.begin(9600); // open the serial port at 9600 bps: }

void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); Serial.println(sensorValue); delay(1000); }

29Multi Sensory Communication

-Rotary Angle Sensor ->A0-※Check the position of GND(Red)

Page 30: Multi Sensory Communication 2/2

Practice 01

• analogRead• Description

• Reads the value from the specified analog pin. • It will map input voltages between 0 and 5 volts into

integer values between 0 and 1023. • Syntax

• analogRead(pin) • Returns

• Int(0 to 1023)

30Multi Sensory Communication

Page 31: Multi Sensory Communication 2/2

Practice 01

• Serial.begin• Description

• Sets the data rate in bits per second (baud) for serial data transmission.

• For communicating with the computer, use one of these rates: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200.

• Syntax• Serial.begin(speed)

31Multi Sensory Communication

Page 32: Multi Sensory Communication 2/2

Practice 01

• Serial.println• Description

• Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n').

• Syntax• Serial.println(val)

Serial.println(val, format)

32Multi Sensory Communication

Page 33: Multi Sensory Communication 2/2

Advance 01

33Multi Sensory Communication

• How to check the present angle?• The angular range is 300 degrees • Hint

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

Page 34: Multi Sensory Communication 2/2

Advance 01 const int analogInPin = 0; int sensorValue = 0;

void setup() { Serial.begin(9600); // open the serial port at 9600 bps: }

void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); sensorValue = map(sensorValue, 0, 1023, 0, 300); Serial.println(sensorValue); delay(1000); }

34Multi Sensory Communication

-Rotary Angle Sensor ->A0-※Check the position of GND(Red)

Page 35: Multi Sensory Communication 2/2

Practice 02

Multi Sensory Communication

3 axis accelerometer

35

Page 36: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

I2c

36

Page 37: Multi Sensory Communication 2/2

Practice 02

• Source Code• Practice02.txt

• Open Practice02.txt, copy the all, and paste it to Arduino IDE.

37Multi Sensory Communication

Page 38: Multi Sensory Communication 2/2

Arduino IDE

Multi Sensory Communication

Serial Monitor

Opens the serial monitor.

38

Page 39: Multi Sensory Communication 2/2

Practice 02

• Wire Library• This library allows you to communicate with I2C / TWI

devices. http://www.arduino.cc/en/Reference/Wire

• I2C• Serial communication method developed by Pilips

• Advantages: it can handle multiple signals with only two signal cables.

• Disadvantages: its program gets longer.

39Multi Sensory Communication

Page 40: Multi Sensory Communication 2/2

Practice 03

Multi Sensory Communication

3 axis Gyro

40

Page 41: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication

I2c

41

Page 42: Multi Sensory Communication 2/2

Practice 03

• Source Code• Practice03.txt

• Open Practice03.txt, copy the all, and paste it to Arduino IDE.

42Multi Sensory Communication

Page 43: Multi Sensory Communication 2/2

Actuator

Multi Sensory Communication 43

Page 44: Multi Sensory Communication 2/2

Practice 04

Multi Sensory Communication

knob

44

x

Servo motor

Page 45: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication 45

To knob

5V / GND to SERVO (RED / BROWN)

Digital 9 to SERVO(ORANGE)

Page 46: Multi Sensory Communication 2/2

Practice 04

• Source Code• Files > Example > Servo > Knob

46Multi Sensory Communication

Page 47: Multi Sensory Communication 2/2

Practice 04#include <Servo.h> Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometerint val; // variable to read the value from the analog pin void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)

val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }

Multi Sensory Communication 47

Page 48: Multi Sensory Communication 2/2

Practice 05

Multi Sensory Communication

Vibrator

48

Page 49: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication 49

Port 9 to vibrator

Page 50: Multi Sensory Communication 2/2

Practice 05

• Source Code• Files > Example > 3.Analog > Fading

50Multi Sensory Communication

Page 51: Multi Sensory Communication 2/2

Practice 06

Multi Sensory Communication

Vibrator

51

x

Mic

Page 52: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication 52

Port 9 to vibrator

Analog 0 to mic

Page 53: Multi Sensory Communication 2/2

Practice 06

• Source Code• Practice06.txt

• Open Practice06.txt, copy the all, and paste it to Arduino IDE.

53Multi Sensory Communication

Page 54: Multi Sensory Communication 2/2

Practice 07

Multi Sensory Communication

Piezo Buzzer

54

Page 55: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication 55

Port 8 to Piezo Buzzer

Page 56: Multi Sensory Communication 2/2

Practice 07

• Source Code• Files > Example > 2.Digital > toneMelody

56Multi Sensory Communication

Page 57: Multi Sensory Communication 2/2

Practice 08

Multi Sensory Communication

Piezo Buzzer

57

knob

x

Page 58: Multi Sensory Communication 2/2

Stem

Multi Sensory Communication 58

Port 8 to Piezo Buzzer

analog 0 to knob

Page 59: Multi Sensory Communication 2/2

Practice 08

• Source Code• Files > Example > 2.Digital > tonePitchFollower

59Multi Sensory Communication

Page 60: Multi Sensory Communication 2/2

Trial!!!

Multi Sensory Communication 60

accelerometer

x

Mic