Pages: [1]   Go Down
Author Topic: translating a potentiometer readings into a range of values  (Read 895 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 11
m++;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi beer lover!

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

Cheers!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16459
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley

Lefty



« Last Edit: January 28, 2011, 01:54:14 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks thats exactly what I was looking for
Logged

Norway
Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
Does it work?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley

Lefty




Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16459
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: