Hooking up deadbolt motor to TB6612FNG Stepper Motor Controller - Page 1
Forum section: electronics / projects

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 05, 2016, 08:52:26 am
content: 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 boardEach pin and its function is covered in the table below.Code:Pin Label Function Power/Input/Output NotesVM 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 speedA01/B01 Output 1 for channels A/B Output One of the two outputs to connect the motorA02/B02 Output 2 for channels A/B Output One of the two outputs to connect the motorNow, 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 ModeH H H/L L L Short brakeL H H L H CCWL H L L L Short brakeH L H H L CWH L L L L Short brakeL L H OFF OFF StopDon’t forget STBY must be high for the motors to drive.And the data sheet on the TB6612FNG ishttp://www.sparkfun.com/datasheets/Robotics/TB6612FNG.pdf.I found a great tutorialhttp://bildr.org/2012/04/tb6612fng-arduino/] 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!

author: CM800
author_rank: Frequent Contributor
timestamp: November 05, 2016, 09:57:13 am
content: See page 7 of the manual, it shows exactly how to wire up the motor.I'd suggest wiring up the two switches to the arduino too so you know when to stop in each direction.The motor will only want 5-6V on the full-bridge too.The schematic on page 7 shows two of those motors on it, naturally you only need to connect one.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 05, 2016, 02:48:56 pm
content: Quote from: CM800 on November 05, 2016, 09:57:13 amI've been told that this is not a stepper motor. Its a series motor..The deadbolt is the Kwikset Powerbolt 2 Touchpad keyless entry.http://www.kwikset.com/products/details/electronic-locks/907-2-3.aspx] http://www.kwikset.com/products/details/electronic-locks/907-2-3.aspxI can take some measurements of voltage is needed.

author: Ian.M
author_rank: Super Contributor
timestamp: November 05, 2016, 03:41:49 pm
content: You can bet its not a series motor. Its almost certainly a permanent magnet DC motor, which is the commonest type of low voltage low power motor.Assuming that's a four cell battery holder under the FCC sticker, you've probably got a 5V motor there. Unplug the motor and measure its DC resistance so we can estimate the stall current.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 05, 2016, 05:25:29 pm
content: Quote from: Ian.M on November 05, 2016, 03:41:49 pmI'm measuring around 50ohm

author: Ian.M
author_rank: Super Contributor
timestamp: November 05, 2016, 05:30:57 pm
content: So at 5V, it will draw about 100mA at startup or when stalled, which is well within the capabilities of your driver chip.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 05, 2016, 06:22:17 pm
content: Quote from: Ian.M on November 05, 2016, 05:30:57 pmWell thats a good thing... but what i really need to know is HOW to hook it up to the motor so I dont blow something

author: IanB
author_rank: Super Contributor
timestamp: November 05, 2016, 06:46:11 pm
content: Quote from: Stealthrt on November 05, 2016, 06:22:17 pmYou learn by experimenting. If I had all the parts you show in your first post I would sit down at at my worktop with a battery, a meter and some wires and I would try things out to see what happens. I don't "know" how to hook up the motor right now because it is not in my hands, but if I were holding it I would know within an hour or two.

author: Ian.M
author_rank: Super Contributor
timestamp: November 05, 2016, 07:39:09 pm
content: That's pretty easy. 'CM800' has already directed you to the diagram on page 7 of the datasheet. Alternatively, there's a guide for the breakout board here:https://learn.sparkfun.com/tutorials/tb6612fng-hookup-guide, the only differences being that you would only connect one motor, and the supply should be +5.0V regulated with a generously sized decoupling cap right at the motor control board in place of the 3V 2xAA cell supply shown by the hookup guide. N.B. DO NOT attempt to power the motor from the Arduino on board regulator.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 20, 2016, 04:14:26 am
content: 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 B02int STBY = 6; //standby//Motor Aint PWMA = 3; //Speed controlint AIN1 = 4; //Directionint AIN2 = 5; //Direction//Motor Bint PWMB = 3; //Speed controlint BIN1 = 4; //Directionint BIN2 = 5; //Directionvoid 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, leftmove(2, 50, 1); //motor 2, full speed, leftdelay(1000); //go for 1 secondstop(); //stopdelay(250); //hold for 250ms until move againmove(1, 50, 0); //motor 1, half speed, rightmove(2, 50, 0); //motor 2, half speed, rightdelay(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-clockwisedigitalWrite(STBY, HIGH); //disable standbyboolean 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 standbydigitalWrite(STBY, LOW);}

author: amyk
author_rank: Super Contributor
timestamp: November 20, 2016, 05:09:00 am
content: You did not buy a stepper motor controller but instead a dual H-bridge, and that is not a stepper motor. Check that it workswithoutthe Arduino first, just switch the H-bridge inputs manually. It would also be a good idea to check that the motor works from your power supply without anything else too. Measure voltages.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 20, 2016, 02:03:00 pm
content: Should the motor turn when i apply 5vdc to the red wire and gnd for the black wire? It does nothing when doing that.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 20, 2016, 02:26:08 pm
content: This is how I did my layout:

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2016, 02:36:31 pm
content: Yes it should spin. As you have it out of the mechanism there shouldn't be anything stopping it. I assume the shaft turns freely - if its stiff or jammed, the motor itself may have a problem.From the look of the mechanism., its designed to reverse if you reverse the motor polarity. +5V on Red and 0V on Black should be one direction, and +5V on Black and 0V on Red the other.I think I see your problem - the long breadboard has split bus strips indicated by the gap in the red and blue lines down each edge. If you want continuous power and ground rails you MUST jumper the two halves together to make a full length bus strip.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 20, 2016, 04:09:29 pm
content: Quote from: Ian.M on November 20, 2016, 02:36:31 pmOK i jumped them but I still get nothing. However, I hooked the RED wire up to 5vdc and the BLACK wire to gnd and it does spin clock-wise. Reversing that it does spend counter-clockwise so thats good news.

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2016, 05:01:26 pm
content: Also the TB6612 breakout board should be fitted with pin headers, soldered in place. You'll never get a reliable connection if you just put a jumper wire pin through its pad holes into the breadboard. Although it is possible to use a PTH pad hole as a socket for an appropriately sized resilient pin (split or sprung), jumper wire pins are solid and either wil be too loose or so tight they damage the hole plating.

author: Stealthrt
author_rank: Regular Contributor
timestamp: November 20, 2016, 05:41:50 pm
content: 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?

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2016, 06:19:38 pm
content: No. You'll want to use a pin in digital INPUT_PULLUP mode for each switch. You are correct that the other side of the switch should be ground.

author: Stealthrt
author_rank: Regular Contributor
timestamp: December 01, 2016, 12:21:39 am
content: 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 voltageWhat would be the best resistor to use to make sure it pulls all the way down to 0vdc?

author: amyk
author_rank: Super Contributor
timestamp: December 01, 2016, 03:41:07 am
content: No, analog inputs are for continuously varying... analog values. The limit switch is binary. Just make sure your input Vih(min) is less than 3.3V and it should be OK to connect it directly.

author: Ian.M
author_rank: Super Contributor
timestamp: December 01, 2016, 06:14:54 am
content: A switch does NOT provide a voltage. Whatever voltage you are measuring is coming from the existing control board which you are replacing with your Arduino circuit.Please confirm that the limit switch, unplugged from the control board, has continuity when not engaged and is open circuit when engaged at the limit.Either use digital INPUT_PULLUP mode which activates the Arduino's internal pullup on that pin, or use external 10K pullups to 5V.

author: Stealthrt
author_rank: Regular Contributor
timestamp: December 02, 2016, 03:55:18 pm
content: I failed to mention that I will be using a ESP8266 esp-12F so I'm not sure that has the pull up?

author: Ian.M
author_rank: Super Contributor
timestamp: December 02, 2016, 06:10:47 pm
content: If not, use external 10K pullups to the MCU Vdd (not 5V if its a 3.3V MCU).

author: Stealthrt
author_rank: Regular Contributor
timestamp: December 02, 2016, 11:41:25 pm
content: 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:

author: Ian.M
author_rank: Super Contributor
timestamp: December 03, 2016, 12:28:21 am
content: Generally one connects switches between Gnd and the digital input, with a pullup resistor to Vdd (MCU supply) - its slightly less risky if something shorts, and its easy enough to invert the bit read in software, but the circuit you have shown will work.