Multiple Readings at the same time`

I am doing a project of a temperature datalogger using Arduino Yun and K-type thermocouple.
Hardware is done but i am stuck at the coding.
So now i have to write the program for 10 channels, and i am using thousands lines of IF-ELSE to code.
Is there any other way that i can use to read 10 different analog input at the same time and display together?

Use arrays and a for loop

byte input[10] = {... list of your input pins ...};
int reading[10];

for (byte i=0; i < 10; i++)
{
reading[i] = analogRead(input[i]);
}

I haven’t tested that code but it should give you the idea.

I’m not sure how you got up to thousands of lines, or why you needed to use if/else.

Even without the arrays and loop, it still only takes 10 lines to read 10 inputs.

GypsumFantastic:
Use arrays and a for loop

byte input[10] = {... list of your input pins ...};

int reading[10];

for (byte i=0; i < 10; i++)
{
reading[i] = analogRead(input[i]);
}




I haven't tested that code but it should give you the idea.

I'm not sure how you got up to thousands of lines, or why you needed to use if/else.

Even without the arrays and loop, it still only takes 10 lines to read 10 inputs.

Thanks for the help,
I used thousands lines of IF-ELSE because I’ve to keep checking on the thermocouple reading and convert to temperature display.
For example

if (voltage1 >=0.05 && voltage1<=0.06)
{
Serial.println("25 'C " );
}

And i used this for all 10 channels so there will be hundreds of IF-ELSE

Thermocouples are pretty linear, so you can just multiply the analog reading with a constant factor to get the temperature. Maybe add an offset as well.

If that doesn't work, you could use a lookup table, like the NTC examples you can find online.

Pieter

A type k thermocouple gives an output of 40uV / C, and needs a special amplifier and a cold junction compensation to get to the 0..5v range of an arduino a/d.

Most people use shields to accomplish this - eg a MAX6675, - which also contain the a/d . The drivers supplied have a function whiich gives the temperature directly in C or F.

How are you doing it ? - it sounds like hard work

Allan

Hi,
What are you using to interface your thermocouples with your Arduino?

Tom… :slight_smile:

PieterP:
Thermocouples are pretty linear, so you can just multiply the analog reading with a constant factor to get the temperature. Maybe add an offset as well.

If that doesn't work, you could use a lookup table, like the NTC examples you can find online.

Pieter

I've been trying to use the lookup NTC table to do the coding. And it took me quite some times. so i am looking for alternatives.

Thank you for the idea :slight_smile:

allanhurst:
A type k thermocouple gives an output of 40uV / C, and needs a special amplifier and a cold junction compensation to get to the 0..5v range of an arduino a/d.

Most people use shields to accomplish this - eg a MAX6675, - which also contain the a/d . The drivers supplied have a function whiich gives the temperature directly in C or F.

How are you doing it ? - it sounds like hard work

Allan

I am doing this as a part of my internship program and my supervisor wanted me to learn from scratch, so he wants me to design my own amplifier and interface instead of using MAX 31588 or MAX 6675.

So i have to slowly write our the code that checks the voltage every second.

TomGeorge:
Hi,
What are you using to interface your thermocouples with your Arduino?

Tom… :slight_smile:

Hi Tom,

so far i am using analogRead to read the voltage generated by the thermocouple then check one by one using IF-Else to convert it into serial print temperature.

OK.. -you have a masochistic supervisor. I'd probably set you a similar task.

But given you have a reference voiltage such that a/d reading 1023 ( fullscale) == X degrees C

And 0 C == Y (a value 0..1023)

And your thermocouple reading == Z ( 0...1023)

temperature = (( Z- Y) /(1023 - Y)) * X

what could be easier?

Allan

edit

I can't remember if a yun has a 12-bit a/d - in which case replace the 1023's with 4095's....

Hi,
So he wants you to learn about instrument amplifiers.
Instead of all those If statements you could make a lookup table, not sure on the resolution needed.

Tom… :slight_smile: