A Robotic Elevator using Lego & Arduino – Part 3
- Part 1: Mechanical Design Basics.
- Part 2: Balancing the Elevator.
- Part 3 (current): Electronics (optocoupler, H-Bridge, and more).
- Part 4: Software to control the Arduino.
In the first two parts of this series, we have introduced the mechanics of our Lego-based elevator and we discussed how to balance it to lift some load. Today, we will be discussing the connection between the Lego Mindstorms’ motor and touch sensors with an Arduino board.
Lego Components Characteristics
First things first, we need the characteristics of the Lego components of our elevator. The philo’s web site is THE place for this. It provides info about different Lego motors including the Mindstorm ones. We are using the RCX which motor current can goes up to 120 mA depending on the load. The voltage varies between 4.5 V and 12 V . Changing the voltage changes the rotation speed from 57 rpm (4.5 V) up to 375 rpm (12 V).
Regarding the touch sensors, getting the info is much easier. Just plug it to a multimeter set to measure the resistance. The Lego touch sensor embeds a potentiometer. When nothing is sensed, the resistance is infinite, meaning that there is no contact. But, when the sensor is touched, its resistance varies from approximatively 500 Ohms (strong pressure) up to 1.5 kOhms (light pressure).
The H-Bridge
We will be using an Arduino Uno Board. The maximum current that can be provided by each pin is 40 mA, which is far below what the Lego motor might require. To avoid burning the Arduino board, we need a power amplifier. The best way to go is to make an H-Bridge to control the motor (see Picture 1).
Picture 1: H-Bridge
The logic behind the H-Bridge is easy. The four transistors (T1 to T4) are used as electronic switches. When they are ON, they can deliver current to the motor. When they are OFF, no current can flow through their collectors. In an H-Bridge, transistors switch in pairs to allow the motor rotate either forward or backward. To make forward rotations, transistors T1 and T4 are switched OFF, while T2 and T3 are turned ON (See Picture 2a). For backward rotations, we use the opposite configuration (see Picture 2b): T1 and T4 are ON, while T2 and T3 are OFF.
Picture 2a: H-Bridge set for motor forward rotation | Picture 2b: H-Bridge set for motor backward rotation |
The Full Circuit
Our H-Bridge will be driven by the Arduino board, which leads us to the voltage issue. The Arduino operates at 5 V, while we have chosen to use 12 V for the motor since we found that it leads to a higher lift power. Thus, we need to insulate electrically the Arduino board from the H-Bridge. The best option is to use optocouplers (also known as opto-isolators). They allow transmitting Arduino signals to turn transistors ON and OFF by means light only. Hence, the Arduino is protected while still controlling the H-Bridge. The full circuit is provided on Picture 3, where only used pins of the Arduino board are represented. The internals of the quad-optocoupler chip CNY74-4 are also represented in grey for sake of easing understanding.
Picture 3: Full circuit of the elevator
We use 6 pins of the Arduino: two for power and 6 for controlling the elevator. Pins number 2 and 3 are used in input mode. They allow detecting when the elevator’s touch sensors are pressed, that is when the elevator is at its maximum or minimum height. Pins 6 and 7 are also in input mode. They are connected to push buttons that allow driving the elevator up or down.
Whenever a push button is pressed the appropriate pair of transistors of H-Bridge is switched on through pins 10 and 11. This obviously means that these two last pins are in output mode. These two pins are enough to control the 4 transistors of the H-Bridge, since transistors function in pairs.
Tips and Tricks
Regarding transistors, we have chosen to use TIP 122 and TIP 127 ones. Those are darlington transistors that can deliver high power, up to 65 W. That is much beyond what we need for the lego motor. So, we can reuse the circuit for controlling other motors in the future.
It is also worth mentioning that the circuit uses color LEDs at different stages. While this makes the circuit look nice, the actual reason is to help debugging. The green and the red LEDs signal that touch sensors are pushed. Yellow and Pink LEDs turn ON when the motor is commanded to rotate forward or backward.
The last tip is that we recommend using a screw shield for the Arduino. It makes life easier for connecting your circuit to the Uno. For smaller circuits, an alternative is to use an Arduino shield that integrates a mini-breadboard. Last, for the lazy, there is an Arduino motor shield that includes the optocouplers and the power transistors.
Leave a Reply