I have some coding experience years ago with languages no one uses anymore but not with Arduino. I've found programs online that start the motor at max speed but none that do the loop repeatedly and then pause.
Welcome
Just hit the flag icon and ask a moderator to move it, your needs are reasonably trivial and you could do it yourself, that is what this forum is for, but you would need to put some time and effort in to learn the concepts. If it is a one off and you donβt care about learning then the paid section is for you. If you want to spend a week or so getting to know arduino and C then ask specific questions posting your code etc as per the forum guidelines
Thanks will do. This is just a program I need for a prototype to turn a motor pending the motherboard being developed and my time would be more useful on other aspects of the project.
Why not post the simplest one, as a starting point? It will save someone a lot of typing. There are a lot of bitten tongues here, it's a super easy sketch.
Thanks. I've never programmed Arduino (my background is a hundred years ago in Fortran, Basic & PL/1, lol) but decided to do some review of the Arduino programming language this morning and try to tackle it myself. I came up with this but added your 'for' command to replace a 'for while' that I had. I changed the delay to 833ms, repeats to 150, left the pause at 400 secs, but then added that the sequence run for 10 hours.
I don't see your motoron() of motoroff() commands existing anywhere in arduino code after doing an online search. Are they the name of a function you created but did not list?
Any advice anyone can give to this newbie about my code would be appreciated.
//L293D
const int motorPin1 = 5; // Pin 14 of L293D
const int motorPin2 = 6; // Pin 10 of L293D
unsigned long startmillis;
void setup() {
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
//initial start time
startmillis = millis();
}
//Run program for 7200000ms (2 hrs)
void loop() {
while (millis() - startmillis < 7200000ul) {
//Spin motor for 833ms & pause for 3000ms, do 150x
//Motor Control - motorPin1,motorpin2
for (i = 0; i < 150; i++) {
//Spin motor clockwise
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(833ul); //run 833ms
//Pause motor for 3000ms
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(3000ul); //pause 3 secs
}
delay(400000ul);
}
}
Thanks. Great idea but I didn't know anything until this morning when I decided to spend a few hours learning the Arduino code. I have now posted my code.
#include <Arduino.h>
// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
void directionControl();
void speedControl();
void setup()
{
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
void loop()
{
directionControl();
delay(1000);
speedControl();
delay(1000);
}
// This function lets you control spinning direction of motors
void directionControl()
{
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 255);
// Turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(2000);
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(2000);
// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
// This function lets you control speed of the motors
void speedControl()
{
// Turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Accelerate from zero to maximum speed
for (int i = 0; i < 256; i++)
{
analogWrite(enA, i);
delay(20);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 0; --i)
{
analogWrite(enA, i);
delay(20);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}