# Change value with linear pot

Status
Not open for further replies.

#### Matienzo

##### Member
Hi all

The project I'm working on requires me to use two linear 20k potentiometers to change two values, time and temperature.

What I'm doing is running a heating element for a certain period of time. The user selects the time(Range 5-9 min) and temperature (100-150C) and pushes a button, then the program reads the time and temp selected by the user,and starts until it reaches the time selected by the user. The heating element is controlled via PWM using a MOSFET to control the temperature by changing the duty cycle. Temperature input is taken from a thermistor.

This project has several milestones but I'm starting with the potentiometers.

My questions are:

How do I change a value on the program with the potentiometer?
I'm assuming that when the user pushes the button the program picks up a value of resistance and turns it into a desired value (temperature or time)

How do I convert a resistance into a value of time and a value of temperature? I'm guessing I could assign to a certain range of resistance a value of time or temp. I wonder if there is a better way.

I'm not a programmer so please keep it as plain as possible. THANKS A BUNCH!!!!

Matienzo

EDIT: I forgot to mention I'm using an arduino.

Last edited:

#### Les Jones

##### Well-Known Member
Most Helpful Member
Just connect a known voltage between the ends of the potentiometer tracks with the negative of the supply connected to the micro ground. (Just using the Vcc supply is the simplest solution. Then connect the sliders each to an ADC input. Use the reading from the ADC to control your parameters.

Les.

#### MikeMl

##### Well-Known Member
Most Helpful Member
I would connect the wiper of one linear 20KΩ pot to one AD input of an Arduino, and then write a program that makes a delay that is proportional to the ADC reading.

I would connect a temperature sensor to a conditioning circuit that creates a linear voltage proportional to temperature. I would connect that voltage to a second ADC input of the Arduino, and then compare the temperature reading to a voltage determined the setting of a second 20KΩ linear pot. The Arduino program would subtract the temperature reading from the pot setting to come up with an error signal which would in-turn determine the PWM duty cycle used to heat the resistive heater.

The Arduino is a much easier approach than building a circuit that is hardwired.

#### Matienzo

##### Member
Thanks for the all the help. Here is what I put together (some help from online tutorials)
Code:
void setup()
{
Serial.begin(9600);
}

void loop()

{
int Res = analogRead(A0);
int temp = Res * (50 / 1023);   //converts to temp value between 0 and 50

Serial.print("Resistance is ");
Serial.print(Res);
Serial.print("\t");

Serial.print("Temperature is ");
Serial.println(temp);
}

However, for some reason the output for temperature is always 0. Any idea why?

Code:
Resistance is 616    Temperature is 0
Resistance is 618    Temperature is 0
Resistance is 613    Temperature is 0
Resistance is 620    Temperature is 0
Resistance is 622    Temperature is 0
Resistance is 615    Temperature is 0
Resistance is 618    Temperature is 0
Resistance is 616    Temperature is 0

Last edited:

#### jjw

##### Member
In integer math 50 / 1023 = 0
Try temp = (50×res) / 1024 or you could use res as a floating point varable.

#### Matienzo

##### Member
thank you jjw,

I was just writing that I found my newbie mistake as I saw your post.

Last edited:

#### Matienzo

##### Member
Here is the final working code. I wanted the temperature range to be between 100 and 150c and the time between 5 and 10 min.
Thank you for the guidance!

Code:
void setup()
{
Serial.begin(9600);
}

void loop()
{
int Res1 = analogRead(A0);
float temp1 = 100 + Res1 * (50.0 / 1023.0);  //gives a range between 100 and 150 C

int Res2 = analogRead(A1);
float Time = 3600000 * 5 + (Res2 * ((3600000 * 5)/1024)) ; //gives a range between 5 and 10 min

// Serial.print("Resistance 1 = ");
// Serial.print(Res1);
// Serial.print("\t");

// Serial.print("Resistance 2 = ");
// Serial.print(Res2);
// Serial.print("\t");

Serial.print("Temperature = ");
Serial.print(temp1);
Serial.print(" C\t");

Serial.print("Time = ");
Serial.print(Time/3600000);
Serial.println(" min ");
}

#### crutschow

##### Well-Known Member
Most Helpful Member
The user selects the time(Range 5-9 min) and temperature (100-150C) and pushes a button, then the program reads the time and temp selected by the user,and starts until it reaches the time selected by the user.
If it stops after a fixed length of time then what does the temperature select do?

#### Matienzo

##### Member
Hi crutschow,

After the time is over everything shuts off. If user wants same settings, it simply pushes the button again and it goes through the same cycle. If the user wants the same time but different temperature then it changes the temperature.

Is that what you asked?

BTW that is obviously sill not in the code

Last edited:

#### crutschow

##### Well-Known Member
Most Helpful Member
After the time is over everything shuts off. If user wants same settings, it simply pushes the button again and it goes through the same cycle. If the user wants the same time but different temperature then it changes the temperature.
So it somehow determines how much heat to apply to reach the desired temperature in the desired time?
How would it do that?

#### Matienzo

##### Member
The temperature selects a target. Once the user pushes the button the program adjusts the duty cycle of a mosfet until it reaches the target temperature. Then it maintains a duty cycle that keeps the temperature within a small range of the target temperature. I honestly don't know yet how to code it, but some guys here coincide on this being the best way to go about it. No doubts they articulated it much better than I just did. I'll post the link to that thread in a bit.

#### crutschow

##### Well-Known Member
Most Helpful Member
The temperature selects a target. Once the user pushes the button the program adjusts the duty cycle of a mosfet until it reaches the target temperature. Then it maintains a duty cycle that keeps the temperature within a small range of the target temperature.
That's all fine.
But were does setting the time come into play?
Does it have to reach the set temperature within the set time?
If so, how will that be done?

#### Matienzo

##### Member
oh I see.
I would like the heating element to reach the desired temperature quickly and then remain close to the target temperature until it runs out of time. I don't know how to code it yet.

#### crutschow

##### Well-Known Member
Most Helpful Member
oh I see.
I would like the heating element to reach the desired temperature quickly and then remain close to the target temperature until it runs out of time. I don't know how to code it yet.
But you still haven't said what the time setting will then do?

#### Matienzo

##### Member
It will determine the time a loop with the temperature control runs.

#### crutschow

##### Well-Known Member
Most Helpful Member
It will determine the time a loop with the temperature control runs.
(This is like pulling teeth ).
So what will happen when you reach the end of the time?
Is this time always longer then it takes to reach the desired temperature?

#### Matienzo

##### Member
(This is like pulling teeth ).

Hahaha I knew a comment like this was coming. Sorry.

So what will happen when you reach the end of the time?

The heating elements shut off and cool down on their own. I know I answered this before but I'm not quite sure what else is there that you are trying to find out.

Is this time always longer then it takes to reach the desired temperature?

Always, the heating element reach its temperature probably in 30 sec. The minimum amount of time the user can choose is 5 minutes.

Am I missing something?

#### crutschow

##### Well-Known Member
Most Helpful Member
Am I missing something?
No.
That was what I was missing.
I was wondering what would happen if the timer had a shorter period then it takes to warm up, but that obviously can't occur.
Sorry for the digression.

So do you still have questions about doing the design?
I can't help much with the code, but I can with any circuit design you may need.

#### Matienzo

##### Member
You are right, I didnt clarify that. Glad is clear now.

I can't help much with the code, but I can with any circuit design you may need.

The arduino makes it super easy to wire things up and most of my connections have voltage through it and go straight to a pin. The next steps are the thermistors, button and MOSFET being the last one the hardest since I've never done it (the code I mean) Thank you for your offer to help!

Status
Not open for further replies.

Replies
1
Views
1K
Replies
15
Views
3K
Replies
6
Views
3K
Replies
2
Views
3K
Replies
4
Views
2K