user63723: I am using an Arduino Atmega2560 clone, I have used it many times before with satisfactory results - although I haven't used it with my Rpi before.
My Raspberry Pi is model 4 (B I think?).
#define knap 49
#define motorOutput 8

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(knap, INPUT);
  pinMode(motorOutput, OUTPUT);
  digitalWrite(motorOutput, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  int knapSensor = digitalRead(knap);
  Serial.print(knapSensor);
  if (knapSensor == 1) {
    int knapSensor = digitalRead(knap);
    Serial.print("aktiveret");
    digitalWrite(motorOutput, HIGH);
    delay(500);
    digitalWrite(motorOutput, LOW);
  }
}

Now I have double checked, the motor and the button is wired correctly. There is no hardware issue, aside from the cables being sh- quality.
Problem is, whenever I run this program two things will happen;
Either it starts fine by displaying "0000..." on the serial monitor.
Then when I press the button it goes to
"AktiveretAktiveretAktiveret..." even when I depress the button.
Or, it will just display "AktiveretAktiveretAktiveret...".
In either case the motor won't work.
Once again, I have done tests where I have removed the power from the breadboard and replaced the voltage pin for the motor with the voltage pin leading from the button.
First thing didn't change the input (i.e still "AktiveretAktiveret,") the latter started the motor.
I.e this isn't about bad wiring.
EDIT:
Added schematics and changed the code


user71133: What motor are you using? If it works straight from the 5v but not from a GPIO, it could be an issue of insufficient power.
As @StarCat4 mentioned, you also need to add a digitalRead inside your while loop if you want the motor to ever turn off.

user62523: Your button needs a pulldown resistor to work reliably.
See the discussion and solution here
The resistor, with a value of around 10K (but any value between 3K and 20K will probably do), needs to be between the input pin or your Arduino and ground to give it a defined value when the button is released.
Putting a resistor between the Arduino pin and ground will make sure the pin reads "low" when no button is pressed. When the button is pressed, it will be connected directly to +5V and will read high. Only a small current (0.5mA) will flow from +5V to ground through the 10K Ohm resistor in that case. It will not create a short circuit.

63723: <p>I am using an Arduino Atmega2560 clone, I have used it many times before with satisfactory results - although I haven't used it with my Rpi before.</p>
<p>My Raspberry Pi is model 4 (B I think?).</p>
<pre class="lang-cpp prettyprint-override"><code>#define knap 49
#define motorOutput 8

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(knap, INPUT);
  pinMode(motorOutput, OUTPUT);
  digitalWrite(motorOutput, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  int knapSensor = digitalRead(knap);
  Serial.print(knapSensor);
  if (knapSensor == 1) {
    int knapSensor = digitalRead(knap);
    Serial.print(&quot;aktiveret&quot;);
    digitalWrite(motorOutput, HIGH);
    delay(500);
    digitalWrite(motorOutput, LOW);
  }
}
</code></pre>
<p>Now I have double checked, the motor and the button is wired correctly. There is no hardware issue, aside from the cables being sh- quality.</p>
<p>Problem is, whenever I run this program two things will happen;</p>
<p>Either it starts fine by displaying &quot;0000...&quot; on the serial monitor.</p>
<p>Then when I press the button it goes to
&quot;AktiveretAktiveretAktiveret...&quot; even when I depress the button.</p>
<p>Or, it will just display &quot;AktiveretAktiveretAktiveret...&quot;.</p>
<p>In either case the motor won't work.</p>
<p>Once again, I have done tests where I have removed the power from the breadboard and replaced the voltage pin for the motor with the voltage pin leading from the button.</p>
<p>First thing didn't change the input (i.e still &quot;AktiveretAktiveret,&quot;) the latter started the motor.</p>
<p>I.e this isn't about bad wiring.</p>
<p>EDIT:</p>
<p>Added schematics and changed the code</p>
<p><a href="https://i.stack.imgur.com/nLmBu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nLmBu.png" alt="enter image description here" /></a></p>
 71133: <p>What motor are you using? If it works straight from the 5v but not from a GPIO, it could be an issue of insufficient power.</p>
<p>As @StarCat4 mentioned, you also need to add a digitalRead inside your while loop if you want the motor to ever turn off.</p>
 62523: <p>Your button needs a pulldown resistor to work reliably.</p>
<p><a href="https://forum.arduino.cc/index.php?topic=378402.0" rel="nofollow noreferrer">See the discussion and solution here</a></p>
<p>The resistor, with a value of around 10K (but any value between 3K and 20K will probably do), needs to be between the input pin or your Arduino and ground to give it a defined value when the button is released.</p>
<p>Putting a resistor between the Arduino pin and ground will make sure the pin reads &quot;low&quot; when no button is pressed. When the button is pressed, it will be connected directly to +5V and will read high. Only a small current (0.5mA) will flow from +5V to ground through the 10K Ohm resistor in that case. It will not create a short circuit.</p>
