Controlling a Potentiometer using Arduino 2560

Hello out there :)

i'm doing a project where i check the temperature of an RF room (and keep it within temp limits) the using the potentiometer on the arduino 2560 board. basically, the voltage being read is the degree change in temperature (in celcius). the potentiometer is a regular 3 pin 10k one. i need a sample code for this. i checked in the arduino library on the software i have but its not the one i want. help pls?

thank you :)

I am unable to understand anything you say. What temperature sensor are you using? With what are you going to control the temperature? Why is a potentiometer involved?

Yes, how would doing an analogRead() on a potentiometer tell you the room temperature?

I think they want to check the temp (presumably, w/ temp sensor?) then use the pot to tell Arduino to tell the chiller by how many Celsius degrees to change the temp.

Does "RF" room mean....."Radio Freq. Room"? ..."Refrigeration Room"? Dunno?

So... you want to use Arduino as a thermostat?

One could map the pot voltage to a certain temperature range. However, if you want to specify a particular delta, buttons (or encoder) may be better choice.

so i didn't make myself clear. sorry...

i'm not using any temperature sensor. i'm using a potentiometer to measure its resolution. for example, if the value for 25.30V is say 100 then changing the voltage to 25.31V, it would correspond to 101. So i'd having to write a program for that. now the 3.30V is the same as the temperature i'm measuring. if the temperature of the room is 25 degrees Celcius, the arduino would read 25V. this is what i would need help with. how do i write a program that corresponds a change in voltage to a bit change in binary value?

I hope its a little more clear now...

You can have a voltage from 0V to 5V, the arduino can analogRead() that and return a number from 0 to 1023, each bit representing 0.00488V. (or, 5/1023) After that, you can do some math on the 0-1023 number and have it represent whatever you would like. Want 511 to be presented as 2.5V? Do a calculation using data type float and show that result. Maybe: int currentLevel = analogRead (A0); float outputVoltage = 0.00488 * currentLevel;

Where is the voltage you are measuring from? Is it 0-5V, or something broader?

1ChicagoDave: I think they want to check the temp (presumably, w/ temp sensor?) then use the pot to tell Arduino to tell the chiller by how many Celsius degrees to change the temp.

Does "RF" room mean....."Radio Freq. Room"? ..."Refrigeration Room"? Dunno?

So... you want to use Arduino as a thermostat?

One could map the pot voltage to a certain temperature range. However, if you want to specify a particular delta, buttons (or encoder) may be better choice.

Yes, RF room is a radio frequency room :) and Yes, i want to use arduino as a thermostat. how do you map the potentiometer's voltage to a certain temperature range?

CrossRoads: You can have a voltage from 0V to 5V, the arduino can analogRead() that and return a number from 0 to 1023, each bit representing 0.00488V. (or, 5/1023) After that, you can do some math on the 0-1023 number and have it represent whatever you would like. Want 511 to be presented as 2.5V? Do a calculation using data type float and show that result. Maybe: int currentLevel = analogRead (A0); float outputVoltage = 0.00488 * currentLevel;

Where is the voltage you are measuring from? Is it 0-5V, or something broader?

yeah the voltage range is from 23V-27V. is there any preloaded program on the arduino software that helps me with this?

Sravani:

CrossRoads: You can have a voltage from 0V to 5V, the arduino can analogRead() that and return a number from 0 to 1023, each bit representing 0.00488V. (or, 5/1023) After that, you can do some math on the 0-1023 number and have it represent whatever you would like. Want 511 to be presented as 2.5V? Do a calculation using data type float and show that result. Maybe: int currentLevel = analogRead (A0); float outputVoltage = 0.00488 * currentLevel;

Where is the voltage you are measuring from? Is it 0-5V, or something broader?

yeah the voltage range is from 23V-27V. is there any preloaded program on the arduino software that helps me with this?

Arduino without external hardware can read only from 0-5v

right. it reads only for 0-5V. can i use this http://www.arduino.cc/en/Tutorial/Potentiometer program? would it suffice for my requirements? i'm having a bit of a tough time putting everything together...also, how do i set a reference voltage? do i use the BOD or ADC itself? :drooling_face: :roll_eyes:

I don’t think we’re quite in sync yet.

You have to bring the 23V-27V down to 0-5V range so you can measure it.
One way would be to use a voltage divider.
27V
|
<

R1
<

|
|-- to analog pin
|
<

R2
<

|
Gnd

Vout = Vin * R2/(R1 +R2)
With R2 of 2K, R1 = 8.8K
Vout max = 5V (27V in)
However Vout min = 4.26V (23V in)
which is a range from ~873 to ~1023. ~150 difference from low to high.
Can you live with that?
Otherwise, next step is to bring in an op amp, subtract 4.26V from the voltage divider output, and then add some gain (about 6.5) to bring the resulting 0 to 0.74 output up to 0-5V level so you can make a full 0-1023 reading.

I had some pots connected to my arduino and had the values displaying to the serial monitor. The whole time my room temperature did not change, so you may be missing something in your project.

zoomkat: I had some pots connected to my arduino and had the values displaying to the serial monitor. The whole time my room temperature did not change, so you may be missing something in your project.

Finally some one did it. LOL :D

It’s easy enough to use analogRead() to read the voltage at an analog input pin and then perform some calculations to convert that to a corresponding temperature. However, none of this does anything to control the temperature or ‘control’ (?) a potentiometer, which you’ve mentioned in various places, and in effect what you’d have would be a thermometer (temperature display) not thermostat (temperature control).

PeterH: It's easy enough to use analogRead() to read the voltage at an analog input pin and then perform some calculations to convert that to a corresponding temperature. However, none of this does anything to control the temperature or 'control' (?) a potentiometer, which you've mentioned in various places, and in effect what you'd have would be a thermometer (temperature display) not thermostat (temperature control).

what calculations would i have to do? are you referring to the calculation for resolution of ADC?

how would i read a voltage of 2.50 volts using arduino? i guess if i get this, i would be able to figure out how to write the rest of the program. but this question seems unanswered...are there any preloaded programs on the arduino software that will help me?

Sravani: how would i read a voltage of 2.50 volts using arduino? i guess if i get this, i would be able to figure out how to write the rest of the program. but this question seems unanswered...are there any preloaded programs on the arduino software that will help me?

You would connect the voltage to an analog input pin and call analogRead() in your sketch. (Make sure the thing you are connecting will never apply a voltage less than 0V or greater than 5V or you may damage the Arduino.)

zoomkat: I had some pots connected to my arduino and had the values displaying to the serial monitor. The whole time my room temperature did not change, so you may be missing something in your project.

would you kindly share the program you used to display the values onto a serial monitor please?

i have this on my sketch so far...anything else to be added? i'm new to arduino although i know a bit of C..please help.

void setup() {

  Serial.begin(9600);
}

void loop() {
  // read the input on A0 at default resolution (10 bits)
  // and send it out the serial connection
  analogReadResolution(10);
  Serial.print("ADC 10-bit (default) : ");
  Serial.print(analogRead(A0));

  delay(100);
  
  void loop()
{

  // read potentiometer
  byte level = analogRead (0) / 10;
  
  // no change? ignore
  if (level == old_level)
    return;
      
}

I suggest you delete everything after the delay(100) apart from the final }.

Then see if it compiles and runs, and fix it until it does.

Then see if it does what you want, and fix it until it does.