3. Components of the Codeable Circuit
• This circuit is codeable, which means that you can control whether or not
these components are activated or not, using inputs and outputs.
• Outputs – the LEDs, the RGB light, the buzzer.
– You can make these different components (called ‘actuators’) turn on
and off and different rates, patterns, etc.
– *Note – To make these controllable/codeable (not always on), at least
one side (usually the + end) needs to be attached to a numbered or A-
pin; the other end can be attached to + or – pin
• Inputs – metallic patches
– You can take a reading of electrical current or conductivity (generally).
If you touch both then you ‘close the circuit’
– *Note - these need to be attached to A-pins (and the – pin) for taking
readings.
5. _
+
Rules for Connecting Components
This LED is always on because it’s connected to the + and – pin.
6. _
+
Rules for Connecting Components
This LED can be programmed/controlled
because you can code pin 5 (polarity).
7. _
+
Rules for Connecting Components
This LED can be programmed/controlled
because you code pin A5 (polarity).
You can also connect the LED to any other
numbered or lettered pin if you want to control it
(though note that only numbered pins can execute
‘analogWrite’ for behaviors such as fade).
8. Rules for Connecting Components
This is also possible. Both pin 5
AND pin 6 would need to be
programmed.
_
+
9. _
+
Rules for Connecting Components
A Parallel Circuit – both LEDs function in the same way
(by coding pin 5).
_
+
10. _
+
Rules for Connecting Components
Also a Parallel Circuit – both LEDs function in the
same way *by programming pin 5)
_
+
11. _
+
Rules for Connecting Components
Not a parallel circuit. These LEDs
function separately (coding pin 5 or
pin 6) even though they have a
shared ground (-).
_
+
12. Rules for Connecting Components
In order to attach the metallic patches, you need to connect one patch to the –
pin and the other patch to one of the A-pins. You can tell the A-pin to take a
‘reading’ of electrical current (generally).
Basically, when you touch both of these, you ‘close the circuit’ (because your
body is conductive and can carry current) and then the A-pin can be told to read
this, and do something as a result.
13. Rules for Connecting Components
The patch connected to the – pin
can also be attached to other
components to act as a ground.
The patches and LEDs act in the
same way.
_
+
15. This is a basic blink program
int bird = 5;
void setup() {
pinMode(bird, OUTPUT);
}
void loop() {
digitalWrite(bird, HIGH);
delay(1000);
digitalWrite(bird, LOW);
delay(1000);
}
This section is for naming variables.
Here, we are calling pin 5 “bird” so
we don’t always have to write 5 in
the below section. Or if we can
quickly change the pin # (if you
resew it) without having to change
each place below.
16. This is a basic blink program
int bird = 5;
void setup() {
pinMode(bird, OUTPUT);
}
void loop() {
digitalWrite(bird, HIGH);
delay(1000);
digitalWrite(bird, LOW);
delay(1000);
}
This is the setup section, where you
write up the conditions that we
want to exist throughout the
program, even when it’s going
through different behaviors. Here,
we setup the pin named bird to be
an output for electricity (an
actuator).
17. This is a basic blink program
int bird = 5;
void setup() {
pinMode(bird, OUTPUT);
}
void loop() {
digitalWrite(bird, HIGH);
delay(1000);
digitalWrite(bird, LOW);
delay(1000);
}
This is the loop section, or the
‘action’ of the program. Basically,
what this code says is:
Turn on pin 5 (voltage high)
Wait 1000 milliseconds
Turn off pin 5 (voltage low)
Wait 1000 milliseconds
18. This is a basic blink program
int bird = 5;
void setup() {
pinMode(bird, OUTPUT);
}
void loop() {
digitalWrite(bird, HIGH);
delay(1000);
digitalWrite(bird, LOW);
delay(1000);
}
19. Basic human sensor program
int sensorValue; //a placeholder for the function below
int MetalPatch = A3; //if your metallic patch is attached to pin A5 and the
other one is attached to the - pin
void setup() {
Serial.begin(9600); //gets touch sensor ready to read value - analog
digitalWrite(MetalPatch, HIGH); //start circuit for human sensing circuit
pinMode(MetalPatch, INPUT); //sets A3 as an input of electricity, for reading
}
void loop() {
sensorValue = analogRead(MetalPatch); //read values from light sensor
Serial.println(sensorValue); //show values in serial monitor window
delay(300); //delay time determines how often the Lilypad will read the
sensor
} Everything to the right of // is a comment and doesn’t get compiled as part of the
code. The way this code works is that you need to upload it to your board, then
press the magnifying glass icon in the upper right corner of your Arduino window.
This will open the serial monitor window, which will show you readings based on the
electrical flow
20. Basic conditional program w/ human sensor
int sensorValue;
int MetalPatch = A3;
Int bird = 5;
void setup() {
Serial.begin(9600);
digitalWrite(MetalPatch, HIGH);
pinMode(MetalPatch, INPUT);
pinMode(bird, OUTPUT);
}
void loop() {
sensorValue = analogRead(MetalPatch);
Serial.println(sensorValue);
delay(300);
if (sensorValue>1000) {
digitalWrite(bird, LOW); }
else {
digitalWrite(bird, HIGH); }
}
This program includes a conditional statement, which
is indicated by the if/then statement in the loop.
Basically it’s saying that: if the sensor has a reading
over 1000 (usually indicating an open circuit, no one is
touching) then turn the LED bird off, otherwise (when
someone is touching) turn the LED bird on.
You can create more complex conditionals by adding
more conditions like ranges (see below for example)
if (sensorValue>300) {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
}
else if (sensorValue<=299 && sensorValue>10) {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
Else {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
21. More resources
• Explore the Examples section of Arduino
(under File > Examples)
• Look at Sew Electric.org
• Look around Instructables
23. Tips for E-Textiles Sewing
• Stitch components onto fabric three times for the
best conductivity.
• Remember that this thread is metallic and can
easily cause short circuits if they touch (due to
frayed thread, messy knots, etc.) To help secure
these, you can use regular masking tape or felt
for insulation, or clear nail polish.
• Remember to keep your – and + lines separate
(otherwise, you’ll cause a short circuit)
• Look online or to your friends or classmates for
basic hand sewing techniques (threading needle,
tying knots, basic running stitch)