Here are the problems I faced when fixing the math and how I solved them(if I did):
PROBLEM | SOLUTION |
The 'volts' variable returned 0.00 | Splitting it into the variables 'preVolts' and Volts |
The 'ratio' variable returned 'ovf' which I guess means overflow | Splitting it into the variables 'preRatio', 'RatioDiv', and 'Ratio' Reducing the 1K2 Rl value to 0.9K2 |
The 'ratiox' variable returned 0.00 | I found a math library called BigNumber which can handle big numbers and operations, and I thought that it would solve the problem |
The 'ratiox' variable returned 0 | I split it into 'preRatiox', and 'Ratiox' |
While 'preRatiox' worked fine, 'Ratiox' still returned 0 | When it did the negative exponent, it rounded the result, which was a decimal less than 0 , to 0. So I removed the minus sign, and decided to make it divide later in the 'ppm' variable, then I would get the same result as a negative exponent. |
The 'ppm' variable returned 0 | I think that division was too much for it... I checked it in a calculator, and it gave me 0.000004326450746152052817198327389249, which is too much. I added 20 zeroes behind the numerator in 'ppm' in the hopes that it would have the same effect as multiplying by 10^20, and it would then round it off to something more precise. |
The 'ppm' variable returned -15226 after about a minute of calculating | I read that the Arduino does make mistakes in division, and that it could take a longer time than multiplication. So I added 'L' after the dividend to make sure the program new it was a 'long' and reduced the number to 0s to 10, and got -26107. Then I reduced the number of 0s to five and got 4. That's good! It's getting closer! With 7 0s, it returns 432. That's even closer! 9 0s returns -22272, which is back to the nonsense values we had earlier. 8 0s returns 4326. It looks like this is the closest I'm going to get. However, it took 1.5 minutes to calculate that. |
Time-consuming calculation | I uploaded the code again, now it works fine. |
I can't find an LPG source to test the code | I'm using a AAA battery to power the sensor at 1.5V, and changed the numbers in the code accordingly (swap the 5s in 'volts' for 1.5). Now it will measure carbon monoxide, which I can test with a match or candle.'' |
'ppm' returns -1 |
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.