float and rotary encoder arduino project

I would like to measure a liquid level using an arduino and a rotary encoder on a wheel knowing the diameter of the wheel is it possible to use the arduino to decipher and count the encoder to give me a count in cm as the pully wheel turns I would also like an led to light with the encoder at 0cm so I can use this in different tanks and vary my 0 datum. because the turning force is done by a float I would like as little drag on the line as possible maybe some one could advise a optical encoder that I could use? cheers

I would like to measure a liquid level using an arduino and a rotary encoder …

is it possible

Yes.

@supermotolew;
A bit more info, perhaps, will allow some of our members an idea of your needs vs wants.

the turning force

I assume a cylinder tube filled with a liquid, or is it a tank, or a u-tube to a tank? Is this a new need or are you trying to replicate an older system? How accurate must your readings be… A % of total volume (?) or a specific quantity: ounce / pint / quart / gallor or centiliters / cubic centimeters / milliliters / liters ?
(Yes, I read you were converting linear displacement to
Is the liquid at a standard temperature. Dies this matter?

Do you need logging over time measurements.
Is the liquid water? If not, what liquid?

Details are important - not that you are expected to write a novel but to help understand your project. You go from “possible?” to asking about a recommendation on optical encoder… That is a far leap without more info.

Ray

thanks Ray
hopefully some more info now I have built a working model.
I have a large cylinder filled with liquid I have a pully at the top on a sparkfun encoder looped over the pully is a line with a float at one end and weight at another as the level goes up and down I get a number in a serial window increase and decrease .
knowing the circumference of the pulley is 20cm and 1 revolution of this encoder currently gives me a value of about 49
I know that every value of 49 is 20 cm level change
I guess my question is how can I make the sketch read in CM with this taken into account.
the current sketch is as follows .

/* Rotary encoder read example */
#define ENC_A 14
#define ENC_B 15
#define ENC_PORT PINC

void setup()
{
/* Setup encoder pins as inputs */
pinMode(ENC_A, INPUT);
digitalWrite(ENC_A, HIGH);
pinMode(ENC_B, INPUT);
digitalWrite(ENC_B, HIGH);
Serial.begin (115200);
Serial.println(“Start”);
}

void loop()
{
static uint16_t counter = 0; //this variable will be changed by encoder input
int8_t tmpdata;
/**/
tmpdata = read_encoder();
if( tmpdata ) {
Serial.print("Counter value: ");
Serial.println(counter, DEC);
counter += tmpdata;
}
}

/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
static int8_t enc_states = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_AB = 0;
/**/
old_AB <<= 2; //remember previous state
old_AB |= ( ENC_PORT & 0x03 ); //add current state
return ( enc_states[( old_AB & 0x0f )]);
}

Maybe this will help with the encoder code: http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino

you have a finite ratio of 20/49 = 0.4081633, so determine the volume displacement for 1/2 rotation, 10cM, and then divide the volume by 10 to get the unit volume per 1cM. If the encoder increases by +1 count, then you calculate the volume increase as 0.4081633 * unit volume per 1cM movement. If the encoder shows a decrease, then the converse.

Ray

You can also look at some posts in my blog about rotary encoders. In the past I was working on making your own encoder (hardware and software).

Simple rotary encoder: http://heliosoph.mit-links.info/make-your-own-rotary-encoder/

Quadrature encoder: http://heliosoph.mit-links.info/make-your-own-quadrature-rotary-encoder/

This is a very basic example for reading an encoder: http://heliosoph.mit-links.info/rotary-encoder-software-for-arduino/

Elektrix

supermotolew: knowing the circumference of the pulley is 20cm and 1 revolution of this encoder currently gives me a value of about 49 I know that every value of 49 is 20 cm level change

For "about 49" read "exactly 48", if its the Sparkfun wheel encoder, quadrature encoders produce a multiple of 4 steps/rotation if every transition is counted.

thanks everyone for the extra info im learning fast ! but still struggling with putting the formula in my sketch to read cm on serial monitor. could any one insert the correct formula for a spark fun 48 with 20cm pulley to read cm ? I would really like to get a reading model to test accuracy over xmas. thanks again all for your guidance and patience !

Are you using the Pololu wheel encoder: https://www.sparkfun.com/products/9208

Not every Sparkfun sensor has an Arduino example, but most do...

I so, https://www.sparkfun.com/datasheets/Robotics/pololu_avr_library.pdf:

This document covers the C/C++ version of the library, but it may also be used with Arduino[http://www.arduino.cc]: a popular, beginner-friendly programming environment for the mega168, using simplified C++ code. See our guide to using Arduino with Orangutan controllers[http://www.pololu.com/docs/0J17] for more information.

but still struggling with putting the formula in my sketch to read cm on serial monitor.

Are you getting the proper count (48) for a full 360 degree spin of the encoder?

Ray

this is the encoder im currently using http://proto-pic.co.uk/rotary-encoder/ I would prefer an optical one in the final model with less drag but for now this will do.

ill plug the arduino in again but from memory I think it starts on 1 then every click is 4 making one click forwards 5 then 9 then 13 but I will re test its been a little while .

Perhaps you'd be better with: https://www.sparkfun.com/products/9208, those mechanical switch encoders are rough and ready to say the least - meant only for control knobs, lots of contact bounce.

ill plug the arduino in again but from memory I think it starts on 1 then every click is 4 making one click forwards 5 then 9 then 13

The PDE code downloadable from the Sparkfun link has the function code to indicate Forward/Reverse... In your case that will represent Addition/Subtraction. You are going to have to incorporate some state variables to indicate the Forward/Reverse direction so that you continue to increment or decrement when the encoder is turned passed 360 degrees.

Ray

Optical encoder ++1