Multi-tasking for a DC motor and Current Sensor

Robin2:
The best thing would be to tell us what you would like the final project to do - described in English, not in code.

...R

Hi Robin,

Ok let me explain what the project is about.

I want to use the motor for fishing (jigging) !

The motor will be driving a spool and controlling the line dropping and hauling.

In other words, the fishing line will be geared with a sinker and a couple of fake baits, so I would hang the sinker off the side of the boat and start the machine where it will start rotating in a direction of letting the line out till it reaches the bottom, then start jigging (horizontal zig-zagging) up and down few feet off the bottom while drifting, and when the fish is hooked, it will automatically haul the line to the point where it was dropped from, ie; the boat.
sensing the hooked fish will be achieved by the current sensor where a load would be felt on the motor which as a result will change the current value, and the sensor will be programmed to operate in a certain current range which will need to be tested and calibrated, and when that range is exceeded, the hauling process starts.

I was also thinking about using a weight sensor instead of the current sensor and attach it to a weight sensing arm and make it work with the same concept.

My biggest challenge now is the programming bit, the rest shouldn't be a problem as it will be wired up, rigged, and told what to do.

I will attach a picture of the machine which I am trying to copy and make my own.
This machine is using a weight sensing arm and the concept I have just explained.

And lets stick to one motor then as I want it to be simple.

That's a very useful description. Forgive any ignorance of fishing that I may display ...

I reckon you will need to sense the load continuously (whether via current sensing or a weight sensor) and that completely rules out the use of the delay() function.

I suspect (and please confirm) that the jiggling movement could be reduced to the repetition of a small set of moves - perhaps half-a-dozen moves repeated over and over. That would mean that there is only a need to store data for the 6 (or whatever) moves.

Suppose there is an array with 6 rows of data each having mode, power and time ...

Then the code would read a row, set the time interval according to the time, start the motor in the appropriate mode and record the starting time. When the interval expires, stop the motor and move on to the next row of data. Something like this pseudo code

void loop() {
  interval = moves[rowNum][2];
  if (nextMoveDue == true) {
    nextMoveDue = false;
    startMotor(moves[rowNum[0], moves[rowNum[1]);
  }
  if (interval has expired) {
      stopMotor();
      nextMoveDue = true;
  }
  if (nextMoveDue == true) {
     rowNum += 1;
     if (rowNum > rowMaz) {
       rowNum = 0;
     }
  }
}

...R

Robin2:
That's a very useful description. Forgive any ignorance of fishing that I may display ...

I reckon you will need to sense the load continuously (whether via current sensing or a weight sensor) and that completely rules out the use of the delay() function.

I suspect (and please confirm) that the jiggling movement could be reduced to the repetition of a small set of moves - perhaps half-a-dozen moves repeated over and over. That would mean that there is only a need to store data for the 6 (or whatever) moves.

Suppose there is an array with 6 rows of data each having mode, power and time ...

Then the code would read a row, set the time interval according to the time, start the motor in the appropriate mode and record the starting time. When the interval expires, stop the motor and move on to the next row of data.

Correct !

That is exactly what I want the motor to do.

Jigging is a set of movements at different speeds and distances to make the fake bait look like a real fish swimming around and fool the fish to attack it.

And your code will just do that if we can put it in the right place in the sketch !

Will the "SeveralThingsAtTheSameTime" sketch have a space for the code, or does it need to be a completely new one?

I am working on modifying the "SeveralThingsAtTheSameTime" code and another code which I copied for the motor driver and trying to combine them to make it suitable for my project, but I am stuck with some lines as the original code works with several LEDs, a Botton, and a Servo, and has 'millis" which I am not yet familiar with it !!

here is how far I got with it so far, not sure if it making sense or a complete mess !!

Please note that there is still some words from the original code which I didn't know what to change it with, like "blinkDuration", and im sure that you will find more mistakes, if not all of it is wrong !!

// --------CONSTANTS (won't change)---------------


const int ENA = 5; //enables A on pin 5 (needs to be a pwm pin) for motor driver H bridge
const int IN1 = 2; //enables side 1 of motor driver
const int IN2 = 4; //enables side 2 of motor driver
const int SensorPin = A0; //enables the output pin for current sensor

//------------ VARIABLES (will change)---------------------

byte ENAState = LOW; //to record whether its on or off
byte IN1 = LOW;
byte IN2 = LOW;
byte SensorPin = LOW;


//******************   Motor control   *******************
void motor(int mode, int percent)
{
  
  //change the percentage range of 0 -> 100 into the PWM
  //range of 0 -> 255 using the map function
  int duty = map(percent, 0, 100, 0, 255);
  
  switch(mode)
  {
    case 0:  //disable/coast
      digitalWrite(ENA, LOW);  //set ENAble low to disable the Motor
      break;
      
    case 1:  //turn clockwise
      //setting IN1 high connects motor lead 1 to +voltage
      digitalWrite(IN1, HIGH);   
      
      //setting IN2 low connects motor lead 2 to ground
      digitalWrite(IN2, LOW);  
      
      //use pwm to control motor speed through ENAble pin
      analogWrite(ENA, duty);  
      
      break;
      
    case 2:  //turn counter-clockwise
      //setting IN1 low connects motor lead 1 to ground
      digitalWrite(IN1, LOW);   
      
      //setting IN2 high connects motor lead 2 to +voltage
      digitalWrite(IN2, HIGH);  
      
      //use pwm to control motor speed through ENAble pin
      analogWrite(ENA, duty);  
      
      break;
      
    case 3:  //brake motor
      //setting IN1 low connects motor lead 1 to ground
      digitalWrite(IN1, LOW);   
      
      //setting IN2 high connects motor lead 2 to ground
      digitalWrite(IN2, LOW);  
      
      //use pwm to control motor braking power 
      //through ENAble pin
      analogWrite(ENA, duty);  
      
      break;
  }
}
//**********************************************************

unsigned long currentMillis = 0;
unsigned long previousENAMillis = 0;
unsigned long previousIN1millis = 0;
unsigned long previousIN2millis = 0;
unsigned long previousSensorPinmillis = 0;


//=================================================

void setup() {

  Serial.begin(9600);
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);


  pinMode (ENA, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (SensorPin, INPUT);
  
  }

//============================================

void loop()   {

  currentMillis = millis();
  
  updateENAState();
  updateIN1State();
  updateIN2State();
  updateSensorPinstate();
  
}

//=====================================================



void updateENAState() {

  if (ENAState == LOW) {
    if (currentMillis - previousENAMillis >= ENAInterval) {
       ENAState = HIGH;
       previousENAMillis += ENAInterval;
    }
  }
  else {
    if (currentMillis - previousENAMillis >= blinkDuration) {
       ENAState = LOW;
       previousENAMillis += blinkDuration;
    } 
  }    
}

//===========================================================

void updateIN1State() {

  if (IN1State == LOW) {
    if (currentMillis - previousIN1Millis >= IN1Interval) {
       IN1State = HIGH;
       previousIN1Millis += IN1Interval;
    }
  }
  else {
    if (currentMillis - previousIN1Millis >= blinkDuration) {
       IN1State = LOW;
       previousIN1Millis += blinkDuration;
    } 
  }    
}

//========================================================

void updateIN2State() {

  if (IN2State == LOW) {
    if (currentMillis - previousIN2Millis >= IN2Interval) {
       IN2State = HIGH;
       previousIN2Millis += IN2Interval;
    }
  }
  else {
    if (currentMillis - previousIN2Millis >= blinkDuration) {
       IN2State = LOW;
       previousIN2Millis += blinkDuration;
    } 
  }    
}

//============================================================

void updateSensorPinState() {

  if (SensorPinState == LOW) {
    if (currentMillis - previousSensorPinMillis >= SensorPinInterval) {
       SensorPinState = HIGH;
       previousSensorPinMillis += SensorPinInterval;
    }
  }
  else {
    if (currentMillis - previousSensorPinMillis >= blinkDuration) {
       SensorPinState = LOW;
       previousSensorPinMillis += blinkDuration;
    } 
  }    
}

//======================================================

I'm afraid I don't immediately see my suggested concept of an array of settings in the code you have posted. However it is not essential to use arrays and maybe you have chosen a different approach.

Can you explain in English what the functions called from loop() are intended to achieve

void loop()   {

  currentMillis = millis();
 
  updateENAState();
  updateIN1State();
  updateIN2State();
  updateSensorPinstate();
 
}

Truthfully, I feel confused and I am not sure why I am confused.

Most (if not all) of your action code is in the function motor() and I don't understand what the other functions are for, or how they are supposed to relate to the motor() function.

The idea behind my suggested use of the array was to provide the numbers that would be supplied in calls to your motor() function as well as the time intervals. And I think that the code in Reply #21 can do that.

...R

Robin2:
Truthfully, I feel confused and I am not sure why I am confused.

I am sorry if I confused you, but I already mentioned that I am new to this and I don't know how to write a code, that's why I posted my problem here hoping to get some help.

In other words,

  • I know nothing about programming.

  • All the codes I posted are COPY/PASTE from someone else's codes.

  • The code in my previous reply was a COPY/PASTE from two codes ( your "SeveralThingsAtTheSameTime" code, and a code I copied from another website which was originally written to drive two DC motors using a H bridge and I just deleted the second motor lines from the sketch to make it work with only one motor) which I was trying to combine together, but apparently it turned out to be a confusing mess.

  • I don't even know what most of the function in the codes are suppose to do, im just COPY/PASTING lines that are for LED lights and changing names and pins hoping to make it work with a motor !!

I posted it hoping you can modify it and correct the mistakes it in and add your suggested code to it in the right place.

The arrays are THE perfect idea for what im trying to do and as you explained it will do the exact thing I am trying to achieve.
But I don't know how and where to put the code and how to get it to work at all !!

Please accept my apology for confusing you and forgive my ignorance.

OneGoal:
But I don't know how and where to put the code and how to get it to work at all !!

Please accept my apology for confusing you and forgive my ignorance.

No apology is needed. I had assumed you were more experienced because you are taking on this task.

Are you interested in learning to program or do you just want to get this single project working?

I will make a note to look at the code again in the morning.

...R

Robin2:
Are you interested in learning to program or do you just want to get this single project working?

Actually am interested in both, but getting the project working is a priority as am fishing for a living and after having two expensive disc replacement surgeries I cant afford a ready made machine, and I cant physically handle the job as I use to do, so I thought some automation would help.

I am doing a lot of reading at the moment and practicing some basic programming with Arduino, but as you know it is time consuming and it takes a lot of trial and error to get to the advance level of programming.

I am sure with some expert help I will get there eventually, but it would be great to get the project up and running as soon as I can so I can use it and also I can learn from it and improve it to suit my needs.

If it will be useful to know my prototype layout, here is how it is set up so far:

I am using Arduino UNO, L298N H bridge motor driver, ACS712 current sensor, a 12v DC motor.

All connected together via a breadboard and running nicely with no connection issues, as I have tried it with a sketch copied from the internet, and it is working, but not the way I want it as it has a delay() function.

If It is not too much trouble for you to write the sketch, that would be great, and I will open it and put the appropriate pin numbers and whatever is needed to be done from my side.

Your help and patience are highly appreciated, so thank you very much.

The following code may work. At least it should illustrate what is in my mind.

There are a lot of changes so I have not taken the trouble to identify them.

I have not tested it so you will need to read through it with a microscope to ensure there are no silly typos and to ensure I have not accidentally screwed up something important in your version.

// evolved from http://forum.arduino.cc/index.php?topic=341603.msg2356572#msg2356572

// --------CONSTANTS (won't change)---------------


const int ENA = 5; //enables A on pin 5 (needs to be a pwm pin) for motor driver H bridge
const int IN1 = 2; //enables side 1 of motor driver
const int IN2 = 4; //enables side 2 of motor driver
const int SensorPin = A0; //enables the output pin for current sensor

//------------ VARIABLES (will change)---------------------

byte ENAState = LOW; //to record whether its on or off
byte IN1 = LOW;
byte IN2 = LOW;
byte SensorPin = LOW;
int sensorValue = 0;



//**********************************************************

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long intervalMillis = 0;

		// these make it convenient to identify the items in the array
byte mode = 0;
byte pwr = 1;
byte mtime = 2;

byte rowNum = 0; // the current row in the array

int motorMoves[4][3] = { 
		// the columns are mode, pwr, mtime
	{1, 100, 2000} ,  // mode 1, power 100, 2000 millisecs
	{0, 0, 1000} ,    // I'm assuming mode 0 = stop
	{3, 100, 3000} ,  
	{0, 0, 5000}  
};

//=================================================

void setup() {

	Serial.begin(9600);
	int sensorValue = analogRead(A0);
	Serial.println(sensorValue);

	pinMode (ENA, OUTPUT);
	pinMode (IN1, OUTPUT);
	pinMode (IN2, OUTPUT);
	pinMode (SensorPin, INPUT);
 
	}

//============================================

void loop()   {

	currentMillis = millis();
 
	if (currentMillis - prevMillis > = intervalMillis) {
			// update the timing values
		prevMillis += intervalMillis;
		moveTime = motorMoves[rowNum][mtime];
		intervalMillis = moveTime;
			// get the latest motor values
		motorMode = motorMoves[rowNum][mode];
		motorPwr = motorMoves[rowNum][pwr];
			// call the motor function
		motor(motorMode, motorPwr];
			// update the rowNum ready for the next time
		rowNum += 1;
		if (rowNum > rowMax) {
			rowNum = 0;
		}
}

//******************   Motor control   *******************
void motor(int mode, int percent)
{
 
	//change the percentage range of 0 -> 100 into the PWM
	//range of 0 -> 255 using the map function
	int duty = map(percent, 0, 100, 0, 255);
 
	switch(mode)
	{
	case 0:  //disable/coast
		digitalWrite(ENA, LOW);  //set ENAble low to disable the Motor
		break;
	 
	case 1:  //turn clockwise
		//setting IN1 high connects motor lead 1 to +voltage
		digitalWrite(IN1, HIGH);   
	 
		//setting IN2 low connects motor lead 2 to ground
		digitalWrite(IN2, LOW); 
	 
		//use pwm to control motor speed through ENAble pin
		analogWrite(ENA, duty); 
	 
		break;
	 
	case 2:  //turn counter-clockwise
		//setting IN1 low connects motor lead 1 to ground
		digitalWrite(IN1, LOW);   
	 
		//setting IN2 high connects motor lead 2 to +voltage
		digitalWrite(IN2, HIGH); 
	 
		//use pwm to control motor speed through ENAble pin
		analogWrite(ENA, duty); 
	 
		break;
	 
	case 3:  //brake motor
		//setting IN1 low connects motor lead 1 to ground
		digitalWrite(IN1, LOW);   
	 
		//setting IN2 high connects motor lead 2 to ground
		digitalWrite(IN2, LOW); 
	 
		//use pwm to control motor braking power
		//through ENAble pin
		analogWrite(ENA, duty); 
	 
		break;
	}
}

//=====================================================

...R

Robin2:
The following code may work. At least it should illustrate what is in my mind.

There are a lot of changes so I have not taken the trouble to identify them.

I have not tested it so you will need to read through it with a microscope to ensure there are no silly typos and to ensure I have not accidentally screwed up something important in your version.

Hi,

Unfortunately it is giving me the following errors and not sure how and what to change it to :frowning:

project_test:14: error: conflicting declaration 'byte IN1'
project_test:8: error: 'IN1' has a previous declaration as 'const int IN1'
project_test:15: error: conflicting declaration 'byte IN2'
project_test:9: error: 'IN2' has a previous declaration as 'const int IN2'
project_test:16: error: conflicting declaration 'byte SensorPin'
project_test:10: error: 'SensorPin' has a previous declaration as 'const int SensorPin'
project_test.ino: In function 'void loop()':
project_test:64: error: 'prevMillis' was not declared in this scope
project_test:64: error: expected primary-expression before '=' token
project_test:67: error: 'moveTime' was not declared in this scope
project_test:70: error: 'motorMode' was not declared in this scope
project_test:71: error: 'motorPwr' was not declared in this scope
project_test:73: error: expected ')' before ']' token
project_test:73: error: expected ';' before ']' token
project_test:76: error: 'rowMax' was not declared in this scope
project_test:83: error: a function-definition is not allowed here before '{' token
project_test:132: error: expected '}' at end of input
conflicting declaration 'byte IN1'

OneGoal:
Unfortunately it is giving me the following errors and not sure how and what to change it to :frowning:

Gimme a break now ... you have to do some of the work... :slight_smile:
How many hours (and I mean hours) have you spent trying to figure out the causes of the problems ?

The first few things come from your own code. It tells you what the problem is - you are declaring the same variable twice.

...R

Robin2:
Gimme a break now ... you have to do some of the work... :slight_smile:
How many hours (and I mean hours) have you spent trying to figure out the causes of the problems ?

The first few things come from your own code. It tells you what the problem is - you are declaring the same variable twice.

...R

Sorry, I have posted the reply too soon, meanwhile I was working on the problem and trying to figure it out, so here is what I came up with, but it is still not working, only the sensor is sending the readings, but the motor is not moving at all !!

When I click on verify its all green, and uploads to Arduino fine, but the only thing I get is the readings from the sensor with no motor movement !

project_test:14: error: conflicting declaration 'byte IN1'
project_test:8: error: 'IN1' has a previous declaration as 'const int IN1'
Replaced with IN1State

project_test:15: error: conflicting declaration 'byte IN2'
project_test:9: error: 'IN2' has a previous declaration as 'const int IN2'
replaced with IN2State

project_test:16: error: conflicting declaration 'byte SensorPin'
project_test:10: error: 'SensorPin' has a previous declaration as 'const int SensorPin'
replaced with SensorPinState

project_test.ino: In function 'void loop()':
project_test:64: error: 'prevMillis' was not declared in this scope
replaced with previousMillis

project_test:64: error: expected primary-expression before '=' token
A space was between > and =, changed to be >=

project_test:67: error: 'moveTime' was not declared in this scope
replaced with mtime

project_test:70: error: 'motorMode' was not declared in this scope
replaced with mode

project_test:71: error: 'motorPwr' was not declared in this scope
replaced with pwr

project_test:73: error: expected ')' before ']' token
project_test:73: error: expected ';' before ']' token
It was motor(motorMode, motorPwr];
**Replaced with motorMoves[mode, pwr]; **

project_test:76: error: 'rowMax' was not declared in this scope
Was added to line 34 below byte rowNum = 0; // the current row in the array
So it is now byte rowNum = 0; // the current row in the array
byte rowMax = 100;
(not sure if it is right or wrong, just assumed the place and the number as 100 is max power !!!)

project_test:83: error: a function-definition is not allowed here before '{' token
project_test:132: error: expected '}' at end of input
Added a missing '}'

conflicting declaration 'byte IN1'
Corrected above

So the new code now is

// evolved from http://forum.arduino.cc/index.php?topic=341603.msg2356572#msg2356572

// --------CONSTANTS (won't change)---------------


const int ENA = 5; //enables A on pin 5 (needs to be a pwm pin) for motor driver H bridge
const int IN1 = 2; //enables side 1 of motor driver
const int IN2 = 4; //enables side 2 of motor driver
const int SensorPin = A0; //enables the output pin for current sensor

//------------ VARIABLES (will change)---------------------

byte ENAState = LOW; //to record whether its on or off
byte IN1State = LOW;
byte IN2State = LOW;
byte SensorPinState = LOW;
int sensorValue = 0;



//**********************************************************

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long intervalMillis = 0;

    // these make it convenient to identify the items in the array
byte mode = 0;
byte pwr = 1;
byte mtime = 2;

byte rowNum = 0; // the current row in the array
byte rowMax = 100;
int motorMoves[4][3] = { 
    // the columns are mode, pwr, mtime
  {1, 100, 2000} ,  // mode 1, power 100, 2000 millisecs
  {0, 0, 1000} ,    // I'm assuming mode 0 = stop
  {3, 100, 3000} ,  
  {0, 0, 5000}  
};

//=================================================

void setup() {

  Serial.begin(9600);
  
  pinMode (ENA, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (SensorPin, INPUT);
 
  }

//============================================

void loop()

{
 
  int sensorValue = analogRead(A0);

  Serial.println(sensorValue);

  currentMillis = millis();
 
  if (currentMillis - previousMillis >= intervalMillis) {
      // update the timing values
    previousMillis += intervalMillis;
    mtime = motorMoves[rowNum][mtime];
    intervalMillis = mtime;
      // get the latest motor values
    mode = motorMoves[rowNum][mode];
    pwr = motorMoves[rowNum][pwr];
      // call the motor function
    motorMoves[mode, pwr];
      // update the rowNum ready for the next time
    rowNum += 1;
    if (rowNum > rowMax) {
      rowNum = 0;
    }
}

}

//******************   Motor control   *******************
void motor (int mode, int percent)
{


  
  //change the percentage range of 0 -> 100 into the PWM
  //range of 0 -> 255 using the map function
  int duty = map(pwr, 0, 100, 0, 255);
  
  switch(mode)
  {
    case 0:  //disable/coast
      digitalWrite(ENA, LOW);  //set enable low to disable A
      break;
      
    case 1:  //turn clockwise
      //setting IN1 high connects motor lead 1 to +voltage
      digitalWrite(IN1, HIGH);   
      
      //setting IN2 low connects motor lead 2 to ground
      digitalWrite(IN2, LOW);  
      
      //use pwm to control motor speed through enable pin
      analogWrite(ENA, duty);  
      
      break;
      
    case 2:  //turn counter-clockwise
      //setting IN1 low connects motor lead 1 to ground
      digitalWrite(IN1, LOW);   
      
      //setting IN2 high connects motor lead 2 to +voltage
      digitalWrite(IN2, HIGH);  
      
      //use pwm to control motor speed through enable pin
      analogWrite(ENA, duty);  
      
      break;
      
    case 3:  //brake motor
      //setting IN1 low connects motor lead 1 to ground
      digitalWrite(IN1, LOW);   
      
      //setting IN2 high connects motor lead 2 to ground
      digitalWrite(IN2, LOW);  
      
      //use pwm to control motor braking power 
      //through enable pin
      analogWrite(ENA, duty);  
      
      break;
  }
}
//=====================================================

Sorry, but these changes are all wrong

project_test:67: error: 'moveTime' was not declared in this scope
replaced with mtime

project_test:70: error: 'motorMode' was not declared in this scope
replaced with mode

project_test:71: error: 'motorPwr' was not declared in this scope
replaced with pwr

project_test:73: error: expected ')' before ']' token
project_test:73: error: expected ';' before ']' token
It was motor(motorMode, motorPwr];
Replaced with motorMoves[mode, pwr];

project_test:76: error: 'rowMax' was not declared in this scope
Was added to line 34 below byte rowNum = 0; // the current row in the array
So it is now byte rowNum = 0; // the current row in the array
byte rowMax = 100;
(not sure if it is right or wrong, just assumed the place and the number as 100 is max power !!!)

You need to declare the variables at the top of the code - not change them to other variables. For example replacing moveTime with mtime will completely screw up the program.

You need to create rowMax to equal the highest index value for the array. With the 4 rows in my example it should be set to 3. What did you think would happen when rowNum became 12, for example (or 87) ?

I did warn yout that the code needed very careful study for just this sort of reason.

...R

Robin2:
Sorry, but these changes are all wrong

That's exactly why im here asking for help :slight_smile:

As I mentioned several times already, I don't know how write a sketch, let alone studying one !!

Well, what seemed to be a simple project turned out to be a mission impossible.

Anyways, thank you very much for your time and attempts to help, and sorry if it caused any inconveniences.

OneGoal:
That's exactly why im here asking for help :slight_smile:

If you ask in the Gigs and Collaborations section you should be able to find someone to write a program for you for a fee. I am not interested in doing that.

I am happy to give a bit of assistance when a person is stuck with a problem - but I assume s/he will have taught himself/herself the basics - or will just be asking questions about the basics. You seem to have started with a complex project - reading Shakespeare without learning your ABC.

As it stands at the moment your project is not very difficult (not nearly as hard as Shakespeare) and I suspect if you spend some more time studying it and learning a bit more about simple Arduino programming via the many tutorials online and the examples that come with the Arduino IDE you will master it.

...R

Robin2:
If you ask in the Gigs and Collaborations section you should be able to find someone to write a program for you for a fee. I am not interested in doing that.

I am happy to give a bit of assistance when a person is stuck with a problem - but I assume s/he will have taught himself/herself the basics - or will just be asking questions about the basics. You seem to have started with a complex project - reading Shakespeare without learning your ABC.

As it stands at the moment your project is not very difficult (not nearly as hard as Shakespeare) and I suspect if you spend some more time studying it and learning a bit more about simple Arduino programming via the many tutorials online and the examples that come with the Arduino IDE you will master it.

...R

You are absolutely right !

I have taken on a project that is way beyond me.

I guess I will have to hire someone to write me the sketch.

All the online examples I found about arrays, millis, and interrupts are for LEDs which use one pin to turn HIGH or LOW, where my motor uses three pins and I couldn't work out which is which and when and how !!

But really thank you very much for the help, and sorry for not being able to make a good use of it.