Download - InteractiveBody Workshop_002_01=Arduino_Sensor

Transcript
Page 1: InteractiveBody Workshop_002_01=Arduino_Sensor

ARDUINO(sensor)

Page 2: InteractiveBody Workshop_002_01=Arduino_Sensor

What is Sensor?

Page 3: InteractiveBody Workshop_002_01=Arduino_Sensor

It is Input!

Page 4: InteractiveBody Workshop_002_01=Arduino_Sensor

DigitalRead&Write

Page 5: InteractiveBody Workshop_002_01=Arduino_Sensor

Pressthebutton

Page 6: InteractiveBody Workshop_002_01=Arduino_Sensor

Signal

Upload the code: File > Examples > 2.Digital > Button.

Press

Light-on

release

Light-off

Press= connectGo the easiest way.

Page 7: InteractiveBody Workshop_002_01=Arduino_Sensor

/ constants won't change. They're used here to // set pin numbers:const int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pin

// variables will change: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);

}}

Set up which pin for what

If you press the button

It turns “on”

Page 8: InteractiveBody Workshop_002_01=Arduino_Sensor

AnalogRead

Page 9: InteractiveBody Workshop_002_01=Arduino_Sensor

potentiometer

Page 10: InteractiveBody Workshop_002_01=Arduino_Sensor

0-1024+ -

signal

Page 11: InteractiveBody Workshop_002_01=Arduino_Sensor

/*AnalogReadSerialReads an analog input on pin 0, prints the result to the serial monitor.Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.*/

// the setup routine runs once when you press reset:void setup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);

}

// the loop routine runs over and over again forever:void loop() {// read the input on analog pin 0:int sensorValue = analogRead(A0);// print out the value you read:Serial.println(sensorValue);delay(1); // delay in between reads for stability

}

Set up which pin for what

Read the message from Analog Pin0

In every ? million second

Print out the value

How to see it?

Upload the code: http://arduino.cc/en/Tutorial/AnalogReadSerial

Page 12: InteractiveBody Workshop_002_01=Arduino_Sensor

Serial Monitor

Page 13: InteractiveBody Workshop_002_01=Arduino_Sensor

Let’s have some fun=Connect to Processing

Upload the code: http://arduino.cc/en/Tutorial/AnalogReadSerial

Page 14: InteractiveBody Workshop_002_01=Arduino_Sensor

Same Code for “Arduino”

Upload the code: http://arduino.cc/en/Tutorial/AnalogReadSerial

Page 15: InteractiveBody Workshop_002_01=Arduino_Sensor

/*AnalogReadSerialReads an analog input on pin 0, prints the result to the serial monitor.Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.*/

// the setup routine runs once when you press reset:void setup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);

}

// the loop routine runs over and over again forever:void loop() {// read the input on analog pin 0:int sensorValue = analogRead(A0);// print out the value you read:Serial.println(sensorValue);delay(1); // delay in between reads for stability

}

Set up which pin for what

Read the message from Analog Pin0

In every ? million second

Print out the value

How to see it?

Page 16: InteractiveBody Workshop_002_01=Arduino_Sensor

Code for “Processing”

Upload the code: http://arduino.cc/en/Tutorial/Graph

Page 17: InteractiveBody Workshop_002_01=Arduino_Sensor

import processing.serial.*;Serial myPort; // The serial portint xPos = 1; // horizontal position of the graph

void setup () {// set the window size:size(1000, 500); // List all the available serial portsprintln(Serial.list());// I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0].// Open whatever port is the one you're using.myPort = new Serial(this, Serial.list()[0], 9600);myPort.bufferUntil('\n'); // don't generate a serialEvent() unless you get a newline character:background(0); // set inital background:}void draw () { // everything happens in the serialEvent()}

void serialEvent (Serial myPort) {// get the ASCII string:String inString = myPort.readStringUntil('\n');

if (inString != null) {// trim off any whitespace:inString = trim(inString);// convert to an int and map to the screen height:float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height);// draw the line:stroke(127,34,255);line(xPos, height, xPos, height - inByte);// at the edge of the screen, go back to the beginning:

if (xPos >= width) {xPos = 0;background(0); }

else {// increment the horizontal position:xPos++; }

}}

Import the library

Check the serial

Break the numbers

Where we can play with

Remap the Value

Page 18: InteractiveBody Workshop_002_01=Arduino_Sensor
Page 19: InteractiveBody Workshop_002_01=Arduino_Sensor

LDRLight Dependent Resistor

Page 20: InteractiveBody Workshop_002_01=Arduino_Sensor

/*AnalogReadSerialReads an analog input on pin 0, prints the result to the serial monitor.Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.*/

// the setup routine runs once when you press reset:void setup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);

}

// the loop routine runs over and over again forever:void loop() {// read the input on analog pin 0:int sensorValue = analogRead(A0);// print out the value you read:Serial.println(sensorValue);delay(1); // delay in between reads for stability

}

Set up which pin for what

Read the message from Analog Pin0

In every ? million second

Print out the value

Turn on your serial monitor

Same code from: http://arduino.cc/en/Tutorial/AnalogReadSerial

Page 21: InteractiveBody Workshop_002_01=Arduino_Sensor

LDR

Page 22: InteractiveBody Workshop_002_01=Arduino_Sensor

import processing.serial.*;Serial myPort; // The serial portint xPos = 1; // horizontal position of the graph

void setup () {// set the window size:size(1000, 500); // List all the available serial portsprintln(Serial.list());// I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0].// Open whatever port is the one you're using.myPort = new Serial(this, Serial.list()[0], 9600);myPort.bufferUntil('\n'); // don't generate a serialEvent() unless you get a newline character:background(0); // set inital background:}void draw () { // everything happens in the serialEvent()}

void serialEvent (Serial myPort) {// get the ASCII string:String inString = myPort.readStringUntil('\n');

if (inString != null) {// trim off any whitespace:inString = trim(inString);// convert to an int and map to the screen height:float inByte = float(inString); inByte = map(inByte, 0, 100, 0, height);// draw the line:stroke(127,34,255);line(xPos, height, xPos, height - inByte);// at the edge of the screen, go back to the beginning:

if (xPos >= width) {xPos = 0;background(0); }

else {// increment the horizontal position:xPos++; }

}}

Still you can play with Processing(Same Code)

Check the serial

Break the numbers

Where we can play with

Need to Remap this

Page 23: InteractiveBody Workshop_002_01=Arduino_Sensor
Page 24: InteractiveBody Workshop_002_01=Arduino_Sensor

Some Examples I did

https://vimeo.com/14201235

Page 25: InteractiveBody Workshop_002_01=Arduino_Sensor

https://vimeo.com/14201235

Page 26: InteractiveBody Workshop_002_01=Arduino_Sensor
Page 27: InteractiveBody Workshop_002_01=Arduino_Sensor

https://vimeo.com/13977345

Page 28: InteractiveBody Workshop_002_01=Arduino_Sensor

https://vimeo.com/13977625

Page 29: InteractiveBody Workshop_002_01=Arduino_Sensor

Did you get the idea?

Page 30: InteractiveBody Workshop_002_01=Arduino_Sensor

It’s all about INPUT

& OUTPUT