Pages: 1 [2] 3 4 5   Go Down
Author Topic: TIP-120 bi-direction motor control  (Read 5460 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also still need to make sure that these 2 transistors are not going to both be powered trying
to turn the motor in opposite directions of each other and causing a short or other problems.
You haven't posted your schematics and I don't know how you can wire two relays in such a way that the motor could be trying to be driven in two directions at once. It sounds like a poor circuit if this is the case. Using two relays you implement a reversal of the motor as shown in this page:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html 
There is no way that can be commanded to go wrong.

Quote
But where to insert the IF statement?
Don't tempt me!
Read what I said:-
In place of the switch statement just use compound ifs.
So you replace the switch statement with a string of compound ifs

Quote
I like the idea of
Quote
if(letter == 'F' || pushButton == true) { // do your stuff
although I am sure the coding of this is not quits as simple. It would be nice to know the
Syntax.
Yes it is that is the syntax where letter is the variable with the command letter in and pushButton is the Boolean variable with the state of the button in.
Logged

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Read what I said:-
In place of the switch statement just use compound ifs.
So you replace the switch statement with a string of compound ifs

I read what you said, what I am wondering is how will the device know what the different parts are;

if(letter == 'F' || pushButton == true) { // do your stuff

I got the "letter == 'F'" as in You press "F", but how does it know what "letter" is or "pushButton == true" how does it
know what these things refer to? Where is that written?

This is why I was asking for an example and showed my example over again.

The relays I am working with are already built into the motor, I have never actually tried turning them both on at the same time.
Maybe I will disassemble one and see how they are actually wired. I was working on the side of caution as to not wanting both
of them enabled at the same time. It am still testing here and seeing what is available out there. We will call this - still gathering ideas =)
Logged

He who dares, Wins.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I got the "letter == 'F'" as in You press "F", but how does it know what "letter" is or "pushButton == true" how does it
know what these things refer to? Where is that written?

Well in your code how does it know what inByte is?

Come on put in a bit of effort.

Hint:-
1) in my code letter is the same as inByte in your code.
2) how do you think you will get the state of a push button's state into a variable? Could it be something to do with reading the digital pin it is attached to?
Logged

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

inByte is defined in" int inByte = Serial.read(); " so that it is listening for the ASCII value of the keyboards characters.

Could you define anything you wanted to be in the place of the inByte?

Could call it " letter " letter = Serial.read() ?


Code:
void loop() {
  int digitalValue = digitalRead(digitalPin);

  if (digitalValue = HIGH) {
    pushbutton = true;
  }

Wow, I am really bad at this.
The reason it take a bit to reply is I am looking at code and trying to figure out different ways to put it
together and syntax.

I bet you would laugh your head off at all of the code I have put together on here then erased before I sent this one.
I promise, I am trying.
Logged

He who dares, Wins.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Could call it " letter " letter = Serial.read() ?
Yes you can have any variable (of the right type) on the left sign of an equals sign.

Code:
if (digitalValue = HIGH)
no it should be:-
Code:
if (digitalValue == HIGH)
anyway it is even simpler than this:-

Code:
boolean pushbutton = digitalRead(digitalPin);

will do it.
Logged

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So why 2 "="?

I will play with this here in a little bit after I have the Arduino back in front of me.

Thanks for the help.
Logged

He who dares, Wins.

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
He's using relays for the real power.
If he is then there is no need at all to worry about the order the relays are energised as taking a motor to the same potential will only help stop the motor before reversing the rotation. In fact it is probable a good idea to have a brief time in this state to prevent damage to the motor. 

With normal two-pole two-relay wiring, energizing both relays at the same time will actually create a short from power to ground. You *really* don't want that :-)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So why 2 "="?
Two == is the logical comparison operation, one = is the assignment operation. It's how the language works.

Use the reference page in the help menu to see the correct syntax for all the commands.

Quote
With normal two-pole two-relay wiring, energizing both relays at the same time will actually create a short from power to ground.
Rubbish, show me the schematic!
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If two relays are to be used, one might use something like below:

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes so how can that create a short to ground?
A neater diagram is:-
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The short-to-ground comes up if you have breaking relays instead of switching relays (two isolated breakers that switch at the same time).

Relay 1 wires switch 1 from +Ve to motor A and switch 2 from Gnd to motor B.
Relay 2 wires switch 1 from +Ve to motor B and switch 2 from Gnd to motor A.

Sorry, no illustration here :-)

Pulling both on at the same time creates a short. Hence, the switch-relay version you show is safer!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Sorry, no illustration here :-)
Sorry I can't picture that explanation. You seem to be talking about two motors and two relays. Can you draw it and post a photograph of it?
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Note that the design above shorts the motor when it's not running, which will make it brake (because the magnets will work as a generator with infinite load).

The design I was thinking about de-couples the motor when not running, so it will free-wheel -- but has the notable draw-back that it shorts the motor voltage if you pull both relay 1 and relay 2 at the same time.



* other-motor.png (19.56 KB, 500x500 - viewed 102 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well OK I will give you that.
However, you are using a more expensive relay (two pole change over in place of one pole change over) and your only "win" is free wheel breaking, which I think is the last thing you need if you are trying to control a robot.
So while that would work I would think only an idiot would use that wiring.
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So while that would work I would think only an idiot would use that wiring.

Does saying that make you feel better? Because, if so, I will happily defer to your judgement. Christmas spirit and all that :-)
Logged

Pages: 1 [2] 3 4 5   Go Up
Jump to: