-1

I think the below logic should work but its throwing error

void setup() {
  Serial.begin(9600);
}

void loop() {
  int soil_moisture = analogRead(A0); // read from analog pin A3
//  int soil_moisture = pinMode(AO);
  Serial.print(“analog value: “);
  if (soil_moisture < 30) {
    Serial.println(“Dry soil”);
  }
  if ((soil_moisture > 300) && (soil_moisture < 700)) {
    Serial.println(“Humid soil”);
  }
  if ((soil_moisture > 700) && (soil_moisture < 950)) {
    Serial.println(“water”);
  }
}

error i get is

Arduino: 1.6.12 (Mac OS X), Board: "Arduino/Genuino Uno"

analog_soil_moisture_v02.ino:16: error: stray '\342' in program
   Serial.print(“analog value: “);
   ^
analog_soil_moisture_v02.ino:16: error: stray '\200' in program
analog_soil_moisture_v02.ino:16: error: stray '\234' in program
analog_soil_moisture_v02.ino:16: error: stray '\342' in program
analog_soil_moisture_v02.ino:16: error: stray '\200' in program
analog_soil_moisture_v02.ino:16: error: stray '\234' in program
analog_soil_moisture_v02.ino:18: error: stray '\342' in program
     Serial.println(“Dry soil”);
     ^
analog_soil_moisture_v02.ino:18: error: stray '\200' in program
analog_soil_moisture_v02.ino:18: error: stray '\234' in program
analog_soil_moisture_v02.ino:18: error: stray '\342' in program
analog_soil_moisture_v02.ino:18: error: stray '\200' in program
analog_soil_moisture_v02.ino:18: error: stray '\235' in program
analog_soil_moisture_v02.ino:21: error: stray '\342' in program
     Serial.println(“Humid soil”);
     ^
analog_soil_moisture_v02.ino:21: error: stray '\200' in program
analog_soil_moisture_v02.ino:21: error: stray '\234' in program
analog_soil_moisture_v02.ino:21: error: stray '\342' in program
analog_soil_moisture_v02.ino:21: error: stray '\200' in program
analog_soil_moisture_v02.ino:21: error: stray '\235' in program
analog_soil_moisture_v02.ino:24: error: stray '\342' in program
     Serial.println(“water”);
     ^
analog_soil_moisture_v02.ino:24: error: stray '\200' in program
analog_soil_moisture_v02.ino:24: error: stray '\234' in program
analog_soil_moisture_v02.ino:24: error: stray '\342' in program
analog_soil_moisture_v02.ino:24: error: stray '\200' in program
analog_soil_moisture_v02.ino:24: error: stray '\235' in program
/Users/ciastro/Documents/Arduino/analog_soil_moisture_v01/analog_soil_moisture_v02.ino/analog_soil_moisture_v02.ino.ino: In function 'void loop()':
analog_soil_moisture_v02.ino:16: error: 'analog' was not declared in this scope
   Serial.print(“analog value: “);
                   ^
analog_soil_moisture_v02.ino:18: error: 'Dry' was not declared in this scope
     Serial.println(“Dry soil”);
                       ^
analog_soil_moisture_v02.ino:21: error: 'Humid' was not declared in this scope
     Serial.println(“Humid soil”);
                       ^
analog_soil_moisture_v02.ino:24: error: 'water' was not declared in this scope
     Serial.println(“water”);
                       ^
exit status 1
stray '\342' in program

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

It is because you declared NONE of your variables (int, floats) (except soil_moisture)

You must declare them. This is not Python where you can simply name a variable without declaring its type. Arduino language is based on C/C++.

3
  • 1
    Where did you get that Arduino language comes from JavaScript? I have known C and C++ for over 20 years, JavaScript for about 10 years and I don't see where Arduino language could be based on the latter.
    – jfpoilpret
    Oct 22 '16 at 16:20
  • My bad, its Java (not JavaScript). It's actually the function printf() from Java which translates to Serial.print(F())
    – Dat Ha
    Oct 22 '16 at 18:53
  • 1
    printf is initially a standard C function, long before Java.
    – jfpoilpret
    Oct 22 '16 at 18:55
3

The actual error you are seeing is caused by the use of incorrect quotes in your program. You most likely copied and pasted the code from a website which has replaced the proper quotes with typeset-standard quotes:

    Serial.println(“Humid soil”);

should be:

    Serial.println("Humid soil");

Note the subtle difference in the quite shape. The first set are typesetter's open- and close-quote characters. The latter are just plain double-quotes (shift-2 on a UK keyboard).

There are other special characters in your program that need replacing with the standard ASCII equivalent, as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.