My watchwinder, with 4 seperate 3 V DC (analogue) motors, controls the winding of 4 watches.
The build-in circuit powers the motors for 2 minutes and the motors rotate 20 turns. Then the motors stop for a certain periode varing from 6 minutes to 10 minutes.
Every watch has its specific turns per day (TPD), advised by the watch-manufacturer and the TPD (adjustable via touchscreen) determines this "stopping-periode".
For a Breitling Navitimer TPD is 800 and for a Rolex TPD is 650.
So a Breitling would rotate 40 times a day for a periode of 2 minutes (of 20 rotations) with 7 minutes interval (in 12 hours).
A Rolex would rotate 33 times a day for a periode of 2 minutes with 9,5 minutes interval.
But because of the different weight of the watches and the analoge motors the watches don't always stop in the same position after their 20 turns.
It looks rather chaotic and it is difficult to tell the time on each watch because some are upside down or in a random postion after the rotations.
Ideally the watches should always stop in the 12 o'clock position which I am trying to achive with an arduino and 4 IR sensors and 4 relais.
The IR sensor, positioned at the 12 o'clock position at the rear of the motorshaft, counts the number of rotations. After 19 rotations a relay is powered and switches OFF the motor
(when watch is in 12 oçlock position) for 10 seconds.
Than I know for sure the 2 minute cycle is completed, the relay can be "released" and the motor is waiting to be powered for its next cycle by the built-in circuit.
My sketch, copied and modified from IR object counter, works for one motor/watch with a "delay(10000)" but how do I use this sketch for 4 IR sensors and 4 relais.
I am aware of the fact that I cannot use the delay function for the 10 seconds to power the relay and power-off the motor.
Obviously I have been trying losts of suggestions regarding options for a "non blocking delay" on the forum but if you are more a "watch-guy" than a programmer it is complicated.
Anybody can help me out?
// Pin configuration
const int sensorPin0 = 2; // Connect the infrared sensor's output pin to Arduino pin 2
const int sensorPin1 = 3;
const int sensorPin2 = 4;
const int sensorPin3 = 5;
// Variables
int objectCount0 = 0; // Counter to keep track of the number of rotations
int sensorState0 = 0; // Current state of the sensor (HIGH or LOW)
int lastSensorState0 = 0; // Previous state of the sensor
int objectCount1 = 0;
int sensorState1 = 0;
int lastSensorState1 = 0;
int objectCount2 = 0;
int sensorState2 = 0;
int lastSensorState2 = 0;
int objectCount3 = 0;
int sensorState3 = 0;
int lastSensorState3 = 0;
int relay0 = 8;
int relay1 = 9;
int relay2 = 10;
int relay3 = 11;
void setup() {
pinMode(sensorPin0, INPUT); // Set sensor pin as input
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
Serial.begin(9600); // Initialize serial communication for debugging
pinMode(relay0, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
}
void loop() {
sensorState0 = digitalRead(sensorPin0); // Read the state of the sensor
sensorState1 = digitalRead(sensorPin1);
sensorState2 = digitalRead(sensorPin2);
sensorState3 = digitalRead(sensorPin3);
// Check if the sensor state has changed (watchrotation)
if (sensorState0 != lastSensorState0) {
if (sensorState0 == HIGH) {
objectCount0++; // Increment the object count when rotation is complete
Serial.print("Object 0 detected! Count: ");
Serial.println(objectCount0);
}
if (objectCount0 > 18) {
digitalWrite(relay0, LOW);
Serial.print("Motor0 powered off for 10 sec. and wait till next cycle");
Serial.println();
//HERE A NON BLOCKING DELAY FOR 10 SECONDS TO STOP MOTOR
objectCount0 = 0;
}
if (objectCount0 < 19) {
digitalWrite(relay0, HIGH);
}
}
lastSensorState0 = sensorState0;
if (sensorState1 != lastSensorState1) {
if (sensorState1 == HIGH) {
objectCount1++;
Serial.print("Object 1 detected! Count: ");
Serial.println(objectCount1);
}
if (objectCount1 > 18) {
digitalWrite(relay1, LOW);
Serial.print("Motor1 powered off for 10 sec. and wait till next cycle");
Serial.println();
//HERE A NON BLOCKING DELAY FOR 10 SECONDS TO STOP MOTOR
objectCount1 = 0;
}
if (objectCount1 < 19) {
digitalWrite(relay1, HIGH);
}
}
lastSensorState1 = sensorState1;
if (sensorState2 != lastSensorState2) {
if (sensorState2 == HIGH) {
objectCount2++;
Serial.print("Object 2 detected! Count: ");
Serial.println(objectCount2);
}
if (objectCount2 > 18) {
digitalWrite(relay2, LOW);
Serial.print("Motor2 powered off for 10 sec. and wait till next cycle");
Serial.println();
//HERE A NON BLOCKING DELAY FOR 10 SECONDS TO STOP MOTOR
objectCount2 = 0;
}
if (objectCount2 < 19) {
digitalWrite(relay2, HIGH);
}
}
lastSensorState2 = sensorState2;
if (sensorState3 != lastSensorState3) {
if (sensorState3 == HIGH) {
objectCount3++;
Serial.print("Object 3 detected! Count: ");
Serial.println(objectCount3);
}
if (objectCount3 > 18) {
digitalWrite(relay3, LOW);
Serial.print("Motor3 powered off for 10 sec. and wait till next cycle");
Serial.println();
//HERE A NON BLOCKING DELAY FOR 10 SECONDS TO STOP MOTOR
objectCount3 = 0;
}
if (objectCount3 < 19) {
digitalWrite(relay3, HIGH);
}
}
lastSensorState3 = sensorState3;
}