sketch_nov08a.ino:4:23: error: 'AO' was not declared in this scope

I'm getting this error when debugging my Uno starter kit, project 4 Love-O-Meter.

Everything else is in great order but this one line of code, and I can't figure out what I may've done wrong.

Here's all of my code:

const int sensorPin = AO;
const float baselineTemp = 20.0;

void setup() {
Serial.begin(9600); // open a serial port

for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber, LOW);

}
}

void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);

// convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;

Serial.print(", Volts: ");
Serial.print(voltage);

Serial.print(", degrees C: ");
//convert the voltage to temperature in degrees
float temperature = (voltage - .5) * 100;
Serial.println(temperature);

if(temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);

}
delay(1);
}

++++++++++++++++++++++++++++++++

Here's the error code again:

Arduino: 1.5.8 (Windows 7), Board: "Arduino Uno"

sketch_nov08a.ino:4:23: error: 'AO' was not declared in this scope
Error compiling.

Cheers Rich

1 Like

AO
or
A0
:wink:

1 Like

If you can sing "Daylight come and I wan go home" to it, then you've got it wrong.

:stuck_out_tongue_closed_eyes: :grinning: :grin: :slight_smile:

I tried AO and A0 and it gave me the same error message. I also tried singing some Al Jolson to the board directly and that didn't work.

const int sensorPin = A0;
Works on IDE 1.06

Try
const int sensorPin = 0;

Works on 1.5.6-r2 also

If you don't have an Oh in your code, then your error message can't report it. It's definitely zero that you need.

Might be some hidden garbage on the line try deleting the line and retyping it.

EDIT:
I was able to reproduce it here.
Went away after I retyped the whole line.

EDIT:
It's the darn font

Well that was helpful, I changed out the first line of code completely and replaced an O with a 0. I definitely got results, but it's not fully working yet. Only 2 of the 3 LEDs are coming on. Using the Monitor Icon button I'm getting read outs from the sensor of:

Sensor Value: 388, Volts: 1.89, degrees C: 139.45

When I put my finger on the sensor I get:

Sensor Value: 390, Volts: 1.90, degrees C: 140.43

Not much difference.

I'm not sure it's working correctly, I guess the next thing is checking all my wiring.

You're a pretty hot blooded individual :slight_smile:
I'd suggest that, while you're debugging, you change the last line of your loop to be **delay(1000);**This will cut down your serial updates to 1 per second. Copy and paste us some results to see.

#include <EmonLib.h> // Include Emon Library
EnergyMonitor emon1; // Create an instance

// include the Library code:
#include <LiquidCrystal.h> // initialize the Library with the numbers of the interface pins
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
const int sensorIn = A0;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double current = 0;
double IRMS = 0;
float powerFactor = 0;
int i;

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

Serial.begin(9600);
lcd.begin(16,2); // set up the LCD's number of colunms and rows.
emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_ shift
emon1.current(1, 111.1); // current: input pin, calibration.

}

void loop() {

analogRead(A0, INPUT);
Voltage = getvoltage();
VRMS = (Voltage) *0.707 * 11 * 12;
current = getcurrent();
IRMS = (current/2.0) 0.707;
AmpsRMS = (IRMS * 1000)/mVperAmp;
emon1.calcVI(20,2000); // Calculatte all. No. of half wavelengthe (crossings), time-cut.
//VRMS =emon1.Vrms; // extract Irms into Variable
// AmpsRMS = emon1.Irms;
for ( i=0; i<100; i++)
{
powerFactor = powerFactor + emon1.powerFactor; //extract Power Facto into Variable
}
powerFactor = powerFactor/100;
lcd.setCursor(0,0);
lcd.print("PF=");
lcd.setCursor(3,0);
lcd.print(powerFactor
100);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("I=");
lcd.setCursor(3,1);
lcd.print(AmpsRMS);
lcd.print("A=");
lcd.print(" ");
lcd.print("V=");
lcd.print(VRMS);
lcd.print("V=");
}

float getcurrent()
{
float result;

int readValue; // value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here

uint32_t start_time = millis();
while((millis()-start_time) < 1000) // sample for 1 Sec
{
readValue = analogRead(A0);
// see if you have a new maxValue
if (readValue > maxValue)
{
/* record the maximum sensor Value*/
minValue = readValue;
}
if (readValue < minValue)
{
/* record the minimum sensor Value*/
minValue = readValue;
}
}

// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;

return result;
}
float getvoltage()
{
float result;

int readValue; // value read from sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here

uint32_t start_time = millis();
while((millis()-start_time) < 1000) // sample for 1 Sec
{
readValue = analogRead(A0);
// see if you have a new maxValue
if (readValue > maxValue)
{
/* record the maximum sensor Value*/
minValue = readValue;
}
if (readValue < minValue)
{
/* record the minimum sensor Value*/
minValue = readValue;
}
}

}

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\EmonLib/EmonLib.h:95:5: error: 'boolean' does not name a type

boolean lastVCross, checkVCross; //Used to measure number of times threshold is crossed.

^

In file included from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:5:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal/LiquidCrystal.h:86:16: error: conflicting return type specified for 'virtual void LiquidCrystal::write(uint8_t)'

virtual void write(uint8_t);

^

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal/LiquidCrystal.h:5:0,

from C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino:5:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:51:20: error: overriding 'virtual size_t Print::write(uint8_t)'

virtual size_t write(uint8_t) = 0;

^

sketch_nov01a:7: error: 'A0' was not declared in this scope

const int sensorIn = A0;

^

C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'void setup()':

sketch_nov01a:22: error: 'Serial' was not declared in this scope

Serial.begin(9600);

^

C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'void loop()':

sketch_nov01a:31: error: 'A0' was not declared in this scope

analogRead(A0, INPUT);

^

sketch_nov01a:31: error: 'INPUT' was not declared in this scope

analogRead(A0, INPUT);

^

sketch_nov01a:31: error: 'analogRead' was not declared in this scope

analogRead(A0, INPUT);

^

C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'float getcurrent()':

sketch_nov01a:69: error: 'millis' was not declared in this scope

uint32_t start_time = millis();

^

sketch_nov01a:72: error: 'A0' was not declared in this scope

readValue = analogRead(A0);

^

sketch_nov01a:72: error: 'analogRead' was not declared in this scope

readValue = analogRead(A0);

^

C:\Users\GHAFOO~1.SAM\AppData\Local\Temp\arduino_modified_sketch_313829\sketch_nov01a.ino: In function 'float getvoltage()':

sketch_nov01a:99: error: 'millis' was not declared in this scope

uint32_t start_time = millis();

^

sketch_nov01a:102: error: 'A0' was not declared in this scope

readValue = analogRead(A0)

^

sketch_nov01a:102: error: 'analogRead' was not declared in this scope

readValue = analogRead(A0)

^

exit status 1
'A0' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Samadi:
exit status 1
'A0' was not declared in this scope

You have a completely different problem than the OP, it just happens to cause the same error message. So there's no point in discussing it further in this thread, let's use the dedicated thread you created instead:
http://forum.arduino.cc/index.php?topic=508904