Tutorial 2

Site map :

Various stuff
Adder
Rotation sensor
Towers
Security device
The Robot pages
Lego Ants
Robotarm v1.0
Robotarm v3.0
Computer-robot
Circuitry
Program
Tutorial 1
Tutorial 2
Physics of Lego
Measurement
Motors
Measuring strength
Combining motors
Stepper motors
Ratchets
Lego ratchet
Electronic ratchet
Multiplexors
1-to-2 multiplexor
2-to-7 multiplexor
Pneumatics
Pressure
Regulator
Measure
Control
RCX Mindstorms
Survey of RCX programming
PRO-BOT
History
Examples
The famous machines
Turing machine
New Page 1
References and links

Last upgrade to the site:
august 10th, 2002.

There has been 

access to my Lego pages since creation.

This is an unofficial LEGO® web site.
LEGO® is a trademark of the LEGO® Group of companies which does not sponsor, authorize or endorse this site.
You can visit the official LEGO website at: http://www.lego.com

Copyright 1996, 2000, Denis Cousineau

 

Tutorial 2:

How to make it

  1. Understanding the parts

    1. DPTP Relays.

    2. Relays are switch that can be turned on and off using electricity (relays cost ~1.50$). They are electromagnetic switch, which means that a magnet is responsible for turning the switch. Relays can drive a voltage +V that is as large as you need (using the appropriate relay, of course) will being controlled by a power +Vcc that can be small (usually 5 V). This mean that with a computer (working on 5 V, with very small power ~.05 Ampere, you can control a motor of 9 V, 1 ampere, like the Lego motors).

      The previous diagram illustrates the different parts of the DPDT relays. The all have 8 pins, two on one side and the remaining 6 on the other side. Normally, a power voltage is applied to the pin labeled +V, and the opposite pin is connected to the ground (not pictured here). This current will get out thru pin a, can be send to a load (such as a motor), and must be send to c so that it can connect with ground. In this situation, pins b and d are passive. If current is applied to +Vcc and the opposite pin is connected to ground, things are reversed: a and c become passive, will b and d drive the +V power. Therefore with this kind of relay, you can choose to either power one appliance or another.

       

      For a test: Using a power source (such as a Lego battery pack, or a wall transformer –be sure that the voltage is smaller than 10 volts), connect one of the pin on one side of the relay to the positive end, and the facing pin the other contact. Immediately, you should here an audible click: the relay has just switch from a-c to b-d which mean it is working properly. If not, reverse the connections.

       

    3. The transistor as a switch

    4. There exist a large number of transistor, but they all are either NPN or PNP. In the designs that will follow, it is important that you use NPN transistors, such as the 2N2222 (Transistors costs ~0.50$). Transistors have three pins, labeled on the case: c (collector), b (base) and e (emitter). The transistor must always be placed *after* the load, so that pin e is link to the ground. The load can be merely anything: a light, a motor… that normally works with a voltage of +Vcc (DC). But instead of connecting the load to the ground, you connect it to the c pin of the transistor. The b pin of transistor is used to turn on or off the load, by applying a very small current. The R represents a resistor. It is used as a protection if you use a computer to send a small current (in this case, it should be a 1 kilo-ohm resistor). When the transistor turns on, you won’t hear a click, since it is a "solid-state" device (which means it is not a mechanical device).

      For a test: As a load, we can use a led (a small light). It need to be connected serially with a 3.3 kilo-ohm resistor; the resistor can be before or after the led, it does not matter). The +Vcc power voltage can be two batteries of 1.5 volts, connected serially.

      1. If you replace the resistor R in the above diagram by a more powerful resistor (say about 10 kilo-ohm), you can use the batteries. With a wire, make a contact between the +pole of the battery and R, and at that time, the led should light. If you use another set of batteries to control the transistor, remember the golden rule: all the grounds must be connected together. Ground is also named the common point for that reason. Therefore, the – poles of the two sets of batteries should be in contact with a wire.
      2. Keeping the led as a load, we can use a computer to send a small current. Using Qbasic, type the following program:

      OUT &H378,1
      INPUT "Pin 2 is now on, press enter to turn it off", p$
      OUT &H378, 0
      INPUT "Pin 2 is now off, press enter to end", p$

Now, connect the pin 2 of your printer port LPT1: (be sure to identify the correct pin, most of the time, pins are numbered on the printer cable) to the resistor R; also connect the pin 25 to the ground (remember: all ground must be connected together). If you run the program above, the led should light, and then be turned off. In the above program, 378 is the address of your printer port (you can see it when you start your computer, in the diagnostic box following the memory test).

 

  • The H-Bridge circuit

  • Basically, the direction of motion of a motor depends on the way it is connected. If the right pole is connected to +Vcc, the motor will turn clockwise, while the opposite will occur if +Vcc is connected to the left pole. A H-bridge is the superposition of the two at the same time. In the following diagram, if switch a and c are turn on, the motor will turn clockwise, while if b and d are turned on, the rotation will be counter clockwise. If both (a and d) or (b and c) are on, the motor will not turn since the current will flow directly from Vcc to ground (electricity always tries to avoid load).

     

     

     

  • Putting it all together

    1. Controlling the position of the relay

    2. The first thing is to be able to trigger the relay using the computer. You can use pin number 2. +Vcc must be a power source compatible with the relay specification. If thing works fine, you should be able to hear the thick when relay turns on.

       

    3. Making an H-bridge circuit with a DPDT relay

    4. The DPTP relay is in fact a very convenient way of implementing an H-bridge. When the relay is not connected, a and c are conducting current, therefore, +V makes the motor turning clockwise. If the relay is activated, b and d are conducting, and try it, the motor will turn counter clockwise. The only way current from b can return to ground is to pass through the load (the motor). The nice thing is that (a and d) or (b and c) cannot be both on at the same time.

       

    5. Turning on and off the motor.

    6. The motor in the previous design is either turning clockwise or counter clock wise, but never stop. We will consider the H-bridge as a load, and use a transistor to turn this load on or off. For that, we need another computer pin, for example, pin 3 (use PORT &H378, 2 to turn it on, and PORT &H378, 2+1 for both pin 2 and 3 at the same time).

       

  • The final schematic and physical implementation

    1. The schematic

    2. In order to realize an electronic project, you need to go through 4 steps: making a schematic of the circuit, that is an abstract representation of the pieces and how they are connected together. The above diagrams are all schematic. Next, you need to device how the pieces will be actually connected (that is physically). You have to think both of the component placement on the one side of the circuit board, and the traces (the connections) on the other side of the board. Finally, you have to actually make the circuit. This is certainly the most difficult part, the one that require the largest amount of patience.

       

    3. The physical plan

    4. The following plan is one of the possible plan we can come with. I tried to make it narrow, so that I can put multiple instance of this circuit, in order to control multiple motors. The direction span on a long trace, so that it can control the direction of the other motors as well. This is not a necessary restriction though.

       

      Components Side

      Component list

      RL1

      Relay

      DPDT

      T1, T2, T3

      Transistors

      2N2222 (NPN)

      BR1, BR2

      Bridge

      (wire)

      D1

      Diode

      1N4001

      R1, R2

      Resistors

      1 K ohms

      ST1 to ST6

      Connectors

      One- and two pins

       

      Trace Side

       

      Connection list

      ST1

      Direction

      Pin #8 of DB25 cable

      ST2

      Ground

      power supply

      ST3

      Power

      +9v

      ST4

      On/Off

      Pin #2 of DB25 cable

      ST5

      To device

      Motor

      ST6

      Ground

      Pin #25 of DB25 cable

    5. The result

    6. In the following pictures, I used a different plan. Instead of soldering the pieces directly on the board, I soldered 18-pin sockets, and the pieces are pined on the sockets. It makes replacement of pieces easier, in case a transistor is burned (this sometimes occurs if you short-circuit two wires – you know by the odor).

      With the program described elsewhere in this site, you are able to control up to seven Lego motors.