Arduino Beer Glass Level

Aus DL8RDS Wiki
Version vom 11. August 2022, 16:42 Uhr von Dl8rds (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

1 Scope

The Octoberfest is just ahead! So I took the chance to understand my MILONE liquids measurement eTape fluid level sensor.

There is that saying whether the glass is half full or half empty. Let's find out.

2 Circuit

2022-08-11-eTape.png

3 Code

This is just a modification of the AnalogSensorValue sketch from the examples section of the Arduino GUI.

The most interesting part is the calibration.

The MILONE sensor has a resistance of 60 Ohm when fully submerged to the zero line. It has 385 Ohm when the glass is empty.

So with a fixed value resistor of 330 Ohm in the voltage divider the voltage divider will be

  • 60/330 Ohm and produce 4,230V when the glass is full
  • 385/330 Ohm and produce 2,300V when the glass is empty

Given that the Arduino ADC has 1024 steps (10 bit) and adds one step every 0,005 Volts, the voltages will produce

  • 866 steps for 4,230V
  • 453 steps for 2,230V

This value will now change te blinking delay. The fuller the glass, the slower the LED will blink.

But we want a serial readout in percents. So we need to translate this into percentages with a formula

y=ax + b

where

b=453 , pull it to the bottom line

The a value is the slope, that will start at empty state with 0 and at full state with an offset of 400. So the value of the multiplier must be 400 resulting in

y=400*x + 453

We now create the inverse function:

x=(y-453)/400

and if we want percentages it will be

p=100*(y-453)/400

So that's the formula you see implemented in the code.

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(100*(sensorValue-453)/400,DEC);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}


4 Images

2022-08-11-eTape01.jpg 2022-08-11-eTape02.jpg 2022-08-11-eTape03.jpg

5 Files