1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Change value with linear pot

Discussion in 'Arduino' started by Matienzo, Jun 27, 2017.

  1. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    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: Jun 27, 2017
  2. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,451
    Likes:
    189
    Location:
    Lancashire UK
    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.
     
  3. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,099
    Likes:
    562
    Location:
    AZ 86334
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz

    Thanks for the all the help. Here is what I put together (some help from online tutorials)
    Code (text):

    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 (text):

    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: Jun 27, 2017
  6. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    266
    Likes:
    15
    Location:
    Helsinki, Finland
    In integer math 50 / 1023 = 0
    Try temp = (50×res) / 1024 or you could use res as a floating point varable.
     
  7. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    thank you jjw,

    I was just writing that I found my newbie mistake as I saw your post.
     
    Last edited: Jun 27, 2017
  8. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    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 (text):


    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 ");
    }
     
     
  9. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    If it stops after a fixed length of time then what does the temperature select do? :confused:
     
  10. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    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: Jun 27, 2017
  11. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    So it somehow determines how much heat to apply to reach the desired temperature in the desired time?
    How would it do that? :confused:
     
  12. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    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.
     
  13. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    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?
     
  14. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    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.
     
  15. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    But you still haven't said what the time setting will then do?
     
  16. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    It will determine the time a loop with the temperature control runs.
     
  17. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    (This is like pulling teeth :rolleyes:).
    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?
     
  18. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    Hahaha I knew a comment like this was coming. Sorry.

    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.

    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?
     
  19. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,611
    Likes:
    478
    Location:
    L.A., USA Zulu -8
    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.
     
  20. Matienzo

    Matienzo Member

    Joined:
    Jul 6, 2016
    Messages:
    49
    Likes:
    0
    Location:
    Jacinto Arauz
    You are right, I didnt clarify that. Glad is clear now.

    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!
     

Share This Page