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
checked, the motor and the button is wired correctly
... how do you know?LOW
when the button is released so it is very vulnerable to noise. You should put a pulldown resistor of around 10K Ohms between pin 49 and ground to make the button more reliable.