Trouble with the code of a complete the circuit project

So I am finishing up the final touches of a Christmas present, and of course it has difficulties being complete. Im gonna paste the code and then explain the project

int buzzPin = 3;
int inPin1 = 9; // pushbutton connected to digital pin 7
int inPin2 = 10;
int inPin3 = 6;
int val1 = 0;// variable to store the read value
int val2 = 0;
int val3 = 0;
int phase1=0;
int phase2=1;
int phase3=1;
int count=0;
int ender=0;

void setup()
{
Serial.begin(9600);
pinMode(inPin1, INPUT); // sets the digital pin 7 as input
pinMode(inPin2, INPUT);
pinMode(inPin3, INPUT);
pinMode(buzzPin, OUTPUT);
}

void loop()
{

val1 = digitalRead(inPin1); // read the input pin
val2 = digitalRead(inPin2);
val3 = digitalRead(inPin3);
// Serial.print(inPin1);
// Serial.print(inPin2);
//Serial.print(inPin3);
if((val1==HIGH) && (phase1==0))
{
digitalWrite(buzzPin,HIGH);
phase1=1;
phase2=0;
count++;
}

if(val2==HIGH && phase2==0)
{
digitalWrite(buzzPin,HIGH);
phase2=1;
phase3=0;
count=count+1;
// Serial.print(count);
}
Serial.print(count);
if(val3==HIGH && phase3==0)
{
digitalWrite(buzzPin,HIGH);
phase3=1;
count=count+1;
//Serial.print(count);
ender==1;
}

if(count>=3 && ender==1)
{
Serial.print(count);
for(int i=0;i<=2;i++)
{
digitalWrite(buzzPin,HIGH);
delay(500);
digitalWrite(buzzPin,LOW);
delay(500);
}
ender=2;
}

delay(500);
digitalWrite(buzzPin,LOW);

}

So this is the code for a little game to get to the Christmas present. When the blocks are put in the correct order(b,c,a c,a,b a,b,c) the buzzer will sound 3 times and then I will present them with the code to get into a keypad. Now I am very sure I have all the wiring down correctly. But what is happening in when I plug the arduino in I instantly get a buzz. and non of the combinations work. Is it because of how I am checking for the completion of the circuit?
Thanks!
(and sorry for bare details, I will be watching for any answer immediately )

You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :)

It would also help if you use more descriptive names for your pins and variables. val1, val2, inPin1, inPin2, phase1, phase2 etc mean nothing. Make the names describe their actual purpose.

Edit: Also add comments in your code, explaining what is happening, (or supposed to be happening).

And this won't be doing what you think:-

ender == 1;

Do you mean:-

ender = 1;

int inPin1 = 9; // pushbutton connected to digital pin 7

Are you sure about this? I sense some prevarication.

i copied some code and changed it for my purpose, just didn't change commentation

Hi,
I don’t see a PULLUP in the setup of your sketch.
How have you got the switches wired?
If the switch is between the input and 5V, you will need a 10k resistor from the input to GND, to make sure the input is LOW when the switch is OFF.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks… Tom… :slight_smile:

Byroscope: So this is the code for a little game to get to the Christmas present.

You are really early with preparing Christmas presents for 2016!

Byroscope: Now I am very sure I have all the wiring down correctly.

As your code does not use the internal pull-up resistors with your Atmega controller: Is your wiring in the circuit using external pull-down or external pull-up resistors with the buttons?