"expected unqualified-id before numeric constant"

Hey everyone, ive tried searching, but havent found anything helpful

basically i just got my arduino yesterday, and ive done some simple LED pattern stuff. i tried to do the project in the “getting started with arduino book” through MAKE that was where you press a button, and the LED lights up.

i typed up the code myself, and there are no other problems with it. i had typed out the code so that if i pressed the button, it did a certain pattern; but i removed that and made it just turn on like the project in the book (over complicating it was what i predicted my problem to

still, it gives me a message that says “error- expected unqualified-id before numeric constant” and it highlights my line that is

#define BUTTON 4

i have no clue what to do, im just new to this, go easy…

heres my code. (the extra LEDs were used in the more complicated version, but this exact code will not work)

#define LED 13
#define LED1 12
#define LED2 11
#define LED3 10
#define LED4 9
#define LED5 8
#define LED6 7
#define LED7 6
#define BUTTON 4

int val = 0

void setup()
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(BUTTON, INPUT);

void loop(){
  val = digitalRead(BUTTON);

  if (val == HIGH) {
  digitalWrite(LED, HIGH);
  } else {
  digitalWrite(LED, LOW);


gotta love my idiocy, i found the problem, i missed the ";" after the "0" in the int line.

Just one thing:

 val = digitalRead(BUTTON);

 if (val == HIGH) {
  digitalWrite(LED, HIGH);
  } else {
  digitalWrite(LED, LOW);

If "val" is not "==HIGH", it is "==LOW" hence:

val = digitalRead(BUTTON);
digitalWrite(LED, val);


And if val is not needed elsewhere it can be removed completely :wink:

  digitalWrite(LED, digitalRead(BUTTON));

Hard to de-bounce the button that way, if that's important.

sorry guys im confused, can you dumb that down for me?

apparently this was supposed to let the button turn it on and off, but it only turns it on, and to turn it off i have to reset the board. any help?

but it only turns it on, and to turn it off i have to reset the board. any help?

Sounds like a wiring problem with your switch, having a “floating input” when the switch is released. Search around here for pull-ups, pull-downs, and enabling pin software pull-ups. Show us how your switch is wired to the input pin.


The code, as you wrote it, will turn the LED on when the button is pushed, and turn it off when the button is not pushed.

This assumes, of course, that you are using the standard momentary contact pushbutton switch, and that the switch is wired correctly.

Groove's comment was about the fact that the digitalRead function returns either HIGH or LOW, which are the same values that digitalWrite expects as input arguments. So, it is not necessary to test whether the value is HIGH or LOW, if all you are going to do is then pass the value to digitalWrite.

Udo was pointing out that it isn't even necessary to store the value from digitalRead. The function call itself can be use in place of the variable that is normally passed to digitalWrite.

My comment was that switches bounce, and debouncing is sometimes required. Without capturing the output from digitalRead, and evaluating it, you can not do the debouncing.

In your simple case, that is not necessary.

im sorry, im completely lost, i guess im trying to move too quickly..

i guess im trying to move too quickly..

Possibly so. The Arduino does not come with a user pushbutton (not counting the reset switch, which can only reset the chip), so how did you wire up your switch? Did you use an example posted somewhere? Lets get the physical switch wiring correct first and then deal with any remaining software issues.


i got it to work now, sorry to waste space on the forum.

You're not the 1st person to have these kind of problems, and won't be the last. The information exchanged when a newbie has problems is useful for other newbies having the same problems.

It helps those of us that have been programming for a while remember that what comes easily (now) to us is as a result of years of practice, and serves as a reminder that the answers we give need to be in easy to understand terms.

So, don't consider your posting as a waste of space on the forum.

What did you need to do to "get it working"?

i typed in the wrong code, i typed in a code for a different project than the one i was wanting.

im having a problem with a much more complex project, that as far as i know im doing everything right except im confused about the wiring of a button.

should i post that here or start a new thread?

Start a new thread, with appropriate title.