3-Channel Arduino Motor-Vibrator Controller

Selfbondage software and other kinky developments

Moderators: Riddle, Shannon SteelSlave

Post Reply
User avatar
FoxBilt
*
Posts: 4
Joined: 30 Jan 2014, 01:53
Location: In The Lab

3-Channel Arduino Motor-Vibrator Controller

Post by FoxBilt »

Finally, a site that combines two of my favorite things; electronics and pleasure.
The hardware for the following control I already had kludged together but Sir Cumference's code finally showed me a practical example of how to use selectable modes, 6 in this case.
I was formerly only able to get a 2-mode 3-channel controller working using state refs(?).
I used, to a sickening degree, plain old digitalWrite commands. I did this because it is the easiest way for beginners to read and understand what the hell is going on in a glob of code.
I also did it because them funny equations with numbers AND letters make my brain hurt. I'm sure there's a more elegant coding solution, I'm still in diapers when it comes to programming.
I ran the electronic repair & calibration divisions at a few universities, never had anything to do with the programming stuff.

Instead of discrete transistors I used a ULN2004A Darlington transistor array. Each section (7 total) handles 500mA. I paralleled the inputs and outputs to handle 1A. I have about 20 hours on the motors at voltages up to 17VDC (short periods), 15VDC continuous. No magic smoke has been emitted yet. Not even any burning wires. Damn.
I have a ULN2069 quad array that handles 1.5A per section, I'll try it out as soon as I can get it unsoldered from a PCB.
The ULN arrays have clamp diodes internally to snub back-EMF. Plus my motors (salvaged from a massage chair) have clamps and capacitors installed across the motor terminals so there's no worries.

So, here's the code. Lots of snippets left in from SC's code but I may use the serial console someday so I left it in.

Code: Select all

    
    /* 3 Motor controller by FoxBilt based upon Sir Cumference's 
    original code and mode / case switch scheme. My coding is very basic,
    the different routines use simple digitalWrite to turn the motors on 
    and off intentionally to allow others to dive right in and kinda 
    have a clue by reading my existing garble.   
    
    Feel free to use it for your own pleasure (and the pleasure of whoever else is similarly inclined).

    Developed on an arduino UNO, then transferred to an ATTiny85.
    A lot of "Serial.print" is commented out in the code. If you use an arduino, it is nice to see what 
    happens, but an ATTiny doesn't like the serial monitor.


    Modes available: 6. Populate with your own routines.    */

    int pot1 = A0;    // select the input pin for potentiometer 1 Sequence Fill
    int pot2 = A1;    // select the input pin for potentiometer 2 Dwell Time
    int selector = A2;   // input pin for 6-pole rotary switch
                         // connect 3.9k resistors between each pole terminal, then + on the CCW term, - on the CW term, and com/wiper term to pin A2
    int led1 = 3;     // (PWM pin) select the pin for transistor 1
    int led2 = 5;     // (PWM pin) select the pin for transistor 2
    int led3 = 6;     // (PWM pin) select the pin for transistor 3
                      // I chose pins 3, 5, 6 for future development using PWM
    int val1 = 0;     // variable to store the value coming from the Sequence pot
    int val2 = 0;     // variable to store the value coming from the Dwell pot
    int mode;
      

    void setup()
    {
    pinMode(led1, OUTPUT); 
    pinMode(led2, OUTPUT); 
    pinMode(led3, OUTPUT);  
  }

    void loop()
    {
    // read values (and print for debugging)
    int selectorVal = analogRead(selector);
    int val1 = analogRead(pot1);
    int val2 = analogRead(pot2);
    /*
    Serial.println(selectorVal);
    Serial.print("val1:");
    Serial.println(val1);
    Serial.print("val2:");
    Serial.println(val2);
    Serial.print("Mode:");
    Serial.println (mode);
    Serial.println("***********************");
    */

    // determine mode
    mode = 0;
    if (  100 < selectorVal )
    { mode = 1; }
    if (  300 < selectorVal )
    { mode = 2; }
    if (  500 < selectorVal )
    { mode = 3; }
    if (  700 < selectorVal)
    { mode = 4; }
    if (  900 < selectorVal )
    { mode = 5; }
     
    // and use the mode determined 
    switch (mode)
    { 


    case 0:    
    // 2x2 - 2 motors on at a time, rotating pattern
  digitalWrite(led3, LOW);
  delay(val1);
  digitalWrite(led1, HIGH); //1 & 2
  digitalWrite(led2, HIGH);
  delay(val2*2);
  digitalWrite(led1, LOW); //2 & 3
  delay(val1);
  digitalWrite(led3, HIGH);
  delay(val2*2);
  digitalWrite(led2, LOW); //3 & 1
  delay(val1);
  digitalWrite(led1, HIGH);
  delay(val2*2);
    break;
       
    case 1:   
    // All ON - All OFF
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  delay(val1);
  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);
  delay(val2*3);  
    break;
       
    case 2:   
    // Variable speed radial pattern - adjustable pulsewidth and period
  digitalWrite(led1, HIGH);
  delay(val1);
  digitalWrite(led3, LOW);
  delay(val2);  
  digitalWrite(led2, HIGH);
  delay(val1);
  digitalWrite(led1, LOW);
  delay(val2);
  digitalWrite(led3, HIGH);
  delay(val1);
  digitalWrite(led2, LOW);
  delay(val2);
    break;

    case 3: 
  // Adjustable Throb
  digitalWrite(led1, HIGH);
  delay(val1 * 2);
  digitalWrite(led3, LOW);
  delay(val1 * 2);  
  digitalWrite(led2, HIGH);
  delay(val1 * 2);
  digitalWrite(led1, LOW);
  delay(val1 * 2);
  digitalWrite(led3, HIGH);
  delay(val1 * 2);
  digitalWrite(led2, LOW);
  delay(val1 * 2);
    break;  
         
    case 4:   
    // The Zipper I
    // Adjustable phase delay ramp
  digitalWrite(led1, HIGH);
  delay(val1);
  digitalWrite(led2, HIGH);
  delay(val1);
  digitalWrite(led3, HIGH);
  delay(val1 + val2);
  digitalWrite(led3, LOW);
  delay(val1 * 0.75);
  digitalWrite(led2, LOW);
  delay(val1 * 0.75);
  digitalWrite(led1, LOW);
  delay(val1 * 0.75);
    break;
       
    case 5: 
    // The Zipper II
    // decreased recycle time using delay(val1 * 0.1);
  digitalWrite(led1, HIGH);
  delay(val1);
  digitalWrite(led2, HIGH);
  delay(val1);
  digitalWrite(led3, HIGH);
  delay(val2 * 2);
  digitalWrite(led3, LOW);
  delay(val1 * 0.75);
  digitalWrite(led2, LOW);
  delay(val1 * 0.75);
  digitalWrite(led1, LOW);
  delay(val1 * 0.1);
    break;
          }
     
    delay(5);        // for stability

    }
Here's a Fritzing breadboard diagram:
3Mtr 5Mode Ctrl sm.jpg
And a pic of the pre-production model :lol:
3Mtr 5Mode Ctrl Protobox.jpg
The rotary switch with divider network:
3Mtr RotSw1.jpg
One of the motors torn from the old massage chair. They're about 1-inch diameter, the sheet metal housing makes it a li'l bigger.
There are 8 of them, heh heh heh...
3Mtr Mtr1.jpg
Now for some of the key parts.
You might wonder why I use the Pro-Mini. They're so cheap that it doesn't make sense to custom etch a PCB in 90% of cases anymore.
I buy them 10 at a time because they're so affordable. 6 analog, 6 PWM, 14 DIO, etc. Plus they're tiny! They'll fit anywhere you want :shock:
Arduino Pro-Mini (they call it "Pro Mini Microcontroller Circuit Board Module":
http://www.fasttech.com/products/1380906
$5.25 (price break to $4.75 at 5 units)

I use a variable buck power supply to power the motors. I'll just call it the +15V rail because that's what my motors seem to like.
I'm feeding it 24VDC but limit it to 15V via the trimpot on the power module.
DC-DC 3-40V to 1.5-35V 3A Buck Converter Stepdown Module (Adjustable)
http://www.fasttech.com/products/1219200
$1.48

The ULN2004A I used came out of an old microwave oven.
The molex connectors on the in and out lines are from a broken computer.
I added 5 leds; +5V rail, +15V rail, and one for each motor output. It's nice to be able to see the patterns, much more understandable than having to feel the motors and run the pots.


I could go on but I won't...
Ask me anything. If I know, I'll tell you. If I don't, I'll bullshit you real good :P
I like having my wire nuts twisted.
PiJoy
**
Posts: 89
Joined: 07 Sep 2011, 18:26
Location: Boston Metro Area, Massachusetts, USA

Re: 3-Channel Arduino Motor-Vibrator Controller

Post by PiJoy »

Good work!

The ULN series parts I've used have both per-channel and total-for-the-package limits for both current and power dissipation. I like the ones (ULN28xx, if memory serves), because they have good diode protection built in and also the biasing resistors all inside the package -- less wiring to do. :)
User avatar
Sir Cumference
Moderator
Posts: 1606
Joined: 29 Jan 2012, 22:00
Location: Scandinavia

Re: 3-Channel Arduino Motor-Vibrator Controller

Post by Sir Cumference »

I'm most delighted that you could use it!

I'm rather new to coding myself, and I think, that I quite often write my code with a shovel, rather than an elegant quill.
(My priority is: Make it work! Then make it look nice.... If time and other projects permit)

I like the idea of multiple motors.
Do the chair-motors vibrate?
~ Leatherworking, blacksmithing , woodworking and programming are the most pervertable skills you can learn! ~
User avatar
Sir Cumference
Moderator
Posts: 1606
Joined: 29 Jan 2012, 22:00
Location: Scandinavia

Re: 3-Channel Arduino Motor-Vibrator Controller

Post by Sir Cumference »

..... It shocks me how cheap the pro minis are!

When I run out of ATtinies, I'll try some of those!
~ Leatherworking, blacksmithing , woodworking and programming are the most pervertable skills you can learn! ~
User avatar
FoxBilt
*
Posts: 4
Joined: 30 Jan 2014, 01:53
Location: In The Lab

Re: 3-Channel Arduino Motor-Vibrator Controller

Post by FoxBilt »

Sir Cumference wrote: I'm rather new to coding myself, and I think, that I quite often write my code with a shovel, rather than an elegant quill.
:rofl:
My drill sergeant, at the mess hall, used to say of the food, "It might look sick but it'll still make a turd..."
Sir Cumference wrote: I like the idea of multiple motors.
Do the chair-motors vibrate?
As do I.
And yeah, boy do they ever!

My +15V rail is powered by one of those FastTech buck supplies that I heavily modded.
I swapped out the 10k 10-turn pot on the PCB for a 10-turn 2k (w/ counting dial) with another 2k trimmer. ~2.6k gets me +15VDC. The SPDT switch swaps the wiper from the long trimmer which is at around 4k and gives 18 volts, OVERDRIVE! I only fire that up for 30-45 seconds at a time (can be painful), though with 9 motors I really should abuse one 'til it craps out...
We have cows and I'm dying to tape one to its rump or head and watch it prance around. Might be more tender than Kobe beef :lol:
3Mtr FTVPS01.jpg
3Mtr FTVPS02.jpg
I like having my wire nuts twisted.
Post Reply