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?
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.
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.
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.
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.
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
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
}
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.