Go Down

Topic: 14 coin vibration motor using arduino (Read 1 time) previous topic - next topic

Jeremystorm

Hi, all

I'm design major student who just started arduino.

In my project I want to make some cloth that makes you feel like get rained on.

It has 14 coin motors on the back. Each coin motors vibrate shortly to feel like real rain drops on you.

To make this I got 14 [XY-B1030-DX coin motor].

In my mind It will be easy.

Like separate those coin motors into 4 groups.

Each groups of coin motors connect to analog pin, and just give them a serial to control it.

However after I've done some research translator must be needed and lots of resistances.

It's beyond my knowledge sadly.

So can someone help me with this a to z?

sorry for my bad english :(

jremington

#1
Nov 21, 2016, 04:24 am Last Edit: Nov 21, 2016, 04:26 am by jremington
Each motor requires 3V, about 120 mA to start up and 85 mA to run.

You will need a transistor, a base resistor (220 Ohms) and a flyback diode for each set of motors, plus a 3V motor power supply capable of providing of providing at least 1 ampere. 2xAA batteries will work.

You can follow this basic approach describing how to drive one motor. It is a good idea to add the capacitor shown in that circuit.

You should never attempt to drive the motor(s) directly with the Arduino, or use the 5V or 3.3V Arduino output to power the motors.

Jeremystorm

#2
Nov 21, 2016, 04:48 am Last Edit: Nov 21, 2016, 05:14 am by Jeremystorm
Thanks for your reply jremington :)

This is my code right now

Code: [Select]

const int motorPin = 13;
const int motorPin2 = 12;
const int motorPin3 = 11;
const int motorPin4 = 10;
const int motorPin5 = 9;

void setup() {
  pinMode(motorPin, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(motorPin5, OUTPUT);
}

void loop() {
  digitalWrite(motorPin, HIGH);
  delay(40);
  digitalWrite(motorPin, LOW);
  delay(120);

  digitalWrite(motorPin2, HIGH);
  delay(30);
  digitalWrite(motorPin2, LOW);
  delay(890);

  digitalWrite(motorPin3, HIGH);
  delay(40);
  digitalWrite(motorPin3, LOW);
  delay(150);

  digitalWrite(motorPin4, HIGH);
  delay(30);
  digitalWrite(motorPin4, LOW);
  delay(60);

  digitalWrite(motorPin5, HIGH);
  delay(35);
  digitalWrite(motorPin5, LOW);
  delay(800);
}


I got only 'TIP122' transistor now, but I don't know how to use it.

So I give 3.3V to breadboard + , and directly put pin13-9 to coin motors.

It works anyway.. but everything I've seen to study says I must not connect those directly.

but I can't understand :( :( :(

Would you teach me what transistor and flyback diode do in this circuit?

jremington

#3
Nov 21, 2016, 05:47 am Last Edit: Nov 21, 2016, 05:49 am by jremington
You will eventually destroy the Arduino if you try to power the motors from the 3.3V output, or if you try to run motors from a digital output. Guaranteed!

The TIP122 transistors won't work as well as the 2N2222 (or similar) transistor shown in the tutorial I linked. The TIP122 won't allow the full motor power supply voltage to reach the motors.

There are many tutorials on transistor action on the web, but you will probably need some basic electronics to understand them.

Jeremystorm

So transtistor and diode help me to not burn my arduino out?

Yes I got to study electronics more..

So 2N2222 needed in this circuit? Thanks jreminton :)

After I study link you give, I upload circuit and code in this thread!

Jeremystorm

#5
Dec 04, 2016, 01:37 pm Last Edit: Dec 04, 2016, 02:36 pm by Jeremystorm
Hi, all

It's jeremy again:)

I've got 14 coin motor project still.

with lilypad arduino, I've got cloth and circuit already.

this is my code

Code: [Select]


#include <DFPlayer_Mini_Mp3.h>
#include <SoftwareSerial.h>

const int L1 = 12;
const int L2 = 13;
const int L3 = A0;
const int L4 = A1;
const int L5 = A2;
const int L6 = A3;
const int L7 = A4;

const int R1 = 11;
const int R2 = 10;
const int R3 = 9;
const int R4 = 8;
const int R5 = 7;
const int R6 = 6;
const int R7 = 5;

int flexSensor = A5;

void setup() {
  Serial.begin(9600);
  mp3Serial.begin(9600);

  mp3_set_serial (mp3Serial);
  delay(1);
  mp3_set_volume (30);

  pinMode(flexSensor, INPUT);
  
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(L5, OUTPUT);
  pinMode(L6, OUTPUT);
  pinMode(L7, OUTPUT);
  
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  pinMode(R3, OUTPUT);
  pinMode(R4, OUTPUT);
  pinMode(R5, OUTPUT);
  pinMode(R6, OUTPUT);
  pinMode(R7, OUTPUT);
}

void loop() {

  int flexVal;

  flexVal = analogRead(flexSensor);

  if (flexVal < 4) {
    //rain LESS
    digitalWrite(L1, HIGH);
    delay(30);
    digitalWrite(L1, LOW);
    delay(200);
  }
  else {
    //rain MORE
    digitalWrite(L1, HIGH);
    delay(40);
    digitalWrite(L1, LOW);
    delay(50);

    mp3_play();
    delay(100000);

  }

  Serial.println(flexVal);
}



When flex sensor straights, flexVal increases above 4 and goes to 'else'.

Though I put 4 simple lines in coin vibrating parts.
It has 40 long codes about 30 sec.

This is my question, like this way, flexVal doesn't change till coin vibrating parts over.

Can I change this 40 long code to simple code with random function?

and How can I get out this loop right away when flexVal changed?

Sorry for the bad english but I'll awake 24 hours from now

so.. help..

jremington

Quote
flexVal doesn't change till coin vibrating parts over.
Correct. The Arduino can't do anything else while it is in delay().

Study the "Blink without delay" example that comes with the Arduino IDE to learn how to avoid this.

Jeremystorm

Thanks jeremington!

nice to see you again:)

okay. I'll!

Cuz I didn't know 'Blink without delay" I made my way to come up with this.

It's my codes right now.

Code: [Select]

#include <DFPlayer_Mini_Mp3.h>
#include <SoftwareSerial.h>

SoftwareSerial mp3Serial(0, 1);

const int c1 = 12;
const int c2 = 13;
const int c3 = A0;
const int c4 = A1;
const int c5 = A2;
const int c6 = A3;
const int c7 = A4;
//왼쪽 모터들

const int c8 = 11;
const int c9 = 10;
const int c10 = 9;
const int c11 = 8;
const int c12 = 7;
const int c13 = 6;
const int c14 = 5;
//오른쪽 모터들

int flexSensor = A5;

void setup() {
  Serial.begin(9600);
  mp3Serial.begin(9600);

  mp3_set_serial (mp3Serial);
  delay(1);
  mp3_set_volume (30);

  pinMode(flexSensor, INPUT);

  pinMode(c1, OUTPUT);
  pinMode(c2, OUTPUT);
  pinMode(c3, OUTPUT);
  pinMode(c4, OUTPUT);
  pinMode(c5, OUTPUT);
  pinMode(c6, OUTPUT);
  pinMode(c7, OUTPUT);
  //왼쪽 모터들

  pinMode(c8, OUTPUT);
  pinMode(c9, OUTPUT);
  pinMode(c10, OUTPUT);
  pinMode(c11, OUTPUT);
  pinMode(c12, OUTPUT);
  pinMode(c13, OUTPUT);
  pinMode(c14, OUTPUT);
  //오른쪽 모터들
}

void loop() {

  int flexVal;

  flexVal = analogRead(flexSensor);

  if (flexVal < 4) {
    // 적게 올때, 숫자가 작음 / 구부러졋단뜻 / 혼자 씀

    for (int i = 0; i < 40; ++i)
    {
      int randomMotorOne = "c + random(1, 15)"; //진동 오는 코인을 랜덤하게
      int rainPowerOne = random(75, 125);     //혼자 쓸때 진동의 세기
      int rainCycleOne = random(150, 350);   //혼자 쓸때 진동 오는 주기

      digitalWrite(randomMotorOne, HIGH);
      delay(rainPowerOne);
      digitalWrite(randomMotorOne, LOW);
      delay(rainCycleOne);
    }
  }
  else {
    // 많이 오기 시작, 숫자 큼 / 안구부러짐 / 둘이 씀

    for (int i = 0; i < 20; ++i)
    {
      int randomMotorTwo = "c + random(1, 15)"; //진동 오는 코인을 랜덤하게
      int rainPowerTwo = random(100, 40);        //둘이 쓸때 진동의 세기
      int rainCycleTwo = 350 - i * 10;       //둘이 쓸때 진동 오는 주기

      digitalWrite(randomMotorTwo, HIGH);
      delay(rainPowerTwo);
      digitalWrite(randomMotorTwo, LOW);
      delay(rainCycleTwo);
    }
    //많이 옴 / 음악재생 / 커진 후 쭉 반복
   
    mp3_play();
    for (int i = 0; i < 1000; ++i)
    {
      int randomMotorThree = "c + random(1, 15)"; //진동 오는 코인을 랜덤하게
      int rainPowerThree = random(100, 125);        //둘이 쓸때 진동의 세기
      int rainCycleThree = random(50, 100);       //둘이 쓸때 진동 오는 주기

      digitalWrite(randomMotorThree, HIGH);
      delay(rainPowerThree);
      digitalWrite(randomMotorThree, LOW);
      delay(rainCycleThree);
    }
  }

  Serial.println(flexVal);
}



I'm stuck in

Code: [Select]

int randomMotorOne = "c + random(1, 15)";


this parts. I know it's wrong cuz that isn't int.

But I don't know how 'randomMotorOne' can give me series of [c1, c3, c14, c11...] randomly :(

jremington

Code: [Select]
int randomMotorOne = "c + random(1, 15)"; Quote marks identify a string constant (character array). Remove them.

Jeremystorm

thanks jremington again :)

to randomize that result

I made it this way

Code: [Select]

int listOfMotor[14] = {12, 13, A0, A1, A2, A3, A4, 11, 10, 9, 8, 7, 6, 5};
int randomMotorOne;

int rainPowerOne = random(75, 125);     //혼자 쓸때 진동의 세기
int rainCycleOne = random(150, 350);   //혼자 쓸때 진동 오는 주기
randomMotorOne = listOfMotor[random(14)];

digitalWrite(randomMotorOne, HIGH);
delay(rainPowerOne);
digitalWrite(randomMotorOne, LOW);
delay(rainCycleOne);


thank you for your advice for  'Blink without delay' :)

I'm working on it now!

Tahreem_Khan

Hi! I just wanted to ask that i am not directly connecting my vibrator to 3.3V but I am connecting it with an I/O pin that is GPIO12 so that it vibrates whenever i send it an alert.
So my question is, can i connect it directly to the pin without any circuit attached?

Wawa

So my question is, can i connect it directly to the pin without any circuit attached?
No, a vibration motor draws more current than an I/O pin can provide.
You must use a resistor/transistor/diode, as explained in the link in post#1.
Leo..

Go Up