I need Help in Setting a Soil Moisture Sensor

Hey everyone, I have a project due soon and I decided I would make a soil moisture sensor that lights a led to show if the moisture is good, now I want to add this [int percentagemoisture = map(moisture, 1024, 0, 0, 100);] to the code below but when I upload it it says primary expression expected before the ? token, how can I add the above integer to show as percentage?

//soil moisture sensor
const int soilpin=A0;
int ledsoil=13;
void setup()
 {
  Serial.begin(9600);
  pinMode(ledsoil,OUTPUT);


}

void loop()
 {
  int moisture=analogRead(soilpin);
  Serial.println(moisture);
  if(moisture>1000)
  {
    digitalWrite(ledsoil,HIGH);
    delay(100);
  }
else
{
  digitalWrite(ledsoil,LOW);
  delay(100);
}
}

if anyone needs the new code

//soil moisture sensor
const int soilpin=A0;
int ledsoil=13;
void setup()
 {
  Serial.begin(9600);
  pinMode(ledsoil,OUTPUT);
  Serial.println("Reading From the Sensor ...");
  delay(2000);
}

void loop()
 {
  int moisture=analogRead(soilpin);
  int percentagemoisture = map(moisture, 0,1023, 0, 100);
  Serial.print("percentagemoisture: ");
  Serial.print(percentagemoisture);
  Serial.println("%");
  if(moisture>700)
  {
    digitalWrite(ledsoil,HIGH);
    delay(1000);
  }
else
{
  digitalWrite(ledsoil,LOW);
  delay(1000);
}
}

Initialise soilpin as an INPUT

tasmod:
Initialise soilpin as an INPUT

I already Solved that problem,but can you help me with the one above???

this compiles:

//soil moisture sensor
const int soilpin=A0;
int ledsoil=13;
void setup()
 {
  Serial.begin(9600);
  pinMode(ledsoil,OUTPUT);


}

void loop()
 {
  int moisture=analogRead(soilpin);
  int percentagemoisture = map(moisture, 0,1023, 0, 100);
  Serial.print("moisture: ");
  Serial.println(moisture);
  Serial.print("percentagemoisture: ");
  Serial.println(percentagemoisture);
  if(moisture>1000)
  {
    digitalWrite(ledsoil,HIGH);
    delay(100);
  }
else
{
  digitalWrite(ledsoil,LOW);
  delay(100);
}
}

hope that helps

sherzaad:
this compiles:

//soil moisture sensor

const int soilpin=A0;
int ledsoil=13;
void setup()
{
  Serial.begin(9600);
  pinMode(ledsoil,OUTPUT);

}

void loop()
{
  int moisture=analogRead(soilpin);
  int percentagemoisture = map(moisture, 0,1023, 0, 100);
  Serial.print("moisture: ");
  Serial.println(moisture);
  Serial.print("percentagemoisture: ");
  Serial.println(percentagemoisture);
  if(moisture>1000)
  {
    digitalWrite(ledsoil,HIGH);
    delay(100);
  }
else
{
  digitalWrite(ledsoil,LOW);
  delay(100);
}
}




hope that helps

Thank you, it did work, however I have one last question, how hard is it to add an LCD to this

how hard is it to add an LCD to this

very similar question as "how long is a piece of string?"

DeanWin1:
Thank you, it did work, however I have one last question, how hard is it to add an LCD to this

Going to depend a bit on what kind of LCD you are going to use, since displays can be directly driven by the Arduino board, or use other interfaces such as I2C or SPI.

Here is some example code and how to connect an LCD display, get it working then adapt your code to display to the LCD.