Go Down

### Topic: translating a potentiometer readings into a range of values (Read 2024 times)previous topic - next topic

#### beverageexpert

##### Jan 28, 2011, 07:15 pm
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

#### mjb

#1
##### Jan 28, 2011, 07:48 pm
Hi beer lover!

Try this: http://www.arduino.cc/en/Reference/Map

Cheers!

#### retrolefty

#2
##### Jan 28, 2011, 07:49 pmLast Edit: Jan 28, 2011, 07:54 pm by retrolefty Reason: 1
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

#### beverageexpert

#3
##### Jan 29, 2011, 12:24 am
thanks thats exactly what I was looking for

#### janeik

#4
##### Feb 02, 2011, 11:06 pm
hi.
Does this work for unlinear behaviour too?

regards

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

#### retrolefty

#5
##### Feb 03, 2011, 12:47 am
Quote
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

Go Up