Hello again folks,
My cogs, and sensors have arrived. I'm using 2 Nema 17's and an Arduino Uno shield v3. I've hooked up a HC-SR501 motion sensor (to detect motion and start moving the gears) to X+ end stop pin and a Hall sensor (to stop the motors) to the Z+ end stop pin of the shield.
I'm making a hidden large disk ( 3 or 4 times bigger than the larger gearwheel) that will have 7-8 magnets on it. Each magnet for one stop to last 3 minutes.
I have never used this hardware set up so I have 2 questions Please:
-
I'm using the sensors with Arduino's 5v, without any resistors and not as PULL_UP. It works but I'd like to know if that's the correct way.
-
I find myself with the Hall effect magnet triggered at power up. Check the PIR
sensor for presence, if yes, move one step at a time until I hit a magnet, then
stop for a couple of minutes. Then check the PIR sensor again, if no presence
then just stay where I am, else move to the next magnet.
I've written some code, it detects presence, moves away from the magnet on start but will not move anymore since the Hall effect sensor is triggered. Where am I goofing ?
const int stepX = 2; // X.STEP
const int stepZ = 4; // Z.STEP
const int MoveSens = 9; // HC-SR 501 Movement Sensor (Pin X+)
const int STopSens = 11; // Hall sensore stop (Pin Z+)
void setup() {
Serial.begin(115200);
pinMode(MoveSens, INPUT);
pinMode(STopSens, INPUT);
pinMode(stepX, OUTPUT);
pinMode(stepZ, OUTPUT);
}
void loop() {
int MoveSensVal = digitalRead(9); // value for HC-SR 501 Movement Sensor
if (MoveSensVal == HIGH) {
Move();
int StopSensVal = digitalRead(11); // Value for Hall Effect sensor STOP
if (StopSensVal == HIGH) {
Move();
}
else
delay (10000);
}
}
void Move() {
for (int x = 0; x < 1; x++) {
digitalWrite(stepX, HIGH);
digitalWrite(stepZ, HIGH);
delay(10);
digitalWrite(stepX, LOW);
digitalWrite(stepZ, LOW);
}
}