[SOLVED]Trouble with the pow() function?

Hi at the community,

I have a, hopefully, pretty simple problem, which I simply can’t figure out. I’m trying to compile the following code, but I get this error message: “‘pow’ was not declared in this scope”

I have been looking at the reference documentation and it seems correct to me.

    const int irsensorpin = A0;

void setup() {
  // put your setup code here, to run once:

void loop(){

  // Reads the InfraRed sensor analog values and convert into distance.
  double sensorValue = analogRead(irsensorpin);
  double IRdistance = 6560.7 * pow(sensorValue, (-0.517));


  // A delay is added for a stable and precise input

I have also tried to change the base to a float like this, but I get the same error.

  float sensorValue = analogRead(irsensorpin);

Hope you guys can help me :grinning:

Regards Mads

Just include this at the top of your source file:

#include <math.h>

Many things are automatically included for you, but math.h is not.


Thanks a lot :smile:

Thanks for the quick fix and answer Rick!