Go Down

Topic: translating a potentiometer readings into a range of values (Read 1 time) previous topic - next topic

beer lover

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

Hi beer lover!

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

Cheers!

retrolefty

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




beer lover


janeik

hi.
Does this work for unlinear behaviour too?

regards


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





retrolefty

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy