Photoresitor Level Detection
Categories:Howtos: Categories:Subcategories
Overview
This tutorial will cover how to use a photoresistor to detect the liquid level of a bottle. This was used in making the Cocktail Maker. This detection told us when we should refill the ingredients in our bottles.
Materials and Requisites
- An LED of any color (Blue seems to have the most accuracy)
- a photo resistor
- an Arduino Uno
- 11 wires
-Breadboard
-a clear bottle containing liquid
-two resistors
-Multimeter
Process
Part 1
1. Connect the photoresistor to a Multimeter.
2. Set up an LED on a bread Board with Arduino as seen below.
3. Fill clear bottle with liquid
4. Turn off lights.
5. Hold LED against one side of the bottle and then hold the photoresistor parallel to the LED light across the bottle underneath the surface of the water.
6. Read the output of the Photoresistor and record.
7. Repeat step 5 and six but make sure the LED and the Photoresistor are above the liquid line.
8. With these numbers plug them into the following equation. V_out= (first reading)/(first reading +R) - (second reading)/(second reading +R)
9. Take the derivative with respect to r.
10. Set derivative equal to 0 and solve for R. This will give you the resistance that you will need for your photoresistor.
Part 2
11. Set up the breadboard to connect the LED to the arduino and the Photoresistor to the Arduino as seen below. the LED and the Photoresistor will be seperate loops.
12. Set up the LED and The Photoresitor to the bottle as previously done in step 5.
Part 3
12. Enter the following code into arduino and load. This code will take an initial reading of the bottle with a full liquid level. Then this will continuously read the level. once the level reaches a predetermined number then it will notify that the bottle is empty.
int lightPen1 = A0; //define a pin for Photo resistor of bottle int full1=analogRead(lightPen1);//sets initial condition for bottle 1 void setup() { Serial.begin(9600); //Begin serial communcation analogReference(INTERNAL); } void loop() { if (analogRead(lightPen1)<.8*full1){ //Tests to see if bottle 1 is empty Serial.println("Bottle 1 Empty"); delay(10); } }
We chose to do the .8 full because that is a drastic enough change from the initial read. This makes sure that it isn't a random toss of the bottle that has one off reading. This would be a significant change.
Authors
Cj Wilson
Weronika Pach
Tom Fare