Error Saying that 'getVPP' Was not Declared in this Scope

Hi all,

I am currently working on a project that controls an air conditioning unit via IR.

To tell if the air conditioner is on/off I use a current sensor.

This code for just the current sensor works fine:

int sensorTA12 = A0; // Analog input pin that sensor is attached to

float nVPP;   // Voltage measured across resistor
float nCurrThruResistorPP; // Peak Current Measured Through Resistor
float nCurrThruResistorRMS; // RMS current through Resistor
float nCurrentThruWire;     // Actual RMS current in Wire

void setup() {
  pinMode(sensorTA12, INPUT);

void loop() {

nVPP = getVPP();

    Use Ohms law to calculate current across resistor
    and express in mA

 nCurrThruResistorPP = (nVPP / 200.0) * 1000.0;

    Use Formula for SINE wave to convert
    to RMS

 nCurrThruResistorRMS = nCurrThruResistorPP * 0.707;

    Current Transformer Ratio is 1000:1...

    Therefore current through 200 ohm resistor
    is multiplied by 1000 to get input current

  nCurrentThruWire = nCurrThruResistorRMS * 1000;

  //Serial.print("Volts Peak : ");
  //Serial.println(nVPP, 3);

  //Serial.print("Current Through Resistor (Peak) : ");
  //Serial.print(nCurrThruResistorPP, 3);
  //Serial.println(" mA Peak to Peak");

  //Serial.print("Current Through Resistor (RMS) : ");
  //Serial.print(nCurrThruResistorRMS, 3);
  //Serial.println(" mA RMS");

  Serial.print("Current Through Wire : ");
  Serial.print(nCurrentThruWire, 3);
  Serial.println(" mA RMS");



  In order to calculate RMS current, we need to know
  the peak to peak voltage measured at the output across the
  200 Ohm Resistor

  The following function takes one second worth of samples
  and returns the peak value that is measured

float getVPP()
  float result;
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  uint32_t start_time = millis();
  while ((millis() - start_time) < 1000) //sample for 1 Sec
    readValue = analogRead(sensorTA12);
    // see if you have a new maxValue
    if (readValue > maxValue)
      /*record the maximum sensor value*/
      maxValue = readValue;

  // Convert the digital data to a voltage
  result = (maxValue * 5.0) / 1024.0;

  return result;

However when I try to combine this code with my other code I get an error when compiling saying:
‘getVPP’ was not declared in this scope

What does this line of code do and what have I done wrong?

The code that comes up with the error is attached as it is rather long!

Any help would be amazing!



IR-Factory-Air-Con-Controller.ino (58.4 KB)

You do not have a closing brace } for the function void Mode()


This will also cause you some problems.

  if (millis() > 86400000) and ((millis() - timeSinceAirconTouched > setTimeSinceAirconTouched))

This library and the example, may make it easier for you to format your sending IR codes.

Tom... :slight_smile:

Hi all,

Thanks very much Steve that fixed my problem!

And thanks Tom those links are very helpful and I have now written it correctly and the code compiles with no errors!

I have one last question, is there a line of code that can repeat a function multiple times? (you set the number of times)



is there a line of code that can repeat a function multiple times? (you set the number of times)

A for loop?

Great, thanks very much!