Continue to Site

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.

  • 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

Status
Not open for further replies.

Matienzo

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

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

//---------Servo------------

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


//-------Thermistor---------

#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];


//---------Display-------------

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) {

  Serial.begin(9600);
  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);
   delay(10);
  }
  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.print(steinhart);
  Serial.println(" *C");
  //delay(1000);
 
 //--------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
 delay(15);

  }

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

Latest threads

New Articles From Microcontroller Tips

Back
Top