Hi everyone.
I am new both to this forum and programming.
I have been building a clock
and rather than wind up the weights by hand every 3 days I have employed a stepper motor, sprocket and chain which is driven by an Arduino uno. The Arduino is activated by 2 hall effect sensors in each of the bottom corners and as a safe guard stopped by 2 read switches in each of the top (sort of top) corners. Each of the weight boxes carry a magnet. The system only requires 1of the hall effect sensors to be triggered. The stepper motor is connect to the main drum via a magnetic clutch. This is necessary as the clock will not function if directly connected so it needs to be able to free wheel.
I have had the program written which appears below.
The system logic is as follows.
- Magnet needs to hover over Hall effect sensors for 10 sec before triggering Arduino.
- Circuit excites magnetic clutch.
- System power to motor for 10 seconds then wait for 5 seconds so clock can recover( its a long story if you know anything about clocks).repeat another 2 times
- cut power.
So far so good except for the magnetic clutch which exhibits backlash after the power is cut. It is turned back around 1/2 by the 16kgs that is resisting with a clunk. This is what i want to eliminate.
I think i need to de-energize the clutch after cutting power to the motor to stop this.
Any suggestions would be appreciated. I have attached a wiring diagram.
//john's comment
int dirpin = 3;
int steppin = 4;
int enable = 5;
int clutch_pin = 2;
int bottomLeft_pin = 8;
int bottomRight_pin = 9;
int Direction;
int Delay;
int tableRows = 13;
int MoveDelay = 1000; //Micro seconds
int MoveSteps = 2000;
int MoveDirection = 0;
int LiftStages = 3;
//LOW FUNCTION
void moveStepper (int Delay, long int steps, int Direction) {
int i;
if (Direction == 0) {
digitalWrite(dirpin, HIGH); // Set the direction.
}
else {
digitalWrite(dirpin, LOW); // Set the direction.
}
for (i = 0; i < steps; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
delayMicroseconds(Delay);
digitalWrite(steppin, HIGH);
delayMicroseconds(Delay); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(dirpin, LOW); // Change direction.
}
void setup() {
Serial.begin(9600);
Serial.setTimeout(500);
// Setup the pins
pinMode(clutch_pin, OUTPUT); //set the clutch pin to be an output
digitalWrite(clutch_pin, LOW); //intitalise the clutch pin to be low (Disabled)
pinMode(dirpin, OUTPUT); // Set up the stepper pins
pinMode(steppin, OUTPUT);
pinMode(enable, OUTPUT);
digitalWrite(enable, HIGH); //intitalise the clutch pin to be High (Disabled)
pinMode(bottomLeft_pin, INPUT); // Assign the pin to read the bottom switch
pinMode(bottomRight_pin, INPUT); // Assign the pin to read the bottom switch
}
void loop()
{
// Main Program
if (digitalRead(bottomLeft_pin) == HIGH && digitalRead(bottomRight_pin) == HIGH ) // not at bottom either hall effect sensor will trigger
{ delay(10000); //Wait 10 seconds
}
else
{
for (int stage =0; stage < LiftStages; stage ++) // go up in stages
{
digitalWrite(clutch_pin, HIGH);
digitalWrite(enable, LOW);
moveStepper (MoveDelay, MoveSteps, MoveDirection);
digitalWrite(clutch_pin, LOW);
digitalWrite(enable, HIGH);
delay(5000);
}
}
}