-1

im working on project which include using of motors and a float switch im getting an error message which expected '}' at end of input . i cant find where should i correct it, btw im putting a float switch at the first of the coding (which on top) and im getting and error, but when i remove the float switch function coding, its running well without any error. so how can i put this switch to it become functional? here is the coding;

int motorPin = 4; // pin that turns on the motor
int blinkPin = 9; // pin that turns on the LED
int lamp1 = 5;// lampu pape
int motorklorin = 3;// isi klorin
int switch1 = 2;// switch float
void setup()
{
  pinMode(motorPin, OUTPUT); 
  pinMode(blinkPin, OUTPUT); // set pin 13 to an output so we can use it to turn on the LED
  pinMode(lamp1, OUTPUT);
  pinMode(motorklorin, OUTPUT); // MOTOR UNTUK ISI KLORIN
  pinMode(switch1, INPUT_PULLUP);// PELAMPONG
}


void loop()
{
if(digitalRead(switch1) == HIGH)
{
  digitalWrite(motorklorin, LOW);
}
else
{
  digitalWrite(motorklorin, HIGH);
  delay(2000);
  }
{
  digitalWrite(motorPin, HIGH); // turn on the motor
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(lamp1, HIGH);// on lampu
  delay(2000);        // multiply by 1000 to translate seconds to milliseconds

  digitalWrite(motorPin, LOW);  // turn off the motor
  digitalWrite(blinkPin, LOW);  // turn off the LED
  digitalWrite(lamp1, HIGH);// motor 1 jalan (air start turun)
  delay(2000);        // multiply by 60000 to translate minutes to milliseconds

  digitalWrite(motorPin, HIGH); // turn on the motor (motorisi balik air jalan)
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(lamp1, LOW);// on lampu
  delay(5000);        // multiply by 1000 to translate seconds to milliseconds



  digitalWrite(motorPin, HIGH);  // turn off the motor
  digitalWrite(blinkPin,HIGH);  // turn off the LED
  digitalWrite(lamp1, HIGH);// OFF LAMPU semua motor stop
  delay(1000);        // multiply by 60000 to translate minutes to milliseconds
  }

closed as off-topic by gre_gor, sempaiscuba, Greenonline, per1234, Juraj Jul 19 '18 at 8:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – gre_gor, sempaiscuba, Greenonline, per1234, Juraj
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    expected '}' at end of input” seems quite self-explanatory to me. What do you not understand about it? – Edgar Bonet Jul 16 '18 at 8:41
  • 1
    It's as simple as counting. Use your fingers if you need to, even your toes if you nest that deep. – Ignacio Vazquez-Abrams Jul 16 '18 at 8:43
  • 1
    The code above contains 5 {s and 6 }s. The numbers should match. – Gerben Jul 16 '18 at 9:03
  • actually i didn't know how to fix it – Asrul Asyraff Jul 16 '18 at 9:49
3

There is an extra { right after your else{} statement. Delete this and the code should compile.

  • Alright bro, thanks for the guide now finally i can compile the code. – Asrul Asyraff Jul 17 '18 at 8:27
  • If that is the case, please accept the answer. – MichaelT Jul 17 '18 at 8:36
2

I cover this error and how to diagnose it in a blog post. Here it is quoted for posterity:


A common problem, and one that can cause a new programmer to pull their hair out.

However, it's a problem that always has a simple solution, and with the right tricks it's also easy to find where the problem lies.

Let's take the following little code snippet, which throws up this exact error:

byte i = 0;

void doSomething() {
  digitalWrite(3, LOW);
}

void doSomethingElse() {
  digitalWrite(13, HIGH);
}

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (i == 1) {
    doSomething();
  i++;
}

At first glance that all looks perfectly good. But you compile, and you get:

/home/matt/Arduino/ErrorTest/ErrorTest.ino: In function 'void loop()':
ErrorTest:21: error: expected '}' at end of input
 }
 ^
exit status 1
expected '}' at end of input

Line 21, of course, is the last line of the file. And the error is pretty explicit - it expects a } at the end of the file. However, there is plainly one there already. So what is it on about?

Simply put, there aren't enough } to balance out the number of { in the file. For every { there must be a } to go with it. On this little file it's easy to just go through and count them all. Add one for a { and subtract one for a }. If the answer is not 0 then there's something wrong. But it can take careful looking to see where the missing one should be, and even I have spent hours going cross-eyed trying to find the location in a big project.

There is one little trick, though, that can help you: Auto Format. The Auto Format facility in both the Arduino IDE and UECIDE (and many other IDEs as well) will sort out your indenting for you according to the presence of (amongst other things) { and }.  If the brackets don't match up the formatting would end up wrong.

So let's pass this little program through the auto formatting and see what happens:

byte i = 0;

void doSomething() {
  digitalWrite(3, LOW);
}

void doSomethingElse() {
  digitalWrite(13, HIGH);
}

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (i == 1) {
    doSomething();
    i++;
  }

As you can see the loop() function's indenting has changed. And if your eyes are sharp enough you'll already see what was wrong. The "if", which had an opening bracket, didn't have a closing one. The "i++" was supposed to be outside the "if" (as can be seen by the original indenting), but actually it wasn't, and the end of the function was really the end of the "if", leaving the function unfinished.

So fixing it is now really easy. By auto formatting we can see where the imbalance occurs, and fix it:

void loop() {
  // put your main code here, to run repeatedly:
  if (i == 1) {
    doSomething();
  }
  i++;
}

And now it compiles. But of course that little snippet doesn't actually do anything useful...

  • Oh okay i noticed it. thank you so much for your guide – Asrul Asyraff Jul 17 '18 at 8:26
-3

You missed the last ending curly bracket for a void loop();

int motorPin = 4; // pin that turns on the motor
int blinkPin = 9; // pin that turns on the LED
int lamp1 = 5;// lampu pape
int motorklorin = 3;// isi klorin
int switch1 = 2;// switch float
void setup()
{
  pinMode(motorPin, OUTPUT); 
  pinMode(blinkPin, OUTPUT); // set pin 13 to an output so we can use it to turn on the LED
  pinMode(lamp1, OUTPUT);
  pinMode(motorklorin, OUTPUT); // MOTOR UNTUK ISI KLORIN
  pinMode(switch1, INPUT_PULLUP);// PELAMPONG
}


void loop()
{
if(digitalRead(switch1) == HIGH)
{
  digitalWrite(motorklorin, LOW);
}
else
{
  digitalWrite(motorklorin, HIGH);
  delay(2000);
  }
{
  digitalWrite(motorPin, HIGH); // turn on the motor
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(lamp1, HIGH);// on lampu
  delay(2000);        // multiply by 1000 to translate seconds to milliseconds

  digitalWrite(motorPin, LOW);  // turn off the motor
  digitalWrite(blinkPin, LOW);  // turn off the LED
  digitalWrite(lamp1, HIGH);// motor 1 jalan (air start turun)
  delay(2000);        // multiply by 60000 to translate minutes to milliseconds

  digitalWrite(motorPin, HIGH); // turn on the motor (motorisi balik air jalan)
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(lamp1, LOW);// on lampu
  delay(5000);        // multiply by 1000 to translate seconds to milliseconds



  digitalWrite(motorPin, HIGH);  // turn off the motor
  digitalWrite(blinkPin,HIGH);  // turn off the LED
  digitalWrite(lamp1, HIGH);// OFF LAMPU semua motor stop
  delay(1000);        // multiply by 60000 to translate minutes to milliseconds
}
}

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