# translating a potentiometer readings into a range of values

hello
I am sure this is an easy 1
I have a potentiometer that I want to use as a temp controller with a sht15 sensor. I need to translate the 0 - 1023 range of the potentiometer to a range of 50F-100F

so I know 0 is 50F and every 20.48 it would advance a degree
What would be the best method to code this?

thanks

Hi beer lover!

Cheers!

Simple, use the map() function:
int tempF;
int raw;

tempF = map(raw, 0, 1023, 50, 100);

This will only give you increments of full degrees, but you could do:

tempF = map(raw, 0, 1023, 500, 1000);

And then convert tempF to float and divide by 10.0 ? Or something like that.

Lefty

thanks thats exactly what I was looking for

hi. Does this work for unlinear behaviour too?

regards

retrolefty: Simple, use the map() function: int tempF; int raw;

raw = analogRead(pin#); tempF = map(raw, 0, 1023, 50, 100);

This will only give you increments of full degrees, but you could do:

tempF = map(raw, 0, 1023, 500, 1000);

And then convert tempF to float and divide by 10.0 ? Or something like that. :)

Lefty

Does this work for unlinear behaviour too?

No. For non-linear one would need to calculate the mapping for each point or use a look-up table. However I'm more hardware experienced then software, so maybe someone else can give you a more complete and/or correct answer.

Lefty