interactivebody workshop_002_01=arduino_sensor
DESCRIPTION
[Technical Study]: For developing basic kinetic or interactive design projects, participants will need to learn basic interactive techniques from simulation to physical computing. Arduino, a well-known microcontroller, will be heavily experimented in this workshop. During the workshop, participants will get the general idea about the basic electronic engineering knowledge and how to use micro-controllers and embed sensing and actuation systems to build the physical prototype. However, they can start experiment the kinetic mechanism by studying physical model as well as virtual simulation through 3D modeling software (Rhino, Maya, Grasshopper...etc). The idea of cellular component and self-organized logics should lead the final projects to an emergent morphological body via collective decision making. Laser-cutting as a digital fabrication technique will also be utilized under the constraint of "using sheet material" for producing the physical prototypes.TRANSCRIPT
ARDUINO(sensor)
What is Sensor?
It is Input!
DigitalRead&Write
Pressthebutton
Signal
Upload the code: File > Examples > 2.Digital > Button.
Press
Light-on
release
Light-off
Press= connectGo the easiest way.
/ 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”
AnalogRead
potentiometer
0-1024+ -
signal
/*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
Serial Monitor
Let’s have some fun=Connect to Processing
Upload the code: http://arduino.cc/en/Tutorial/AnalogReadSerial
Same Code for “Arduino”
Upload the code: http://arduino.cc/en/Tutorial/AnalogReadSerial
/*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?
Code for “Processing”
Upload the code: http://arduino.cc/en/Tutorial/Graph
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
LDRLight Dependent Resistor
/*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
LDR
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
Some Examples I did
https://vimeo.com/14201235
https://vimeo.com/14201235
https://vimeo.com/13977345
https://vimeo.com/13977625
Did you get the idea?
It’s all about INPUT
& OUTPUT