 # Natural Log on Arduino ATMega328?

Hi All,

I am currently using Arduino Uno ATMega328 and am looking to use the Natural Log function.

Online I read I need to use Arduino ATMega168, though that seems likea downgrade. How can I start using the Natural Log function on my Aruino, such as in this equation

y = -0.317ln(x) + 1.3286

Does the Arduino Micro ATmega32u4 allow me to use Natural Log?

Thanks a ton, Andrew

Ardiuno includes the AVR libc library. Math functions are here:

http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html

Thank you,

Can someone tell me what is wrong with this code attached though?

I get error messages when I verify.

Andrew I think, you misunderstood function usage - C basics: double log(double x) means that the function requires parameter type double and returns value type double. I should be just:

``````y = log(2);
``````

but y should be defined as double and also consider that you are using constant as parameter in loop function and the result will be always the same.

``````int y;
y = log (2);
Serial.print(y);
``````

aka

``````Serial.print (0);
``````

Thanks Everyone,

Still having some trouble and been working for hours.

1) how is natural log of 2, y = log (2); equal to serial.Print (0). I have natural log 2 = .69 on my calculatot?

2) I would like to add many more decimal places to my y = log (2). Can someone post code that can let me do this?

It's been hard to filter through what I am reading online with float.

Thank you, Andrew

1) how is natural log of 2, y = log (2); equal to serial.Print (0).

It is if you mistakenly assign the natural log of 2 to an [u]integer variable[/u].

To print more decimal places, use a command (function call) like this:

``````Serial.print(log(2), 4); //prints to 4 decimal places
``````
``````// 'log' is defined as returning a double precision floating point value as in ...
//     double log(double x);
// ... on most Arduinos 'double' is in fact a 'float'
double y = log(2);
Serial.print(y);
``````