Description:
In this assignment, I created a coaster out of leftover beer box that uses a photocell to measure how much liquid is in the glass on top of it and then blinks a light at increasing speed as you get down to the bottom of the glass. I set the coding using a fully lit room, so that when certain photocell thresholds are met, the blinking speeds up. Obviously, the user of the glass typically will know when it is getting low (unless, say, they've had WAAY too much beer, in which case helping them realize they need a refill is a bad thing! :) ) so the practical application here might be more along the lines of a waitperson being alerted that a patron's drink is getting low.
Turns out there are a number of problems with this approach:
- different light conditions throw off the photocell thresholds
- non-clear glasses obscure the light coming through the liquid
- water doesn't work because it doesn't filter light much
An alternative might be to try weight/force, but then you have the issue of how to discount the weight of the cup. In any case, under perfect conditions, it works and makes for a kind of fun drinking effect.
Parts used:
(1) - Breadboard
(1) - Arduino Uno Board
(1) - Photocell
(1) - Green LED
(2) - 220 Resistors
(1) - Cardboard Coaster
Arduino Code:
/*
* Modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
*
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int potPin = 2; // select the input pin for the photocell
int ledPin = 4; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
//rules for interpreting amount of light into photocell
if (val > 700) {
val = 50;}
else if (700 > val && val > 500) {
val = 100;}
else if (500 > val && val > 400) {
val = 250;}
else {
val = 1;}
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
Serial.begin(9600);
//Serial.print(val);
}
- Login to post comments