First try at Arduino

So this is my first try at Arduino and I'm not geting it to work, I was wondering if something is wrong with this code or if it is the connections to the board

int pushButton = 2;
int led = 9;

void setup() { //Verið að start upp forritinu og skillgreina útgánga og ingánga
Serial.begin(9600); //Hér er skilgreint klukkuhraðan í forritinu
pinMode(pushButton, INPUT); //pushButton skillgreindur sem Input
pinMode(led, OUTPUT); //Led skillgreint sem Output
}

void loop() { //Endalaus loop sem keyrir þetta aftur og aftur eftir skillyrpum sem voru set hérna fyrir
int buttonState = digitalRead(pushButton); //lessið af pushButton
Serial.println(buttonState); //prentar data sem er hægt að lessa
if (pushButton == HIGH){ //Ef pushButton er high
digitalWrite(led, HIGH); //þá led high
delay(1); //Delay
}
else { //Annars led = low
digitalWrite(led, LOW);
delay(1);
}
delay(1);
}

I think the code is correct but I cant find any problems with the board ither :X

Really can't say much about the board as you don't publish a circuit or a photo :slight_smile:

The code does something. You haven’t said what.
You want it to do something. You haven’t said what.
There is, apparently, an LED connected to the board. You haven’t defined how.
There is, apparently, a switch connected to the board. You haven’t said how.

Therefore, we really can’t help you.

The led is connected to pin 9 on the board and I got a pushButton connected to pin 2, the idea is when i push the button the light goes on.

I'm mainly wondering if there is something wrong with the code and if so what it is since I have zero experience with this

An LED has two legs, of different length. Now, we know that one leg is connected to the pin. But, we don't know which one, or where the other one is connected, if anywhere.

A switch has two legs. Now, we know that one leg is connected to the pin. But, we don't know where the other one is connected, if anywhere.

Try again.

So I’m guessing the code is correct hen since your focusing on the board?

The board is connected 5V > Button > 10k > grnd, button > pin 2, then pin 9 > led > 220r > grnd

the led is connected correctly

  if (pushButton == HIGH){

What possible values can pushButton have in your code ? You set it to 2, presumably because a pushbutton is attached to pin 2 and its value never changes. You do read from the pin  int buttonState = digitalRead(pushButton);but you do nothing with the value that has been read into the buttonState variable apart from printing it.

I rather think that the first line of code quoted above should be   if (buttonState== HIGH){ 

That just leaves the hardware to sort out.

So I’m guessing the code is correct hen since your focusing on the board?

Not at all. The hardware needs to be sorted out, first. Without spending the effort that UKHeliBob did looking at your code, there is no way to tell. The thing is that we need some input from you. What is the code doing? You still haven’t said. In the absence of any information, we can only conclude that the software is not playing well with the hardware, so we need to understand what the hardware consists of, before we bother reading the code.

The board is connected 5V > Button > 10k > grnd

It would be simpler to ditch the resistor, and connect the switch (put the button back on your shirt) to the digital pin and ground. Then, enable the internal pullup resistor:
pinMode(pushButton, INPUT_PULLUP);

The HIGH is released and LOW is pressed, just like the top of the switch (assuming that the switch is vertical).