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