Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
PART I. Processing
Components used:
1 Photocell
1 10K resistor
1 LED
1 220K resistor
Description
The first part of the assignment asks for a visualization of a given input through the use of Processing. I decided to use a photocell to determine the brightness of the LED.
I connected this to a Processing program that would display weather icons based on the amount of light the photocell would detect.
Maximum light would mean it is sunny:
While mediocre lighting would mean cloudy:
No light at all would mean a cloudy night.
Arduino Code:
The Arduino code used was the 1a_SinglePotControlsBrightness.txt code used in class.
Processing Code:
import processing.serial.*;
String portname = "/dev/tty.usbserial-A9007M5u"; // or "COM5"
Serial port;
String buf="";
int lf = 10; // ASCII linefeed == 10
String currentPic;
void setup() {
size(300,300);
frameRate(10);
smooth();
background(255);
noStroke();
port = new Serial(this, portname, 9600);
currentPic = "sunny.png";
}
void draw() {
}
void loadPicture(String filename)
{
PImage weather;
weather = loadImage(filename);
background(255);
image(weather, 0, 0, width, height);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
if (val >= 0 && val < 100 && currentPic != "cloudy_night.png")
{
loadPicture("cloudy_night.png");
currentPic = "cloudy_night.png";
}
else if (val >=100 && val < 200 && currentPic != "clear_night.png")
{
loadPicture("clear_night.png");
currentPic = "clear_night.png";
}
else if (val >= 200 && val <400 && currentPic != "no_sun.png")
{
loadPicture("no_sun.png");
currentPic = "no_sun.png";
}
else if (val >=400 && val < 600 && currentPic != "heavy_cloud.png")
{
loadPicture("heavy_cloud.png");
currentPic = "heavy_cloud.png";
}
else if (val >= 600 && val < 750 && currentPic != "bit_cloudy.png")
{
loadPicture("bit_cloudy.png");
currentPic = "bit_cloudy.png";
}
else if (val >= 750 && val < 850 && currentPic != "light_clouds.png")
{
loadPicture("light_clouds.png");
currentPic = "light_clouds.png";
}
else if (val >= 850 && val <=1000 && currentPic != "sunny.png")
{
loadPicture("sunny.png");
currentPic = "sunny.png";
}
else loadPicture(currentPic);
buf = "";
}
}
PART II. Mechanical
Components Used:
1 Force Sensitive Resistor
1 10K Resistor
1 LED
1 220K Resistor
Candle bottom
Cardboard, cut in a circle
Laundry Basket
Clothes
Description:
I used the metal bottom normally used in candles (this one with a radius that fit the most sensitive pressure point of the FSR) as the object that would focus the force of a larger area (the cardboard) onto the FSR. I attached this metal bottom to the center of a cardboard box:
I taped the FSR onto it:
This would serve as the base for my laundry basket:
The LED lights up when the clothes reach a certain weight as detected by the FSR:
A program in Processing then displays the laundry icon to tell the user that it is time to do laundry:
If the laundry basket is empty or hasn't reached its threshold yet, the LED does not light. The processing program also shows a Closet icon to let the user know that he still has enough clothes in the closet.
Arduino Code:
int potPin = 0; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
val = val - 420; //offsets the weight of the laundry basket
Serial.println(val);
if (val > 250)
digitalWrite(ledPin, HIGH); // turn the ledPin on
else
digitalWrite(ledPin, LOW); // turn the ledPin off
}
Processing Code:
import processing.serial.*;
String portname = "/dev/tty.usbserial-A9007M5u";
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
String currentPic;
void setup() {
size(300,300);
frameRate(10);
smooth();
background(255);
noStroke();
port = new Serial(this, portname, 9600);
currentPic = "closet.png";
}
void draw() {
}
void loadPicture(String filename)
{
PImage statusLaundry;
statusLaundry = loadImage(filename);
background(255);
image(statusLaundry, 0, 0, width, height);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
if (val < 250 && currentPic != "closet.png")
{
loadPicture("closet.png");
currentPic = "closet.png";
}
else if (val > 250 && currentPic != "laundry.png")
{
loadPicture("laundry.png");
currentPic = "laundry.png";
}
buf = "";
}
}