HANDS ON THE ELECTRONicS
One of my biggest dreams yet still quite a challenge in the realm of smart textiles is to master the electronics like a boss. I am a knowledgeable beginner, and I have been one for a while now. This week's challenge was to step up my game in this field, by relying minimally on expert help from the techies in the Fablab. The idea was to be able to prototype the basic module for my interaction, to see if it worked and if it made sense beyond the concept.
INSPIRATION
OBJECTIVES & PLAN
This week I will focus on the ELECTRONICS of my IO<3 garment. I need to work step by step in order to create a circuit that is simple with an elegant interaction.
I decided to break down the process in the following bite sizes:
- CREATING 1 MODULE
- BUTTON + VIBRATION MOTOR
- BUTTON + VIBRATION MOTOR + LED
- PRESSURE SENSOR + VIBRATION MOTOR + LED
- PRESSURE SENSOR + VIBRATION MOTOR + 3 LEDs
- ADDING A 2nd MODULE
- 2 PRESSURE SENSORS + VIBRATION MOTORS + LEDS
- ADDING A 3rd MODULE
- 3 PRESSURE SENSORS + VIBRATION MOTORS + LEDS
BUTTON + VIBRATION
- Lilypad Button
- Lilypad Vibration Board
- LED
- Lilypad LED
- Arduino UNO
- Resistors
PROCEDURE
I initially used the code from Week 5, E-textiles and Wearables I, when I made the Mexican Calavera with LED eyes turning on via soft pressure sensor.
I still had the same problem I had with the Calavera: when the pressure sensor was not pressed the LED is ON, when the I pressed the pressure sensor the LED turned OFF. Since the code is not a digital input/output but an analog, I can't just reverse the HIGH/LOW in the Arduino. I need to learn more about the map() function.
So I decided to try and make the vibration motor run first and then reverse engineer everything else, the pressure sensor and the LED.
I used this tutorial to get the motor running.
I discovered and once and for all will remember the following:
Diode and LED Polarity. Diodes only allow current to flow in one direction, and they're always polarized. A diode has two terminals. The positive side is called the anode, and the negative one is called the cathode.
The definition for diodes comes from here.
The setup required by the tutorial was a bit too laborious and ended up not being necessary. I just used a simple Pushbutton tutorial , changing the LED together with the vibration motor. It worked.
RESULTS & REFLECTIONS
The circuit worked as follows: when I press the pressure sensor, the motor starts running and the LED turns on. When I stop pressing the pressure sensor, the motor and the LED turn off. That's exactly what I needed to achieve in this first step, before making the behavior of the LED different from that of the motor.
PROCEDURE
I added an LED to the circuit I created above. The idea was to ensure the following interaction:
If the button is pressed, the motor vibrates AND the LED fades in an out.
The goal is to soothe the wearer with the massage and with a calming visual stimulus, resembling a slow breathing pattern.
I initially added the LEDPin as a Digital Output, using the Blink Example in Arduino. Once I mastered that, I used the Fade Example in Arduino. This example is slightly trickier because it already contains an if statement to increase/decrease the brightness level. I have an if statement in the void loop () function already because I need to create the condition "if the button is pressed, the motor vibrates".
So I understood how to nest if statements from here. This is the code:
int motorPin = 9; // choose the pin for the LED int inPin = 7; // choose the input pin (for a pushbutton) int LEDPin = 3; // choose the input pin (for a pushbutton) int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by int val = 0; // variable for reading the pin status void setup() { pinMode(motorPin, OUTPUT); // declare motor as output pinMode(LEDPin, OUTPUT); // declare LED as output pinMode(inPin, INPUT); // declare pushbutton as input } void loop(){ val = digitalRead(inPin); // read input value analogWrite(LEDPin, brightness); brightness = brightness + fadeAmount; if (val == HIGH) { // check if the input is HIGH (button released) digitalWrite(motorPin, LOW); // turn MOTOR OFF { brightness = 0; } else { digitalWrite(motorPin, HIGH); // turn MOTOR ON if(brightness <= 0 || brightness >= 255){ fadeAmount = -fadeAmount; } delay(50); } }
RESULTS & REFLECTIONS
It worked! The LED faded in and out as I pressed the button, while the motor turned on when I pressed the button, while it turned off when I let it go. I was very pleased and felt like a true PRO.
PROCEDURE
In this case I used the Velostat pressure sensor I made in Sprint 1/Week 1 and substituted it to the Lilypad button. Not so easy though.. Now the trick is to change the Digital Input (button) with the Analog Input (pressure sensor). The pressure sensor senses a change in resistance and it needs a bit more complex code to get this done. It also needs the Pin on the Arduino to be changed to A0. I used the code from Week 5 and added the pressure sensor + Serial Monitor to check the value I needed to use to make the pressure sensor trigger the Output.
Here is the code I used:
int motorPin = 9; // choose the pin for the LED int sensorPin = A0; // choose the input pin ffor the PRESSURE SENSOR int LEDPin = 3; // choose the input pin (for a pushbutton) int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by int val = 0; // variable for reading the pin status int sensorValue = 0; // variable to store the value of the sensor void setup() { Serial.begin(9600); pinMode(motorPin, OUTPUT); // declare motor as output pinMode(LEDPin, OUTPUT); // declare LED as output pinMode(sensorPin, INPUT); // declare pushbutton as input } void loop(){ Serial.println(sensorValue); sensorValue = analogRead(sensorPin); // read input value analogWrite(LEDPin, brightness); // fade LED brightness = brightness + fadeAmount; // brightness amount fading if (sensorValue > 850) { // check if the input is HIGH (button released) digitalWrite(motorPin, LOW); // turn MOTOR OFF { brightness = 0; } else { digitalWrite(motorPin, HIGH); // turn MOTOR ON if(brightness <= 0 || brightness >= 255){ fadeAmount = -fadeAmount; } delay(50); } }
RESULTS & REFLECTIONS
The maximum value for the pressure sensor when not pressed was 1023. When I pressed it, the changes would oscillate around 750 and 840. So I decided to go for a threshold of 850, above which the Motor and LED would turn off. The whole things works quite well!!
ADDING MORE LEDS IN PARALLEL
INGREDIENTS
- Alligator jumpers
- 2 Lilypad LEDS
- Arduino UNO
- 1 Capacitor .1 uF
- 1 Transistor 2N2222A
- 1 Resistor 33Ohm
- 1 Resistor 1.0 kOhm
- Arduino IDE
PROCEDURE
At this point, the only thing I had to do to light up multiple LEDs while pressing the pressure sensor was to add 2 LEDs and connect them to the 2N2222A transistor in series. The code is the same as before, only with with 1 Pin for all 3.
RESULTS & REFLECTIONS
The circuit worked very well and 3 LEDs can light up through 1 Pin, which is great. The first press + vibration massage + LED module is ready.
USER TEST
During the creation of the first interactive module, I performed a few user tests in order to assess the COMFORT and USABILITY of the PRESSURE SENSOR & VIBRATION MOTOR.
- For the Pressure Sensor, I was identifying the amount of pressure needed to activate the LEDs, and if that would hinder the user comfort.
- For the Vibration motor, I evaluated if the motor provided a pleasant sensation that acted like a massage when pressed.
The results were positive: the pressure sensor had a good resistance variation, which allows the user to press gently but not too hard to get the motor + LEDs to turn on, and the vibration motor, when pressed on the user's skin, gives a very pleasant sensation on the skin.