I'm building a project for my Physical Computing class that involves 4 vibration motors for varied haptic feedback based on serial input via analogRead. I have each coming out of their own pin and assigned to conditionals.
I'm wondering:
- how do i control the PWM of each individual motor?
- assuming I need an external power source for the motors, do I need to have a diode and transistor in between each motor and the ground?
Thanks in advance - I'm still learning but definitely looking forward to taking Part II next semester!
-
2arduino.cc/en/Reference/AnalogWritesa_leinad– sa_leinad2016年12月08日 06:09:27 +00:00Commented Dec 8, 2016 at 6:09
1 Answer 1
- You can control motor PWM by using AnalogWrite() feature. Arduino Mini is equipped with 6 PWM pin, so you can use 1 PWM pin for each of you motor. Check here about more information on AnalogWrite, and here about Arduino Mini
- This is the circuit if you want to use external power source. Normally, I use 1k ohm resistor, I'm sure there are someone out there that knows the exact formula.
schematic
simulate this circuit – Schematic created using CircuitLab
-
Why specifically use a zener diode as a flyback? Can't a regular diode (granted it can handle the voltage) do the trick? Is there a specific advantage of using a zener diode over a normal diode?Len– Len2016年12月08日 09:22:09 +00:00Commented Dec 8, 2016 at 9:22
-
1Sure regular diode will also works, I didn't mention anything about specifically using zener diodeduck– duck2016年12月08日 09:31:39 +00:00Commented Dec 8, 2016 at 9:31
-
Hi - thanks for the help. I'm pretty solid on the physical routing now, at this point, its more the code I'm worried about. I'm guessing I can use an elseif statement? So for example if I have
irPin1 = analogread(irVal1)
to set the analogRead for the IR sensor I'm using, and then: ' if (irVal1 < 400){ digitalWrite(vibePin1 = HIGH); } else(){ digitalWrite(vibePin1 = LOW); }'Nick– Nick2016年12月08日 15:12:03 +00:00Commented Dec 8, 2016 at 15:12 -
From there, how would I distribute PWM values to each sensor? I'm assuming that I'd be creating a pwmVal variable to store something? AnalogWrite(pwmVal = 30) or something like that? Assuming it goes 0-255.Nick– Nick2016年12月08日 15:15:43 +00:00Commented Dec 8, 2016 at 15:15
-
1@Nick if there are new question, in my opinion you should post another question or edit the original instead of asking in comment section.duck– duck2016年12月09日 01:19:12 +00:00Commented Dec 9, 2016 at 1:19