need some help for a buzzer + button

hi, i am new in arduino and programing and i made this :

int pushButton = 2;
int Buzzer = 8;

void setup() {

Serial.begin(9600);

pinMode(pushButton, INPUT);
pinMode(pushButton, OUTPUT);
}

void loop() {

int buttonState = digitalRead(pushButton);

Serial.println(buttonState);
delay(1);
if(buttonState == 1);{
digitalWrite( 8, HIGH);

}
if(buttonState == 0) {
digitalWrite(8, LOW);
}

}
but when i push the button, it doesnt make the buzzer ring

Maybe it has something to do with this:-

pinMode(pushButton, INPUT);
pinMode(pushButton, OUTPUT);

Did you mean:-

pinMode(pushButton, INPUT);
pinMode(Buzzer, OUTPUT);

Edit: And code should always be posted in [code]code tags[/code], not inline.
It's not too late to edit your post and fix this. :wink:

Edit2: Oops, it almost slipped by me. You also need to lose the semicolon at the end of this line:-if(buttonState == 1);
Also, having gone to the trouble of declaring 'Buzzer' as pin 8, it's a good idea to actually use it, to make your code more readable:-digitalWrite(Buzzer, HIGH);instead of:-digitalWrite( 8, HIGH);
And a final point. I see you have the button set up as 'active-high', (hopefully with a pulldown resistor).
It's better (easier) to connect the button between the pin and ground, as 'active-low', then change the code to read the pin as 'pressed' when it's low.
That way, you can do away with the external pulldown resistor and use the internal pullup resistor.
To enable the internal pullup resistor for a pin:-pinMode(pin, INPUT_PULLUP);

following your advices i did that :int pushButton = 2;
int Buzzer = 8;

void setup() {

Serial.begin(9600);

pinMode(pushButton, INPUT);
pinMode(Buzzer, OUTPUT);
}

void loop() {

int buttonState = digitalRead(pushButton);

Serial.println(buttonState);
delay(1);
if(buttonState == 1);{
digitalWrite(Buzzer, HIGH);

}
if(buttonState == 0); {
digitalWrite(Buzzer, LOW);
}

}
but still not working, i guess i've done something wrong

Take a look at my last reply again, regarding this:-if(buttonState == 1);{(I said that you need to lose the semicolon, not also add one to the other 'if' statement. :wink: )

And also the point about code tags. You must use them. Now please edit both of your posts and add them. If unsure, read this:- How to use this forum (Especially item #7.)

Edit: Another small point, although it won't stop your code from working.
For pin allocations, it's better to use 'const byte' rather than 'int':-

const byte pushButton = 2;
const byte Buzzer = 8;

That conserves SRAM space, and ensures that you can't accidentally change the values in your code.

Here's a fixed version of your code, that should work. Read the comments to see why I made some of the changes:-

const byte pushButton = 2;
const byte Buzzer = 8;

void setup()
{
    Serial.begin(9600);

    pinMode(pushButton, INPUT);
    pinMode(Buzzer, OUTPUT);
}

void loop()
{
    bool buttonState = digitalRead(pushButton);    // 'bool' is better than 'int' here - smaller.

//    Serial.println(buttonState);  // I commented this out, because it would result in a constant fast
                                    // stream of serial prints.
//    delay(1);                     // This delay achieves nothing, so I removed it
    if (buttonState == HIGH)
    {
        digitalWrite(Buzzer, HIGH);
    }
    else                            // if (buttonState == 0) // no need for this. 'else' is better here.
    {
        digitalWrite(Buzzer, LOW);
    }
}

There's an even simpler way to write this, but that should do for now.

i think i built the thing wrong so i did it like that http://reboot.yoha.co.uk/images/a/ae/AAC_button_full.jpg, i tried to set the button as analog 5 but it doesnt work, i must be quite anoying

In that circuit, a piezo buzzer is shown. Is your's the same type, or does it have a built-in driver?

If your's has a built-in driver, it will make a sound when connected directly from +5V to ground, (without the 180 ohm resistor). If you get no sound, it's a piezo buzzer with no driver built in.
Make sure you connect in the correct polarity.

If it has no built-in driver, it will need the 'tone()' function to make sounds.

Let me know which type you have, and we'll go from there.

Provided you've fixed the code tag problem by then. You just keep ignoring it. If you ignore it this time, you'll have to hope that someone else comes along to help you.

CathArtic:
Buzzer 5V - Breadboard friendly : ID 1536 : $0.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Ok, now read the last bit of my last post.

You're just plain selfish. You expect people to donate their time helping you with your problem, yet you won't even spend 30 seconds correcting your posts by adding code tags when asked (3 times).
You'll go far here......