# Hooking up deadbolt motor to TB6612FNG Stepper Motor Controller

Status
Not open for further replies.

#### StealthRT

##### Member
Hey all I am in need of some help with hooking up this little motor to the TB6612FNG Stepper Motor Drive Controller that I purchased. I am wanting some feedback on how to go about hooking it up to this deadbolt motor so that I dont mess up the motor. This board will be controlled by an Arduino.

The deadbolt insides look like this:

And the TB6612FNG is this:

Back of the board

Each pin and its function is covered in the table below.
Code:
     Pin        Label                      Function    Power/Input/Output Notes
VM         Motor Voltage              Power       This is where you provide power for the motors (2.2V to 13.5V)
VCC        Logic Voltage              Power       This is the voltage to power the chip and talk to the microcontroller (2.7V to 5.5V)
GND        Ground                     Power       Common Ground for both motor voltage and logic voltage (all GND pins are connected)
STBY       Standby                    Input       Allows the H-bridges to work when high (has a pulldown resistor so it must actively pulled high)
AIN1/BIN1  Input 1 for channels A/B   Input       One of the two inputs that determines the direction.
AIN2/BIN2  Input 2 for channels A/B   Input       One of the two inputs that determines the direction.
PWMA/PWMB  PWM input for channels A/B Input       PWM input that controls the speed
A01/B01    Output 1 for channels A/B  Output      One of the two outputs to connect the motor
A02/B02    Output 2 for channels A/B  Output      One of the two outputs to connect the motor
Now, for a quick overview of how to control each of the channels. If you are using an Arduino, don’t worry about this too much as the library takes care of all of this for you. If you are using a different control platform, pay attention. When the outputs are set to High/Low your motor will run. When they are set to Low/High the motor will run in the opposite direction. In both cases, the speed is controlled by the PWM input.
Code:
    In1  In2 PWM Out1 Out2 Mode
H    H   H/L L    L    Short brake
L    H   H   L    H    CCW
L    H   L   L    L    Short brake
H    L   H   H    L    CW
H    L   L   L    L    Short brake
L    L   H   OFF  OFF  Stop
Don’t forget STBY must be high for the motors to drive.

And the data sheet on the TB6612FNG is http://www.sparkfun.com/datasheets/Robotics/TB6612FNG.pdf.

I found a great tutorial http://bildr.org/2012/04/tb6612fng-arduino/ but want to make sure I hook up the wires correctly for this deadbolt motor and thats why I ask someone whos more knowledgeable about these types of things to help me out.

Thanks!

#### ronsimpson

##### Well-Known Member
Beautify done pictures. Good data.

I don't think you have a stepper motor.

#### Les Jones

##### Well-Known Member
Hi Ron,
That was my first thought when looking at the picture of the motor. I suspect that he just wants to us the H bridge to drive the motor in forward and reverse. As there was no information supplied on the deadbolt I did not reply. The picures appear to show limit switches but there seems to be too much electronics in it for it to work just by supplying power in one polarity to close and the other to open. Mayby he will post the information on the deadbolt.

Les.

#### StealthRT

##### Member
Hi Ron,
That was my first thought when looking at the picture of the motor. I suspect that he just wants to us the H bridge to drive the motor in forward and reverse. As there was no information supplied on the deadbolt I did not reply. The picures appear to show limit switches but there seems to be too much electronics in it for it to work just by supplying power in one polarity to close and the other to open. Mayby he will post the information on the deadbolt.

Les.
You are correct. I just want to be able to open the lock and close the lock with the arduino.

The deadbolt is the Kwikset Powerbolt 2 Touchpad keyless entry. http://www.kwikset.com/products/details/electronic-locks/907-2-3.aspx

I can take some measurements of voltage is needed.

#### Tony Stewart

##### Well-Known Member
Start by defining all the "interface and power surge/steady and average requirements and power fail thresholds, signal immunity etc. fault detection etc. Then decide how to implement. Test it if there are no good specs with variable voltage range etc.. i.e. use a 50mV sized current shunt on gnd to measure I and V vs load force with your finger or some friction and how to avoid stall currents which will always be 10x max rated and same for full speed accleraton from start.

See if active current limit is used or detected with suitable external current limit protection. i.e. LDO current source to a voltage source for test purposes only. Check for max hot spot when testing with your finger or thermocouple, thermistor.thermometer. If too hot to touch, its too high. Current = motor torque and excess friction (jammed) will stress the plastic gears. The two gear tooth sensors tell me it should be well-protected and they are out of phase with gear-tooth position for quadrature sensing.

SHort Brake means the bridge shorts out the coil back EMF (either + or - V, so it stops fastest. STOP means it coasts to a stop with inertia and open circuit on bridge driver.

Last edited:

##### Well-Known Member
The motor is a DC brushed by the look of it, and the TB661FNG is for controlling two DC brushed motors according to specs.
Max.

#### Les Jones

##### Well-Known Member
Are you connecting directly to the motor or using it with the electronics shown in the pictures of the deadlock ? Is the keypad shown in your link still going to be connected to the deadbolt ?

Les.

#### StealthRT

##### Member
I will be directly connected to the motor. The keypad will be used as well.

#### Les Jones

##### Well-Known Member
You will have to ensure that the existing drive to the motor does not conflict with the H bridge output. You will also have to add extra limit switches unles you can find a way to get signals from the existing limit switches. If I was doing this I would use two DPDT relays so the motor was disconnected from the internal electronics when your interface was being used.

Les.

#### StealthRT

##### Member
Well i hooked it up to the TB6612FNG and the Arduino and i got....nothing.

Code:
//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 6; //standby

//Motor A
int PWMA = 3; //Speed control
int AIN1 = 4; //Direction
int AIN2 = 5; //Direction

//Motor B
int PWMB = 3; //Speed control
int BIN1 = 4; //Direction
int BIN2 = 5; //Direction

void setup(){
pinMode(STBY, OUTPUT);

pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);

pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}

void loop(){
move(1, 50, 1); //motor 1, full speed, left
move(2, 50, 1); //motor 2, full speed, left

delay(1000); //go for 1 second
stop(); //stop
delay(250); //hold for 250ms until move again

move(1, 50, 0); //motor 1, half speed, right
move(2, 50, 0); //motor 2, half speed, right

delay(1000);
stop();
delay(250);
}

void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise

digitalWrite(STBY, HIGH); //disable standby

boolean inPin1 = LOW;
boolean inPin2 = HIGH;

if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}

if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}

void stop(){
//enable standby
digitalWrite(STBY, LOW);
}

#### StealthRT

##### Member
Should the motor turn when i apply 5vdc to the red wire and gnd for the black wire? It does nothing when doing that.

#### StealthRT

##### Member
This is how I did my layout:

#### StealthRT

##### Member
Ah it seems to be working now. YAY!

Just need to tweak the code a little and hook up the limit switches to the analog inputs and see if i get readings from them. That would just consist of grounding one side and running the other to the arduino analog pin, correct?

##### Well-Known Member
Ah it seems to be working now. YAY!

Just need to tweak the code a little and hook up the limit switches to the analog inputs and see if i get readings from them. That would just consist of grounding one side and running the other to the arduino analog pin, correct?
Wouldn't you want to connect the limit switches to the DI (Digital Inputs) rather than the AI (Analog Inputs)? The existing unit likely has pull up resistors on the limit switches. I would measure across the limit switches under normal operation and see what you have.

Ron

#### StealthRT

##### Member
Alright so I finally got around to testing out the limit switch. Seems the Left pin is Gnd and the middle pen is voltage and the right pin is na.

Measuring the limit switch its 0vdc when not engaged and 3.3v when it is engaged.

So knowing that, wouldn't it be best to use an Analog input for measuring the voltage?
Code:
floatvoltage=limitSwitchValue*(3.3/1023.0); //Using 3.3v for max limit switch voltage
What would be the best resistor to use to make sure it pulls all the way down to 0vdc?

##### Well-Known Member
You can use an analog in but the digital in would likely be the better way to go. Here is what I am getting at. Each micro (limit) switch has three terminals and they use two of the three. These are normally a Common, Normally Open and Normally Closed or C / NO / NC and either the NO or NC is tied to a ground. The voltage applied to the Comm terminal is applied through a 10K Ohm resistor (a pull up resistor). When a switch closes or opens depending on configuration the Common pin goes to either 3.3 volts or 5 volts (whatever the Vcc is. Now as to the Arduino I would give this link a read, Defining Logical Levels: true and false (Boolean Constants). You can use an analog in but what you really have is a digital signal, a Boolean True or False. It looks like you have 3 wires from the micro switches. The white appears to be common to both switches with the Blue and another wire I can't make out as the signal wires. I would measure Ground to the Blue and Other Wire when the motor is at limits and see what you get.

Also before I forget you will have a signal off a switch so consider switch bounce in there. You can't just say if analog in is greater than then... I would use a digital in and add a delay of 100 mSec to allow for switch bounce.
A boolean holds one of two values, true or false. (Each boolean variable occupies one byte of memory.)
That link will give you an idea as to adding the delay.

Ron

Last edited:

#### StealthRT

##### Member
is this the correct way of doing it? of course it would be an esp8266 and not an Arduino board and using 3.3v instead of 5v:

#### StealthRT

##### Member
Ron:

...of course it would be an esp8266 and not an Arduino board....