Description
In this week’s lab, we explored two other analog sensors in addition to the pot (explored last lab). The first sensor is a photocell, which measures light brightness. The second one is a force sensitive resistor ("FSR"), which measures force/pressure. All three analog sensors that we have studied thus far (pot, photocell, and FSR) convert some physical action into an electrical characteristic-namely, resistance.
During this lab we were introduced to "Processing", a programming language used to create interesting UIs that is very graphic-intesive. Arduino programming is based heavily on Processing, so the language and interface are very similar.
For the first part of the lab, we built our typical LED circuit to which we integrated a photocell. Using sketches from previous lab exercises and modifying them slightly, we controlled the LED's blink rate with the input from the photocell. An analogous exercise was done with an FSR.
For the programming portion of the homework, I used Processing to create a cloloured screen with different values of hues, saturation, and brightness. The brightness value is set at 0 at the beginning, so the screen is black. I then used the FSR connected to my circuit and to the Arduino to control the brightness value. The higher the force exerted on the FSR, the higher the brightness level displayed on the coloured screen.
For the mechanical portion of the homework, I made a bubble-wrap sleeve for my FSR in order to distribute the force applied to it, mainly when squeezing it. This mimics the action performed on one of those stress-release balls. The stronger the sleeve is squeezed, the brighter the colours appear on the screen, and vice versa.
Components
1- Arduino Uno Microcontroller
1- Breadboard
1- 10KΩ Resistor
1- USB Cable
1- Apple Laptop Computer (Mac OSX)
1- Force Sensitive Resistor (FSR)
1- Bubble wrap strand
Arduino Code
/*
Sofia Solar Cafaggi
Lab 4
*/
int squeeze=0;
int val;
void setup() {
Serial.begin(9600);
pinMode(squeeze,INPUT);
}
void loop() {
val = analogRead(squeeze);
Serial.println(val);
delay(60);
}
Processing Code
/*
Spfia Solar Cafaggi
Lab 4
Force Sensitive Resistor
This program uses the pressure sensor's input to determine
the brightness of a coloured screen (no pressure shows a
black screen, increasing pressure increases the brightness
of the colours)
*/
import processing.serial.*;
Serial port;
float brightness = 0;
void setup () {
size(400,400);
noFill();
port = new Serial(this, "/dev/tty.usbmodem411", 9600);
port.bufferUntil('\n');
}
void draw()
{
noStroke();
colorMode(HSB, 400);
for (int i = 0; i < 400; i++)
{
for (int j = 0; j < 400; j++)
{
stroke(i, j, brightness);
point(i, j);
}
}
}
void serialEvent(Serial port) {
brightness = float(port.readStringUntil('\n'));
println(brightness);
}
- Login to post comments