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
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.
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..
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 :(.
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
All i can say is, thanks a lot for your time and patience for solving this issue with me. I am sorry if i have been harsh trying to solve this problem. But, it's sure is worth to know that the Array usually starts at 0 and ends with 9 if the row is equals to 10, and the column starts with 0 and ends with 1 if the cols is equals to 2.
Thank you a lot for your time and patience with me :). There is another task that i am trying to solve as well, but for now. let me get this code organized.
The thing to remember here is that the compiled code (when it is that simple and that explicit) rarely lies.
If you see that a result that is being printed when perhaps you don't expect it to be, check and double check the conditions and fit the result to the observation.
I realised as soon as you typed your interpretation of the table values what the problem was, but you found it yourself from my correction, and you gained a valuable lesson about arrays which will stick in your mind better than if I had simply told you.
I'm curious why the values in the 2nd column of the lookup table are in decreasing order. I find it easier to understand when a value is in range when the lookup table is in increasing order.
And here is the output to that (Works like a charm :D!): -
Value = 685.00 Voltage = 3.35 V Resistance = 4927.11 Ohm
Value = 688.00 Voltage = 3.36 V Resistance = 4862.12 Ohm
Value = 693.00 Voltage = 3.39 V Resistance = 4755.04 Ohm
Value = 695.00 Voltage = 3.40 V Resistance = 4712.64 Ohm
Value = 698.00 Voltage = 3.41 V Resistance = 4649.50 Ohm
Value = 701.00 Voltage = 3.43 V Resistance = 4586.89 Ohm
Value = 704.00 Voltage = 3.44 V Resistance = 4524.82 Ohm
Value = 707.00 Voltage = 3.46 V Resistance = 4463.28 Ohm
25 C
25 C
25 C
25 C
25 C
25 C
25 C
Value = 729.00 Voltage = 3.56 V Resistance = 4027.40 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 731.00 Voltage = 3.57 V Resistance = 3989.07 Ohm
Value = 731.00 Voltage = 3.57 V Resistance = 3989.07 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 739.00 Voltage = 3.61 V Resistance = 3837.84 Ohm
Value = 737.00 Voltage = 3.60 V Resistance = 3875.34 Ohm
Value = 739.00 Voltage = 3.61 V Resistance = 3837.84 Ohm
Value = 740.00 Voltage = 3.62 V Resistance = 3819.16 Ohm
Value = 740.00 Voltage = 3.62 V Resistance = 3819.16 Ohm
Value = 742.00 Voltage = 3.63 V Resistance = 3781.96 Ohm
28 C
28 C
28 C
28 C
28 C
28 C
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 768.00 Voltage = 3.75 V Resistance = 3316.00 Ohm
Value = 768.00 Voltage = 3.75 V Resistance = 3316.00 Ohm
Value = 769.00 Voltage = 3.76 V Resistance = 3298.70 Ohm
Value = 771.00 Voltage = 3.77 V Resistance = 3264.25 Ohm
30 C
30 C
30 C
30 C
30 C
30 C
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 777.00 Voltage = 3.80 V Resistance = 3161.95 Ohm
34 C
34 C
34 C
34 C
34 C
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
How am i suppose to announce the indices that i need to call out the printout that i am looking for (say i need to call out a printout of 25 C with a range between 4030 & 4470) How will i apply that in an index method?
I now cannot work out what you're trying to do.
If you're just filtering for specific values, then you don't need loops at all.
I thought you were using a for loop to give you lookup capabilities, but since you don't use the indices, you're just wasting processing cycles.
I also don't see why you need to iterate over the columns of the table at all.
AWOL:
I now cannot work out what you're trying to do.
If you're just filtering for specific values, then you don't need loops at all.
I thought you were using a for loop to give you lookup capabilities, but since you don't use the indices, you're just wasting processing cyles.
I also don't see why you need to iterate over the columns of the table at all.
I see your double increment has crept back in.
That's the whole point of having the for loop...is to use it for lookup capabilities as you have mentioned.