Im using a NodeMCU with this circuit, but every time the motor turns on the nodemcu restarts. The motor is rated 3 ~ 12 volts and 40-180mA no-load current. I want to use the motor for haptic feedback on my laser tag gun. Im using 4 AA rechargeable batteries to power this. My best guess is that the motor is producing too much noise or drawing too much current. I'm new to electronics and any help would be greatly appreciated.
//simple test code for motor
const int Motor = 16;
void setup() {
pinMode(Motor,OUTPUT);
}
void loop() {
digitalWrite(Motor,HIGH);
delay(1000);
digitalWrite(Motor,LOW);
delay(3000);
}
I've added a decoupling capacitor but the issue persists. and also the voltage initially drops to 4.7 from 5v but then quickly goes back to 5v when directly powering the motor.
When you tried doing the motor test, did you have the diode and 0.1mf capacitor attached? The diode looks like it's backwards in the schematic you showed. If you test with just the motor but have a short to ground on your diode it may not be an accurate test.
After your 220 ohm resistor, I'd put a 1k going from the base to ground. It might help with response time as the base could hold a capacitive charge and stay on. I don't think this is causing your problem, just something I noticed.
with the diode and 0.1mf capacitor attached, it drops down to 4.8 volts initially. and diode in the schematic is wrong sorry but it's wired up correctly.
I can see your problem. Single power supply with no filtering.
For starters motors can draw a lot more current in starting to rotate from standstill then that arted no load.
This high current draw combined with batterys internal resistance will lead voltage dropping and in this case enough that NodeMcu will reboot. What you need is preferably a lot more filetring on nodes powerlines, preferably also schotky diode so motor docent drain those capasitors too..
I'm new to this so is there any circuit or material online you could suggest? from what I understand adding an LC filter to the power source will filter out the noise generated by the motor.
Well your problem is huge current motor draws on start. LC are good for filtering, but here i would probably try first schotky diode and few big electrolyte capacitors. Basicly charge those caps up, diode prevents motor drawing current wrong way. Charged caps keep your micro going until motor current drops from start stage.
And that schotky diode do to much lover voltage drop over it.
When the transistor turns on the 0.1uF is effectively a shhort circuit across the supply. Also the motor is not turning, so no back emf and also effectively a short circuit.
A cap across the supply will not help it will just feed the motor.
You need a big electrolytic (eg >100uF NOT 0.1uF) across the supply to the arduino, AND a diode to prevent it being discharged by the motor.