I have a middle school student who is having problems getting her pollution sensor to work when asked to. I have attached her document to this post. Can anyone help her fix the issue?
int conductivitySensorValue; //initialize an integer variable to hold the sensor reading
void setup() {
Serial.begin(9600); //start serial communications so we can print the reading out
}
void loop() {
conductivitySensorValue = analogRead(A0); //gat the integer representation of the sensor reading
float voltage = conductivitySensorValue*(5.0/1023.0); //put the data in terms of our voltage (5 volts)
Serial.println("The Conductivity is" + voltage); //print the current reading to the serial port
}
Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\sushmit\Documents\Arduino\sketch_apr19a\sketch_apr19a.ino: In function 'void loop()':
sketch_apr19a:13: error: invalid operands of types 'const char [20]' and 'float' to binary 'operator+'
Serial.println("The Conductivity is" + voltage); //print the current reading to the serial port
^
exit status 1
invalid operands of types 'const char [20]' and 'float' to binary 'operator+'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
End copy.......
Serial.println("The Conductivity is" + String(voltage));works and is readable, though there's more efficient ways with lower level code. – dandavis Apr 21 '17 at 08:09