Expected "}" at end of input

im following this guys tutorial on youtube but when I copy his code it doesn't work for me but does for him

here's the code:

int switchPin = 8;
int ledPin = 13;

void setup() 
{
 pinMode(switchPin, INPUT);
 pinMode(ledPin, OUTPUT);
}

void loop() 
{
  if (digitalRead(switchPin) == HIGH)
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  } // <----- this is the problem

You failed to copy all his code. Add a } at the end, and all will be well.

Your topic was moved to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

It will help you get the best out of the forum in the future.

Thank you

In fact, you (and he) have too much code.

void loop() 
{
    digitalWrite(ledPin, digitalRead(switchPin));
}

In fact, you (and he) have too much code along with a missing closing brace ( } ).

See post #2

Question was answered. Why continue, I doubt the OP is even around to see this, he's back to watching YouTuber.

OP had not yet acknowledged?

They often don't.

I’m reading all the answers I’m a beginner I don’t know anything about arduino so that’s why I’m watching youtubers

Do you know what {} are for and that an { needs a } to close it? Count your {s and your }s divide by 2

The below will keep you right

1 Like

Then I apologize, you are atypical, though you should acknowledge things that have solved your immediate ask.
C

Maybe OP is caredully learning how to get it right, but has to sift through grumpy posts that contribute nothing?

No grumping, here, buddy, just pointing out typical etiquette on the forum. As a newbie, he may not be aware.
You're assuming something that isn't there.
C

1 Like

You fail to understand "observation" versus "assumption." See post #6.

How do I do that

Don't worry about it. The thread is only six hours old and some are assuming that you've wandered off never to be seen again.

I wouldn't have worriedfor a day or two, then might request that you say something, anything at all, to indicate your presence and continued internet in the problem you brought here.

Actually I wouldn't worry at all. ppl ghost us here alla time.

a7

1 Like

@danieldacheff

Do you know what this pair of braces ( {} ) are for and that an opening brace ( { ) needs a closing brace ( } ) to close it? Count your number of opening braces ( { ) and your number of closing braces ( } ) an then divide by 2 to get no remainder. For example:

void setup()
{

}

void loop()
{

}

Number of opening braces ( { ) is 2.
Number of closing braces ( } ) is 2.
(2 + 2)/2 = 2 + 0 (the remainder).

There's a bit more to it. Braces come in matching pairs, every open brace is matched to a closing brace and you can't just count them to see if you've got the syntax correct.

void setup()
}

}

void loop()
{

{

Correct by counting and dividing, not all all correct code.

a7

void setup()
{

void loop()
{

}

}

No remainder.
Hmmm.

Let's see. You asked what was wrong with the code you posted. I pointed out a missing "}". If that addressed your question, a simple "thanks, that fixed it" would have sufficed. Instead, as you can see, the usual thread drift has occurred.
It doesn't matter, really, you have your answer.
C