The Clif Bar Detector
Sunday, June 1, 2008
For our find and fix assignment I had the idea of making something that would allow someone walking through the floor to know if and where there is food being sold out of any of the lockers. Since, typically, it's energy bars or other packaged food that's available, it was relatively easy to calibrate an FSR to show whether or not there is food in the locker - as well as how many items are inside (as long as the items are the same).
The biggest challenge that I faced was setting up my FSR - even though it's entirely straightforward, and there are only two leads off the sensor (which are not polar).. I couldn't get the readings to be in any way accurate or stable. It took me the good part of the day to realize that, in fact, nothing was being read (during the course of that day I tried every resistor I could get my hands on). With Chris Cerrito's help via phone I realized that I wasn't powering the sensor properly and that it hadn't been functioning at all.
After that was all sorted out and everything was running, I measure 1, 2, 3 ad 4 Clif Bars to see how I could use the FSR as a scale of sorts. In the end, though it isn't entirely accurate, the setup functions generally and measures whether there are any bars in the locker and if so, how many. Among the comments I received in class was a suggestion to have an LED lit the entire time to show that the system is functioning, and making it battery powered. In class Rob showed us how to check using continuity readings off the multimeter to see which wire is power and which is ground on the battery adapter.

Here's the Arduino code:
++++++++++++++++++++++++++
int finderPin = 1; // Analog input from rangefinder
int finderValue = 0; // value read from the finder
int redLedPin = 2;
int yellowLedPin = 4;
int blueLedPin = 5;
int whiteLedPin = 6;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(finderPin, INPUT);
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
pinMode(whiteLedPin, OUTPUT);
}
void loop() {
// read the rangefinder value
finderValue = analogRead(finderPin)/4;
// new line
delay(500); // Wait half a second
// print finder value back to the debugger pane
Serial.println(finderValue);
//no bars
if(finderValue <= 5) {
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(whiteLedPin, LOW);
}
//one bar
if (finderValue > 5 && finderValue <= 18) {
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(whiteLedPin, LOW);
}
//two bars
if (finderValue > 18 && finderValue < 37) {
digitalWrite(yellowLedPin, HIGH);
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(whiteLedPin, LOW);
}
//three bars
if (finderValue >= 38 && finderValue <=60) {
digitalWrite(blueLedPin, HIGH);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(whiteLedPin, LOW);
}
//four bars
if (finderValue >= 61 && finderValue <=85) {
digitalWrite(yellowLedPin, LOW);
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(whiteLedPin, HIGH);
}
}
/*
4 bars - 61-85
3 bars - 38-60
2 bars - 18-37 (30 ideal)
1 bars - 9-18 (11 ideal)
*/
posted by Amanda @ 10:32 PM,