I would like to control 32 mini vibration motors rated 3V 50mA each.
I would like to control each group of 4 motors with 1 pwm pin.
the motors will be located around 10/15 meters away from the Arduino. In that case - should I:
-
add optocoupler? if yes how to wire it?
-
add a fuse?
-
if using 32 motors in total the total consumption is 1.2A' if we take x1.5 margin it is rated to almost 2A. in that case the 3x 1N4001 diode that drop the voltage from 5 to 3V is rating will not be good right? what diode I should use instead?
any other tips?
Here is my schematics (16 out of 32 in total):
Here is my Arduino code (it has some other parts that are not in that schematics)
const int NUM_PWM_MOTORS = 4;
const int pwm_motor_pins[] = { 3, 5, 6, 9, 10, 11 };
const char pwm_motor_ids[] = { 'U', 'V', 'W', 'X', 'Y', 'Z' };
//digital pins connected to solenoids 1 - 9:2,4,7,8,12,13,A0,A1,A2//
const int NUM_DIGITAL_MOTORS = 9;
const int digital_motor_pins[] = { 2, 4, 7, 8, 12, A0, A1, A2, A3 };
const char digital_motor_ids[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I' };
unsigned long heartbeatMillis;
int heartbeatLED = 13;
//pedal//
int SW;
int exSW = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup() {
for (int i = 0; i < NUM_PWM_MOTORS; i++) {
pinMode(pwm_motor_pins[i], OUTPUT);
}
for (int i = 0; i < NUM_DIGITAL_MOTORS; i++) {
pinMode(digital_motor_pins[i], OUTPUT);
}
pinMode(heartbeatLED, OUTPUT);
pinMode(A4, INPUT_PULLUP);
Serial.setTimeout(10);
Serial.begin(115200);
}
void loop() {
checkHeartbeatTIMER();
motorsControl();
pedal();
}
void motorsControl() {
if (Serial.available() > 0) {
char id = Serial.read();
int state = Serial.parseInt();
for (int i = 0; i < NUM_PWM_MOTORS; i++) {
if (id == pwm_motor_ids[i]) {
analogWrite(pwm_motor_pins[i], state);
Serial.print(id);
Serial.print(" ");
Serial.println(state);
}
}
for (int i = 0; i < NUM_DIGITAL_MOTORS; i++) {
if (id == digital_motor_ids[i]) {
digitalWrite(digital_motor_pins[i], state);
Serial.print(id);
Serial.print(" ");
Serial.println(state);
}
}
}
}
void checkHeartbeatTIMER() {
if (millis() - heartbeatMillis >= 500) {
heartbeatMillis = millis();
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
}
void pedal() {
SW = 1 - digitalRead(A4);
currentMillis = millis();
if (currentMillis - previousMillis >= 100 and SW != exSW) {
previousMillis = currentMillis;
Serial.print("pedal ");
Serial.println(SW);
exSW = SW;
}
}
Thanks!