2. Parts
• Arduino UNO x1
• USB cable x1
• GROVE - Starter Bundle x 1pkg
※Please keep these parts until 12/20
Multi Sensory Communication
2
3. 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
4. Download
• Source code
– http://dl.dropbox.com/u/326446/
msc/02/source.zip
Multi Sensory Communication
4
5. 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
6. 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
16. 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
}
16
Multi Sensory Communication
17. Change the BlinkInterval
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
}
17
Multi Sensory Communication
18. Change the BlinkRatio
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
}
18
Multi Sensory Communication
19. Change the BlinkRatio
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
}
19
Multi Sensory Communication
21. PWM
• PWM(Pulse Width Modulation)
D = τ/ T
D : duty cycle
τ: pulse
T : transition
Multi Sensory Communication
ex: 0.25(D) = 1(τ)/4(T)
Pulse
time
21
22. PWM
Multi Sensory Communication
Analog Input x 6
Digital Input and
Output x 14
3.3V
Ground
Ground
5V
Power Indicator
External Power
22
PWM~
3, 5, 6, 9, 10, 11
29. 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);
}
29
Multi Sensory Communication
-Rotary Angle Sensor ->A0
-※Check the position of GND(Red)
30. 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)
30
Multi Sensory Communication
31. 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)
31
Multi Sensory Communication
32. 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)
32
Multi Sensory Communication
33. Advance 01
33
Multi Sensory Communication
• How to check the present angle?
• The angular range is 300 degrees
• Hint
http://arduino.cc/en/Reference/Map
34. 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);
}
34
Multi Sensory Communication
-Rotary Angle Sensor ->A0
-※Check the position of GND(Red)
39. 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.
39
Multi Sensory Communication
46. Practice 04
• Source Code
• Files > Example > Servo > Knob
46
Multi Sensory Communication
47. Practice 04
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int 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
// is comment
pinMode = Configures the specified pin to behave either as an input or an output.
digitalWrite = Write a HIGH or a LOW value to a digital pin.
Writes an analog value (PWM wave) to a pin.
HighとLowをすばやく切りかえることで、 中間量の電流が流れているときと同じ状態を作ることができる。
http://monoist.atmarkit.co.jp/fembedded/h8/h8primer09/h8primer09a.html
1/10 = 0.1 D
9/10 = 0.9 D
Writes an analog value (PWM wave) to a pin.
The potentiometer twig produces analog output between 0 and Vcc (5V DC) on its SIG(D1) Pin. The D2 Pin is NC(not used).
The angular range is 300 degrees with a linear change in value.
Writes an analog value (PWM wave) to a pin.
Writes an analog value (PWM wave) to a pin.
3 axis motion/orientation sensing
For...
Motion Detection
Digital Still Camera: Image Stability
I2C = serial communication method
Magic spell
motherboard, embedded system, cellphone, or other electronic device.
Merits: it can handle multiple signals with only two signal cables.
Demerits: its program becomes longer.
Magic spell
motherboard, embedded system, cellphone, or other electronic device.
Merits: it can handle multiple signals with only two signal cables.
Demerits: its program becomes longer.