Playing small motors from synth and arduino

I have the following idea -
Reading the volage from modular synth into arduino analog pin and convert that to pwm values to drive mini vibration motors.
I am using switchable jack, so if no cable is connected to the jack input I'm using the potentiometer to change th spead of the motors
I made the following schematics:

Regarding the schematics:
does the ground of J3 should be connected to the psu and mosfet ground or to gnd1 (arduino ground, pot ground and optocoupler ground)

The following code reads the input from pots or from synthesizer:

#define NUM_POTS 3             // Number of pots

const byte POT_pins[] = { A0, A1, A2};  // pot analog input pins
const byte filterPOT = 5;  // fsr filter 
int lastValuePOT[NUM_POTS];

int heartbeatLED = 13;




//timing variables
unsigned long previousMillis = 0;
unsigned long heartbeatMillis;

unsigned long interval = 20;


//motor//
const byte MOTOR_pins[] = { 3,5,6};



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

  pinMode(heartbeatLED, OUTPUT);
  
  for (byte i = 0; i < NUM_POTS; i++) {
    pinMode(POT_pins[i], INPUT);
      pinMode(MOTOR_pins[i], OUTPUT);

  }
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    readPOTS();
    checkHeartbeatTIMER();
  }
}


//// functions ////



void readPOTS() {
  for (byte i = 0; i < NUM_POTS; i++) {
    //read the stabilized analog
    int POTValue = 1023 - analogRead(POT_pins[i]);

    //has analog value changed more than the filter amount ?
    if (abs(lastValuePOT[i] - POTValue) > filterPOT) {
      if (lastValuePOT[i] != POTValue) {
        //update to the new value
        lastValuePOT[i] = POTValue;
        Serial.print("POT");
        Serial.print(i + 1);
        Serial.print(" ");
        POTValue = map(POTValue, 0, 1023, 255, 0);
        Serial.println(POTValue);

        analogWrite(MOTOR_pins[i], POTValue);

      }
    }
  }
}




void checkHeartbeatTIMER() {
  
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul) {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

}  //END of   checkHeartbeatTIMER()

J3's ground should go to what you're calling GND1. Since J3 is an input to A0, it has to use the same ground as the Arduino in order to complete the circuit.

What happen to negative voltages reads by the Arduino? is it reading it as 0V?
And voltages above 5V? reads it as 5V ?

Your Arduino lets the magic smoke out. Maybe not literally, but it will cease to function. The ATMega328P is a 5V processor. All I/O is limited to 0-5V. Exceed those limits at your peril.

I could I avoid the magic smoke? (which I must say did not happen when I try that circuit)

The above was for driving solenoids.

For the mini vibration motors I'm using bjt:

I don't mind if higer voltages then 5V (lets say 7.5V) will be read as 5V (1023) and I don't mind if lower voltages then 0V (lets say -5V) will be read as 0V (0) .
I just don't want to burn my arduino.

Is adding series resistor of 10k or so between the tip of the jack to the arduino analog pin will solve that?

No, it will not. If you've already applied voltages outside of 0-5V to A0, you have already damaged it. The longer you continue to do so, the more you will damage it. Eventually it will quit working.

So what do you offer in order to clamp the analog input between 0V and 5V ?
might using 5V zener diode?

Wow. I am done with you.

why? I'm really asking. is just my knowledge is not enough but I try to learn..

Will that work?

@hk_jh
This will clip the voltages
image

1 Like

Thanks! 1k is for limiting the current?

what is the difference from this clamping using zener?
which one is better?

Yes

what is the difference from this clamping using zener?

They both do the same thing, however these circuits are to protect against temporary excursions of the signal going above 5V and below 0V.

So if my signal is above or below 0V 5V for longer duration is that clamping circuit might not work as intended?

would you build it using the zener diode or two 1N5817 diodes?

How much above and for how long?
Is it a periodic signal?
What is the source impedance?

Impedance is 1k (the output resistor in modular synthesizers are usually 1k)

could be up to 8V and could be for long time

Signal is sometime periodic but might be noise source

So you don't care if it is clipped?
The parts of the signal that are above 5V and below 0V are not important?

I preferred it to clip rather then not worked at all..

Do you have a solution for the signal above or below? to use voltage divider or something?

Sure but exactly what is this signal?
What is maximum and minimum voltage?
What is the lowest and highest frequency?

The signal can be constant DC of 2V 5V 7V -2V etc
It can be varying dc between 0V and 8V and it can be periodic signal between -5V +5V and sometimes +-2V or +-8V

frequency can vary between 0Hz and 10kHz