1

Hej..I am building a project with four NTC 10k ohm temperature sensor with Arduino. It is easy to measure only one NTC temperature sensor. There is many examples for NTC measurement for example code written with Steinhart-Hart Equation or reading ADC Thermistor with Lookup Table.

I found one example with Steinhart-Hart Formula. I am not so good at coding with Arduino but I Manage and build to write code for only one NTC sensor and read it with Nokia LCD 5110. The question is how to do code for Multiple NTC sensors?

/* NTC temperature mesurment 13-08-2017
 *  
 *  Using Nokia LCD 5110
 */

#include "LCD5110_Graph.h"
LCD5110 myGLCD(8, 9, 10, 12, 11);  // Setup Nokia 5110 Screen SCLK/CLK=5, DIN/MOSI/DATA=6, DC/CS=7, RST=8 Chip Select/CE/SCE=9,
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];

int tempPin = 0;   // A0 analog input
int Vout, charTc ;
float R1 = 10000; //otpornost na sobnoj temperaturi 10K ili 10000 oma
float R2, Tk, Tc;
float Ac = 1.009249522e-03, Bc = 2.378405444e-04, Cc = 2.019202697e-07;
char charBuffer[10];


void setup(){
myGLCD.InitLCD(); //initialize LCD with default contrast of 70
myGLCD.setContrast(68);
myGLCD.setFont(SmallFont); // Set default font size. tinyFont 4x6, smallFont 6x8, mediumNumber 12x16, bigNumbers 14x24
myGLCD.clrScr();

myGLCD.print("Temp test",CENTER,0);
myGLCD.print("Check",CENTER,12);
myGLCD.print("Please Wait",CENTER,24);

myGLCD.update(); 
delay(5000);
myGLCD.clrScr();
}

void loop() {
  Vout = analogRead(tempPin);
  R2 = R1 * (1023.0 / (float)Vout - 1.0); // konvertovanje iz analogne u digitalnu
  Tk = (1.0 / (Ac + Bc*log(R2) + Cc*log(R2)*log(R2)*log(R2))); // Temperature in Klven
  Tc = Tk - 273.15; //temperature converted to celcious

charTc=dtostrf(Tc, 3, 2, charBuffer);



  myGLCD.clrScr();
  //myGLCD.print("Discharging",CENTER,0);
  //myGLCD.print("Temperature:",CENTER,0);
  myGLCD.print("Temp1:",0,0);
  //myGLCD.print( charTc,CENTER,20 );
  myGLCD.print( charTc,36,0 );
  myGLCD.print("Temp2:",0,10);
  myGLCD.print("Temp3:",0,20);
  myGLCD.print("Temp4:",0,30);
  myGLCD.update(); 
  delay(2000);
  myGLCD.clrScr();
}
2
  • The row int tempPin = 0; // A0 analog input specify which analog input that should be used as input for reading the NTC value. Then you can expand the code with the analog inputs that is needed.
    – MatsK
    Aug 18, 2017 at 15:05
  • Thanks for you reply. Yes i know that Arduino has 8 ADC input. But my desire is how to do interval time execution for many ADC input. Is it best way to write timer interrupt? for every analog input to Execute every 2 seconds if the reading is changed of adc? Aug 18, 2017 at 20:02

5 Answers 5

1

The row int tempPin = 0; // A0 analog input specify which analog input that should be used as input for reading the NTC value.

Then you can expand the code with the analog inputs that is needed.

1

Arduino UNO has 6 Analog pins ..

Sequentially Read ADC every 2 seconds either by calling the Respective ADC functions inside a TIMER_INTERRRUPT_VECTOR() or if high Accuracy is not Required you can restrict your main loop() to be small and write all ADCs inside it. Also make sure that you sample your ADC if writing inside loop to make sure that its accurate.

2
  • 1
    You don't need interrupts to sample every 2 seconds. Just do it directly in the loop().
    – user31481
    Oct 18, 2017 at 9:31
  • Yes..both the ways it can be done ,writing in loop is simple but it's always better to make your loop () run at shortest time..if planning to modify the code in future .one more option is to create individual tasks and make all ADCs run independently but little complicated
    – GOKUL
    Oct 18, 2017 at 9:45
1

As I understand, you have multiple analog sensors you want to read. So your code should look something like this:

// assuming sensors are on A0, A1, A2, Ax

sensorPins [] = {A0, A1, A2};
int sensorNum = 3;

for(int x = 0; x < sensorNum; x++){
  readSensor(x);
}

Something like that should work for you.

0
  1. Put in multiple analog input pins and read them sequentially;

  2. Put in multiple analog input pins and scan them in the adc interrupts.

the first approach is quite simple and the 2nd approach requires a thorough read of the datasheet.

0

This is pretty simple. Create an array of uint_8 variables that contains your pin numbers.

Then write a function that takes a pin number as an input, reads the ADC, does the math, and returns a value.

sensorPins [] = {A0, A1, A2, A3};

float readTemp(int tempPin) {
  int Vout = analogRead(tempPin);
  float R2 = R1 * (1023.0 / (float)Vout - 1.0); // konvertovanje iz analogne u digitalnu
  float Tk = (1.0 / (Ac + Bc*log(R2) + Cc*log(R2)*log(R2)*log(R2))); // Temperature in Kelven
  Tc = Tk - 273.15; //temperature converted to Celsius
  return Tc;
}

Then write a loop that loops through your array of pin numbers and calls the readTemp function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.