i have a program and it works, but insted of contact1pin, I want to youse the hallsenor magic switch KY-003, but if I delete contctpin1 and put in the hall sensor it doesn't work.
how do I program it so I can youse the high and low?
i have try to do this
// Defined pin-numrene for motorerne and concact
const int motor1ForwardPin = 2;
const int motor1BackwardPin = 3;
const int motor2Pin = 4;
const int contact2Pin = 6;
const int enA = 7;
const int enB = 8;
const int motor2pinback = 7;
const int hallsensorpin = 9;
int halldigital;
void setup() {
// put pin-mode for motorer og contact
pinMode(motor1ForwardPin, OUTPUT);
pinMode(motor1BackwardPin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(contact2Pin, INPUT_PULLUP);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(motor2pinback, OUTPUT);
pinMode(hallsensorpin, INPUT) ;
// motor 1 forward, until contact 1 hits
int halldigital = digitalRead(hallsensorpin);
while (digitalRead(halldigital) == LOW) {
digitalWrite(motor1ForwardPin, HIGH);
digitalWrite(motor1BackwardPin, LOW);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor2pinback, LOW);
digitalWrite(enA, HIGH);
digitalWrite(enB, HIGH);
}
// motor 1 drivning bag until concact 2 har hit
while (digitalRead(contact2Pin) == LOW) {
digitalWrite(motor1ForwardPin, LOW);
digitalWrite(motor1BackwardPin, HIGH);
}
// Stop motor 1 and 2 when contact 2 are push
digitalWrite(motor1ForwardPin, LOW);
digitalWrite(motor1BackwardPin, LOW);
digitalWrite(motor2Pin, LOW);
}
void loop() {
}```
this program works with the contact1pin.
// Defined pin-numrene for motorerne and concact
const int motor1ForwardPin = 2;
const int motor1BackwardPin = 3;
const int motor2Pin = 4;
const int contact1Pin = 5;
const int contact2Pin = 6;
const int enA = 7;
const int enB = 8;
const int motor2pinback = 7;
void setup() {
// put pin-mode for motorer og contact
pinMode(motor1ForwardPin, OUTPUT);
pinMode(motor1BackwardPin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(contact1Pin, INPUT_PULLUP);
pinMode(contact2Pin, INPUT_PULLUP);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(motor2pinback, OUTPUT);
// motor 1 forward, until contact 1 hits
while (digitalRead(contact1Pin) == LOW) {
digitalWrite(motor1ForwardPin, HIGH);
digitalWrite(motor1BackwardPin, LOW);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor2pinback, LOW);
digitalWrite(enA, HIGH);
digitalWrite(enB, HIGH);
}
// motor 1 drivning bag until concact 2 har hit
while (digitalRead(contact2Pin) == LOW) {
digitalWrite(motor1ForwardPin, LOW);
digitalWrite(motor1BackwardPin, HIGH);
}
// Stop motor 1 and 2 when contact 2 are push
digitalWrite(motor1ForwardPin, LOW);
digitalWrite(motor1BackwardPin, LOW);
digitalWrite(motor2Pin, LOW);
}
void loop() {
}