could somebody correct my code

Could somebody correct my code.
it gives a error message when I verify stating
expected unqualified ID before `{` token
Thank you
/*
#####################################################################################
# File: Arduino_Watering_sustem.ino
# Processor: Arduino UNO, MEGA ou Teensy++ 2.0
# Language: Wiring / C /Processing /Fritzing / Arduino IDE
#
# Objectives: Watering System - Irrigation
#
# Behavior: When the soil is dry,
#
#
#
# Author: Marcelo Moraes
# Date: 12/10/12
# place: Brazil, Sorocaba City
#
#####################################################################################

This project contains public domain code.
The modification is allowed without notice.

*/

// libraries definition
#include <Wire.h>
#include <LiquidCrystal_I2C.h>




// frequency musical notes
#define NOTE_C6 1047
#define NOTE_C3 131
#define NOTE_G3 196

// pins definition
int levelSensorPin = 0;
int moistureSensorPin = 1;
int audioPin = 2;
int soggyLEDPin = 3;
int moistsoilLEDPin = 4;
int drysoilLEDPin = 5;
int pumpLEDPin = 6;
int pumpPin = 7;

// variables
int levelSensorValue; // stores the level sensor values
int moistureSensorValue; // stores the moisture sensor values
int j = 0;

// system messages
const char *string_table[] =
{
" Welcome! =)",
" Tank LOW level",
" Dry soil",
" Moist soil",
" Soggy soil",
"The water pump is on",
" ArduinoByMyself",
" Watering System",
" Please wait!"
};

// objects definition

LiquidCrystal_I2C lcd(0x27,20,4);


void setup(){
// serial initialization
Serial.begin(9600);

// LCD initialization
lcd.init();
lcd.backlight(); // with Backlight
lcd.clear(); // clearscreen

// Wire initialization
Wire.begin();
}
{
// Arduino pins initalization
pinMode(audioPin, OUTPUT);
pinMode(soggyLEDPin, OUTPUT);
pinMode(moistsoilLEDPin,OUTPUT);
pinMode(drysoilLEDPin,OUTPUT);
pinMode(pumpLEDPin,OUTPUT);
pinMode(pumpPin,OUTPUT);

// LCD initial messages
lcd.clear();
lcd.setCursor(0,0);
lcd.print(string_table[6]);
lcd.setCursor(0,1);
lcd.print(string_table[7]);
lcd.setCursor(0,3);
lcd.print(string_table[0]);
// initialization delay
delay(5000);
}


void loop(){




// reads the sensors
levelSensorValue = analogRead(levelSensorPin);
moistureSensorValue = analogRead(moistureSensorPin);

// if low water level: plays the low level alarm
if(levelSensorValue > 600){
// system messages
lcd.clear();

lcd.setCursor(0,3);
lcd.print(string_table[1]);
// plays the alarm sound
for(int i=0;i<2;i++){
tone(audioPin, NOTE_G3, 200);
delay(200);
tone(audioPin, NOTE_C3, 200);
delay(200);
noTone(audioPin);
}
}

// check the moisture range
if(moistureSensorValue >= 700){
// in case of dry soil:
// system messages
lcd.clear();

lcd.setCursor(0,3);
lcd.print(string_table[2]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,HIGH);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,LOW);
// plays the alarm sound
tone(audioPin, NOTE_C6, 100);
delay(250);
noTone(audioPin);
}
if((moistureSensorValue < 700) && (moistureSensorValue >= 300)){
// in case of moist soil:
// system messages
lcd.clear();

lcd.setCursor(0,3);
lcd.print(string_table[3]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,HIGH);
digitalWrite(soggyLEDPin,LOW);
delay(250);
}
if(moistureSensorValue < 300){
// in case of soggy soil:
// system messages
lcd.clear();

lcd.setCursor(0,3);
lcd.print(string_table[4]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,HIGH);
delay(100);
}

// if the soil is dry and if it is the right time: turn on the pump for 1 minute
{
while(moistureSensorValue >= 700){
// system messages
lcd.clear();

lcd.setCursor(0,1);
lcd.print(string_table[8]);
lcd.setCursor(0,3);
lcd.print(string_table[5]);
// turn the pump on
digitalWrite(pumpPin,HIGH);
digitalWrite(pumpLEDPin,HIGH);
delay(10000);
// if the soil is not moist so far
// reads the moisture sensor once more
moistureSensorValue = analogRead(moistureSensorPin);
}
// turn the pump off
digitalWrite(pumpPin,LOW);
digitalWrite(pumpLEDPin,LOW);
}

[/code]
Last edited on
The arduino doesn't use vanilla C++, though it is very similar. You can use some generic troubleshooting techniques with short code like this, don't forget you can cut code out and paste it back in at will.

If the IDE tells you there is an issue, normally they're nice enough to tell you what line it's on- I don't know if the arduino IDE allows initialization of your string array or if it allows the block without an identifier directly after your setup function, my guess is it's the blank {} after your setup.
Thank you very much for the reply. but I still couldn`t get it right
Topic archived. No new replies allowed.