# B4R Questioncalculation different values B4R / Arduino

#### Michael1968

##### Active Member
Hi all,
I am working on a project to measure/calculate temperature from a NTC resistor using MCP3208.
the arduino code works but i have a problem to write it in B4R.

I get different values.
Arduino Code:
``````float Rmess = 47;
float a, b, c, Rn;

Rn = 1000;
a = 0.003358;
b = 0.0002242;
c = 0.00000261;

// start sampling

float Rt = Rmess * ((4096.0 / (4096 - raw)) - 1); -->1016.60
float v = log(Rt / Rn); -->0.02
float erg = (1 / (a + b * v + c * v * v)) - 273.15; -> 24.32``````

...and this is the B4R Code
B4X:
``````Dim Rmess,V,erg As Float
Dim RT As Float
Dim a,b,c,rn As Float

rn = 1000
a = 0.003358
b = 0.0002242
c = 0.00000261

Rmess=47

RT = Rmess * ((4096.0 / (4096 - 3915)) - 1)  '-->1016.6022

v= RT/rn
v = Logarithm(V,10) '-->0.0072

erg = (1 / (a + b * v + c * v * v)) - 273.15 '--> 24.54``````

any idea?

i have also testet to use the Arduino Code inline but i get an Error at the point
float v = log(Rt / Rn);
is called

thx for help

#### thetahsk

##### Active Member

Try this and dont't mix log and log10 function.

B4X:
``````Dim Rmess,V,erg As Float
Dim RT As Float
Dim a,b,c,rn As Float
Dim Math_Euler As Float=2.7182818284590452354
rn = 1000
a = 0.003358
b = 0.0002242
c = 0.00000261
Rmess=47
RT = Rmess * ((4096.0 / (4096 - 3915)) - 1)
Log("RT=",RT)
v= RT/rn
v = Logarithm(v,Math_Euler)
Log("v=",v)
erg = (1 / (a + b * v + c * v * v)) - 273.15
Log("erg=",erg)``````

#### Michael1968

##### Active Member
Wow...

it Work thank you very much

DANKE

Share My Creation Arduino to PC
Replies
3
Views
580
B4R Tutorial Intel Arduino 101
Replies
0
Views
5K
Replies
41
Views
14K
Replies
36
Views
31K
B4R Tutorial Arduino + Raspberry Pi
Replies
0
Views
9K