Newbie Question wiring and code

Hi, newbie here. Can someone shed some light on this please. :frowning:

I watched a few Utube videos and searched the forums on how to display temperature with arduino using a pot. I can’t seem to reverse the Output for the Temp instead of 0v = hot and 5v = cold, it shows the opposite.

How can I display the temps on the LCD/OLED LCD with a 0-5v Input using a Potentiometer:
0v=220c
0.16v=212c
0.31v=194c
0.47v=183c
0.62v=174c
0.78v=163c
0.94v=154c
1.09v=145c
1.25v=136c
1.40v=127c
1.56v=118c
1.72v=109c
and so on until 5v = -30c

Sorry for the terminologies I used, I really am a newbie. And for the confusing tinker cad wirings, just trying to get it done.

Here are the codes I copied from some forums and videos:

//
#include "LiquidCrystal.h"
LiquidCrystal lcd(12,11,5,4,3,2);
int sensorPin = 0;
 
void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
}
 
void loop()
{
 
 int reading = analogRead(sensorPin);

 // measure the 5v with a meter for an accurate value
 //In particular if your Arduino is USB powered

 float voltage = reading * (5 / 1023.0);
 
 // now print out the temperature      
 float temperatureC = (voltage - 0.5) * 100;
 Serial.print(temperatureC);
 Serial.println(" degrees C");
   lcd.setCursor(0,0);
   lcd.print("TEMP: ");
   lcd.setCursor(7,0);
   lcd.print(temperatureC);
   lcd.setCursor(13,0);
   lcd.print("C");
  // print out the voltage
  Serial.print(voltage);
  Serial.println(" volts");
   lcd.setCursor(0,1);
   lcd.print("Volts: ");
   lcd.setCursor(6,1);
   lcd.print(voltage);
   lcd.setCursor(11,1);
   lcd.print("v");
   
 delay(100);
}

Try inverting the raw value...

reading = 1023 - reading;

or mapping the reading to your temperature range

reading = map (reading, 0, 1023, lowTemp, hiTemp);
1 Like

Everyone has been a newbie!
I suggest reverse the polarity to the pot and to the display.
A tip. Don't use that circuit representation later. Those coloured bird nest pictures lacks lots of information. Pen and paper with pun designations, polarity, voltages.. are most of the times better.

2 Likes

It worked. Thanks for the tip, Railroader. :grin:

Thank you xfpd! I tried adding both to the code, it worked! :smile:

Good. Thanks for telling!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.