• 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.

TM1637 to display temperature. Code question

Not open for further replies.


Hi there,

I'm trying to display the temperature on a TM1637 display. the variable I'm trying to display is "steinhart". It is declared as a float but when I compile the error reads:"steinhart' was not declared in this scope". Alrighty then, I declare it and displays a 0 on the display. The code is made out of pieces from other codes so it might have discrepancies.

What do you think I'm doing wrong? Thank you for any guidance.

#include <Servo.h>
#include <TM1637Display.h>


Servo myservo;                // create servo object to control a servo
int potpin = 0;               // analog pin used to connect the potentiometer
int val;        


#define TPIN A1                  // which analog pin to connect
#define TRESISTANCE 2500000      // resistance at 25 degrees C
#define TROOM 25                 // temp. for nominal resistance
#define NSAMPLES 5               // how many samples to take and average, more takes longer but is more 'smooth'
#define BCOEFF 3980              // The beta coefficient of the thermistor
#define SERIESRESISTOR 100000    // the value of the 'other' resistor
int samples[NSAMPLES];


const int CLK = 3;                 //Set the CLK pin connection to the display
const int DIO = 2;                 //Set the DIO pin connection to the display
TM1637Display display(CLK, DIO);   //set up the 4-Digit Display.

void setup(void) {

  myservo.attach(8);                // attaches the servo on pin 9 to the servo object
  display.setBrightness(0x0a);      //set the diplay to maximum brightness

void loop(void) {
  {uint8_t i;
  float average;
  for (i=0; i< NSAMPLES; i++) {      // take N samples in a row, with a slight delay
   samples[i] = analogRead(TPIN);
  average = 0;
   for (i=0; i< NSAMPLES; i++) {
     average += samples[i];
  average /= NSAMPLES;
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;
  float steinhart;
  steinhart = average / TRESISTANCE;           // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFF;                         // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TROOM + 273.15);         // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C
  Serial.print("Temperature ");
  Serial.println(" *C");
 //--------Servo Knob----------------
 val = analogRead(potpin);          // reads the value of the
                                    // potentiometer (value between
                                    // 0 and 1023)
 val = map(val, 0, 1023, 0, 179);   // scale it to use it with
                                    // the servo (value between 0 and
                                    // 180)
 myservo.write(val);                // sets the servo position according
                                    // to the scaled value


 //-----------Display-- -------------
 //float steinhart;
 display.showNumberDec(steinhart);  //Display the Variable value;
Last edited:
Not open for further replies.

Latest threads

EE World Online Articles