Continuous and Delay Question

Hello, I hope everyone’s going well!

Me and my dad are starting a project and need a small DC motor to run off a 9V battery. We don’t have much experience in these board or programming so I’m figured I’d ask for input.

We need the motor to have 3 options.

  • On (continuous)
  • On (delay for 10 seconds
  • Off

We will have a 3 way switch to control these 3 options. What is the best way going about this? Which board? Maybe even some programming help?

Thanks for your time,
Logan.

Google for tutorials on small DC motors. Figure out what driver you want to use (lose the 9V batteries by the way) and look at the examples in the library. That will get you going very well.

Loosing the 9V battery, what battery would a guy use then?

We are fine with using a D cell also.

Right. 9V batteries typically can't supply the current required to drive even a small DC motor. They're not that great for powering processor boards either. Depending on the processor board and motor's requirement, you could go with a battery pack of 4-AAA (or AA) cells. Or, perhaps a LiPo. If it's not a hard requirement that the project be battery-powered, there's always a 5V wall wart of sufficient output capability.

You'll need a switching device to deliver current to the motor as processor output pins are incapable of supply that much current. That could be as simple as a bipolar transistor or a FET.

See This Tutorial From Adafruit. There are many others online ... only a search engine away.

Also check out DroneBotWorkshop. Here is one of several videos/articles
Video
Article

Another good resource of drivers and information is Pololu

Maybe you fellas could name this PCB Board, this is exactly what I need but can’t seem to find anything.


I name it "boardie". Where did it come from and what does it do and why do you need it? Ir is this a guessing game?

Should have clarified, my bad.

This board has a 3 way switch. On Off On.

In the 1st on position it spins the motor continuously.
In the second on position it spins the motor for a few seconds then stops, spins stops so on so fourth.

This came off of an ice fishing auto jigger it’s called.

Ok, but what has the board to do with an Arduino? The switch can be used if NOT connected to anything else.

I’m trying to figure out if an Arduino can do the same as this.

As I said, this is all completely new to me. I’ve done some research but see to be going in circles.

Sure, it can be done. Connect the switch central terminal to the Arduino ground. Connect each end terminal to a digital pin on the Arduino.
In your program set each of the connected digital pins to inputPullup.
Then write your code to test each of those digital pins for 0. If it is zero, then the switch is moved to one end or the other. If neither pin is zero, then the switch is centered.
So, there are the three options you need.

Which Arduino controller would be the best for this? I would need an Arduino and a motor driver correct? Thanks for all the information so far!

You need a module with a MOSFET(transistor) that can carry the motor current and has a diode to protect itself from the motor acting as a generator when the power is suddenly removed from the motor.
Any Arduino you care to get will work for you. Look for a NANO board as it is tried and true.
Then you need to think about power for the nano and for the motor. They should not be the same.

if not clear already, it's best to get a motor driver board that uses an external battery. Some are shields that plug into an Arduino, others are separate boards that can be connected with wires.

both typically have 3 pins to control a motor: IN1, IN2 and EN. IN1 and IN2 control the direction when one is HIGH and the other LOW. The EN pin is typically dirven with a PWM signal that can be generated using analogWrite() to control the motor speed

switches to select one of your 3 options can be wired between the pin and ground. The pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.

the code below is for 3 separate buttons

before using motors, you can use LEDs (in series with a 1k resistor) connected to the output pins to test the logic of the program

ook over the following

const byte PinIN1   = 11;
const byte PinIN2   = 12;
const byte PinEN    = 13;

const byte PinS0    = A1;
const byte PinS1    = A2;
const byte PinS2    = A3;

const unsigned long TenSec = 1 * 1000;
unsigned long msecPeriod;
unsigned long msec0;

// -----------------------------------------------------------------------------
void loop()
{
    unsigned long msec = millis ();

    if (LOW == digitalRead (PinS0))  {
        Serial.println ("Off");
        digitalWrite (PinEN, LOW);          // motor off
        msecPeriod = 0;                     // reset delay option
    }

    else if (LOW == digitalRead (PinS2))  {
        Serial.println ("On");
        digitalWrite (PinEN, HIGH);         // motor on
        msecPeriod = 0;                     // reset delay option
    }

    else if (LOW == digitalRead (PinS1))  {
        Serial.println ("Delay");
        if (0 ==  msecPeriod)  {
            msecPeriod = TenSec;
            msec0      = msec;
            digitalWrite (PinEN, HIGH);     // motor on
        }
    }

    if (msecPeriod && msec - msec0 >= msecPeriod)  {
        msec0 = msec;
        digitalWrite (PinEN, ! digitalRead (PinEN));    // toggle on/off
    }

    delay (50);     // debounce
}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin (115200);

    pinMode (PinS0,  INPUT_PULLUP);
    pinMode (PinS1,  INPUT_PULLUP);
    pinMode (PinS2,  INPUT_PULLUP);

    pinMode (PinIN1, OUTPUT);
    pinMode (PinIN2, OUTPUT);
    pinMode (PinEN,  OUTPUT);

    digitalWrite (PinEN,  LOW);          // motor Off
    digitalWrite (PinIN1, LOW);          // set direction
    digitalWrite (PinIN2, HIGH);
}
1 Like

Would I be able to use a 3 way switch to control all those functions instead of having 3 separate switches?

i assumed (!?) a 3 position rotary switch not an on-off-on, DPST SPDT. I think a SPDT, connected to 2 pins can work where the Off case is simply the else case

    if (LOW == digitalRead (PinS2))  {
        Serial.println ("On");
        digitalWrite (PinEN, HIGH);         // motor on
        msecPeriod = 0;                     // reset delay option
    }

    else if (LOW == digitalRead (PinS1))  {
        Serial.println ("Delay");
        if (0 ==  msecPeriod)  {
            msecPeriod = TenSec;
            msec0      = msec;
            digitalWrite (PinEN, HIGH);     // motor on
        }
    }
    else  {
        Serial.println ("Off");
        digitalWrite (PinEN, LOW);          // motor off
        msecPeriod = 0;                     // reset delay option
    }
1 Like

I name it "LM556 oneshot."

If you peeled off all the brown goo, the board looks like it is done with a DIP, a transistor, 3 resistors, and a couple capacitors.

Maybe it is something like a 555 as in this timer one-shot with some transistor output as in this 555 PWM circuit. The switch would either power the 555 (556?) one-shot circuit or bypass the 555 and drive the transistor directly.

It looks a lot lower power than an Arduino.