I'm making my arduino uno read and change the temperture of a heated glove and read the values onto an oled screen. Although, currently the temp displayed on the screen is 2 decimal places and I want it to be either 1 or none. I am using a thermistor to read the temperature and the website I got the code from is Make an Arduino Temperature Sensor (Thermistor Tutorial) .
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_WIDTH 128 // OLED display width, in pixels
#define OLED_HEIGHT 64 // OLED display height, in pixels
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);
int buttonPin_down = 8;
int buttonPin_up = 12;
int relay = 7;
int value = 30;
int ThermistorPin = A3;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
pinMode(relay, OUTPUT);
Serial.begin(9600);
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
delay(2000);
oled.clearDisplay();
}
void loop() {
Serial.println(value);
Vo = analogRead(ThermistorPin);
Serial.print (" Vo =");
Serial.print(Vo);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
Serial.print("\t R2 =");
Serial.print(R2);
logR2 = log(R2);
Serial.print("\t logR2 =");
Serial.print(logR2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Serial.print("\t T =");
Serial.print(T);
Tc = T - 273.15;
// Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print("\t Temperature: ");
Serial.print(Tc);
Serial.println(" C");
if(Tc < value)
digitalWrite(relay, LOW);
else
digitalWrite(relay, HIGH);
if(digitalRead(buttonPin_up) == HIGH)
++ value;
if(digitalRead(buttonPin_down) == HIGH)
-- value;
oled.setTextSize(2);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(0, 13);
oled.println(Tc);
oled.display();
oled.setTextSize(1);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(0, 0);
oled.println("Real Temp:");
oled.display();
oled.setTextSize(2);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(65, 13);
oled.println("C");
oled.display();
oled.setTextSize(2);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(0, 45);
oled.println(value);
oled.display();
oled.setTextSize(1);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(0, 32);
oled.println("Set Temp:");
oled.display();
oled.setTextSize(2);
oled.setTextColor(WHITE, BLACK);
oled.setCursor(65, 45);
oled.println("C");
oled.display();
delay(300);
}