Having trouble on solving the following tasks

My suggestion is to lose the the second i++ and j++ in the loops (I think I've already said this).

My suggestion is to test not for equality, but for a range of values. (I think others have said this).

I still don't know why you're looping through a table but using constant subscripts, or even why you're looping across the columns. Maybe you can answer this.

AWOL:
My suggestion is to lose the the second i++ and j++ in the loops (I think I’ve already said this).

My suggestion is to test not for equality, but for a range of values. (I think others have said this).

I still don’t know why you’re looping through a table but using constant subscripts, or even why you’re looping across the columns. Maybe you can answer this.

Ok, i think i got it somehow working. Except it isn’t as accurate as i’ve expected. I’ve followed your lead, and this is what i’ve done so far: -

void loop()
{

float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
                         
  SensorValue = analogRead(ThermPin);
  Serial.print("Value = ");
  Serial.print(SensorValue);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  Serial.print("\t Voltage = ");
  Serial.print(Vout);
  Serial.print(" V");
  
  ThermResist =((R2*Vin)/Vout)-R2;
  Serial.print("\t Resistance = ");
  Serial.print(ThermResist);
  Serial.println(" Ohm");
  
      if(ThermResist <= Table[4][1] && ThermResist >= Table[5][1])
      {
        Serial.print(Table[4][0]); 
        Serial.println(" C");
      }

}

I’ve tried to go between those 2 values, but no luck. Except, if i’ve gone below Table[5][1], the printout statement have been triggered.

Except it isn't as accurate as i've expected

Can you tell us what your expectations are, and how your observations differ?

What sort of value are you seeing for "TermResist"

AWOL:

Except it isn't as accurate as i've expected

Can you tell us what your expectations are, and how your observations differ?

What sort of value are you seeing for "TermResist"

My expectations is, if the ThermResist values hits below 3800. At the same time, stays above 3530. A printout statement of the Temp of 29 C have been initiated. Otherwise, it will keep on repeating the sensval, volt, & ohm outputs the usual.

ThermResist records the resistance of the Thermister, by adding the static resistance with it.

OK, I'll try one more time. What sort of value are you seeing for "ThermResist" ? (OK, I know I spelled it wrong last time)

AWOL: OK, I'll try one more time. What sort of value are you seeing for "ThermResist" ? (OK, I know I spelled it wrong last time)

I see the ThermResist as a float value to calculate the resistance of the Thermistor based on the voltage Output

Lose the excess subscript increments. How so? The task mentions that i need to make a simple lookout table based on 2D array (without using the steinhart-hart equation).

Ok, I’ll repeat: you get an analog value and you search it with equality among a (small) set of predefined values. An analog value in Arduino is an integer number between 0 and 1023. If you compare it to, say, 10 values you roughly have 1% probability to “catch” it each time.

Back to your code, it’s clear that you’re trying to identify the type of battery based on its weight. Each battery type has a minimum and maximum weight. You want to determine in which weight range your analog value falls. For this you need to test it against the minimum and maximum value of each range. And for this you need >= and <=, not ==.

I don’t understand why using a lookup table implies using (only) ==.

If you insist on using ==, you could probably make a 1024-elements lookup table and use the analogRead result as an index into it. Total waste of RAM, IMHO, but using just 1 byte per element it could be doable (you’d be using half RAM just for that…).

(edit: sorry I assumed you would search using an integer value. If you use floats, then == is definitely out of question)

I see the ThermResist as a float value to calculate the resistance of the Thermistor based on the voltage Output

Sigh.

"Seeing" with your actual eyes, not your mind's eye.

Jonraptor:

AWOL: OK, I'll try one more time. What sort of value are you seeing for "ThermResist" ? (OK, I know I spelled it wrong last time)

I see the ThermResist as a float value to calculate the resistance of the Thermistor based on the voltage Output

Please copy-n-paste here what you get on the serial monitor after running your program.

Tell us why what you see is wrong, and what it should be instead.

I hope it's clear now.

tuxduino:

Jonraptor:

AWOL: OK, I'll try one more time. What sort of value are you seeing for "ThermResist" ? (OK, I know I spelled it wrong last time)

I see the ThermResist as a float value to calculate the resistance of the Thermistor based on the voltage Output

Please copy-n-paste here what you get on the serial monitor after running your program.

Tell us why what you see is wrong, and what it should be instead.

I hope it's clear now.

Yup, in a min.

Here is an output of my code: -

Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 753.00   Voltage = 3.68 V    Resistance = 3580.90 Ohm
Value = 751.00   Voltage = 3.67 V    Resistance = 3617.02 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 752.00   Voltage = 3.68 V    Resistance = 3598.94 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 753.00   Voltage = 3.68 V    Resistance = 3580.90 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 753.00   Voltage = 3.68 V    Resistance = 3580.90 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 754.00   Voltage = 3.69 V    Resistance = 3562.91 Ohm
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 756.00   Voltage = 3.70 V    Resistance = 3527.08 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C
Value = 755.00   Voltage = 3.69 V    Resistance = 3544.97 Ohm
Value = 759.00   Voltage = 3.71 V    Resistance = 3473.68 Ohm
29 C
Value = 757.00   Voltage = 3.70 V    Resistance = 3509.23 Ohm
29 C
Value = 758.00   Voltage = 3.71 V    Resistance = 3491.44 Ohm
29 C

tuxduino:

Lose the excess subscript increments. How so? The task mentions that i need to make a simple lookout table based on 2D array (without using the steinhart-hart equation).

Ok, I’ll repeat: you get an analog value and you search it with equality among a (small) set of predefined values. An analog value in Arduino is an integer number between 0 and 1023. If you compare it to, say, 10 values you roughly have 1% probability to “catch” it each time.

Back to your code, it’s clear that you’re trying to identify the type of battery based on its weight. Each battery type has a minimum and maximum weight. You want to determine in which weight range your analog value falls. For this you need to test it against the minimum and maximum value of each range. And for this you need >= and <=, not ==.

I don’t understand why using a lookup table implies using (only) ==.

If you insist on using ==, you could probably make a 1024-elements lookup table and use the analogRead result as an index into it. Total waste of RAM, IMHO, but using just 1 byte per element it could be doable (you’d be using half RAM just for that…).

(edit: sorry I assumed you would search using an integer value. If you use floats, then == is definitely out of question)

I think i pointed out that i’ve removed the for loop in replacement for adding an if statement based on the range between values.

I think i pointed out that i've removed the for loop in replacement for adding and if statement based on the range between values.

I'm sorry, I wrote that comment before seeing your last code.

Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm 29 C

What's the problem?

AWOL:

Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
29 C

What’s the problem?

I’ll point out the issue in this.

Here is the code that i’ve implemented for my if statement: -

      if(ThermResist >= Table[5][1] &&ThermResist <= Table[4][1] )
      {
        Serial.print(Table[4][0]); 
        Serial.println(" C");
      }

And here is the output of the function trigger less than 3530: -

Value = 754.00	 Voltage = 3.69 V	 Resistance = 3562.91 Ohm
Value = 755.00	 Voltage = 3.69 V	 Resistance = 3544.97 Ohm
Value = 755.00	 Voltage = 3.69 V	 Resistance = 3544.97 Ohm
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
29 C
Value = 754.00	 Voltage = 3.69 V	 Resistance = 3562.91 Ohm
Value = 753.00	 Voltage = 3.68 V	 Resistance = 3580.90 Ohm
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
29 C
Value = 754.00	 Voltage = 3.69 V	 Resistance = 3562.91 Ohm
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
29 C

I am simply trying to print out the statement that is way out of the range which i am trying to implement (between 3800 & 3530). Instead, i get the printout below 3530… which for me, is a catastrophe…

I’m sorry, I really don’t see the problem.

3527.08 is greater than 3270 AND it is less than 3530.

AWOL:
I’m sorry, I really don’t see the problem.

3527.08 is greater than 3270 AND it is less than 3530.

  if(ThermResist >= Table[5][1](3530) &&ThermResist <= Table[4][1](3800) )
      {
        Serial.print(Table[4][0]); 
        Serial.println(" C");
      }
f(ThermResist >= Table[5][1](3270) &&ThermResist <= Table[4][1](3530) )

is what you meant to type, I guess.

AWOL:

f(ThermResist >= Table[5][1](3270) &&ThermResist <= Table[4][1](3530) )

is what you meant to type, I guess.

OMG, i have completely forgotten that the array starts with 0, rather than 1. My apologies for the misunderstanding, ill get this sort out ASAP and show you the output :(.

I’ve solved the problem by counting the array from 0-9, turned out i have mistaken 4 with 3530, and 5 with 3270.

Here the code that i’ve altered after a while: -

      if(ThermResist >= Table[4][1] && ThermResist <= Table[3][1] )
      {
        Serial.print(Table[4][0]); 
        Serial.println(" C");
      }

And here is the output that i am quite happy on (between 3800 && 3530): -

Value = 738.00	 Voltage = 3.61 V	 Resistance = 3856.56 Ohm
Value = 739.00	 Voltage = 3.61 V	 Resistance = 3837.84 Ohm
Value = 741.00	 Voltage = 3.62 V	 Resistance = 3800.54 Ohm
Value = 741.00	 Voltage = 3.62 V	 Resistance = 3800.54 Ohm
Value = 741.00	 Voltage = 3.62 V	 Resistance = 3800.54 Ohm
Value = 743.00	 Voltage = 3.63 V	 Resistance = 3763.44 Ohm
29 C
Value = 741.00	 Voltage = 3.62 V	 Resistance = 3800.54 Ohm
Value = 743.00	 Voltage = 3.63 V	 Resistance = 3763.44 Ohm
29 C
Value = 743.00	 Voltage = 3.63 V	 Resistance = 3763.44 Ohm
29 C
Value = 745.00	 Voltage = 3.64 V	 Resistance = 3726.54 Ohm
29 C
Value = 742.00	 Voltage = 3.63 V	 Resistance = 3781.96 Ohm
29 C
Value = 745.00	 Voltage = 3.64 V	 Resistance = 3726.54 Ohm
29 C
29 C
Value = 755.00	 Voltage = 3.69 V	 Resistance = 3544.97 Ohm
29 C
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
Value = 753.00	 Voltage = 3.68 V	 Resistance = 3580.90 Ohm
29 C
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
Value = 758.00	 Voltage = 3.71 V	 Resistance = 3491.44 Ohm
Value = 756.00	 Voltage = 3.70 V	 Resistance = 3527.08 Ohm
Value = 758.00	 Voltage = 3.71 V	 Resistance = 3491.44 Ohm
Value = 757.00	 Voltage = 3.70 V	 Resistance = 3509.23 Ohm
Value = 757.00	 Voltage = 3.70 V	 Resistance = 3509.23 Ohm
Value = 757.00	 Voltage = 3.70 V	 Resistance = 3509.23 Ohm

Time to put your for loops back.

Thanks for sticking with it.