Multiple Servomotors

22,059

Circuit Image

A modified version of the previous program allows control of multiple servomotors, utilizing all available I/O lines on port B. The following listing demonstrates the control of two servos similarly to how a single servo was managed in the earlier program. The associated circuit is depicted in figure 4 below. The program employs two pulse width variables, pw1 and pw2, along with two sets of routines: left1 and left2, right1 and right2, corresponding to each motor. In the schematic, the first servo is connected as in the earlier circuit, while the second servo utilizes B3 for its pulse output, and B4 and B5 are designated for the SPDT switch.

The circuit design facilitates control of two servomotors through a microcontroller's port B, leveraging its I/O capabilities. Each servo is driven by a pulse width modulation (PWM) signal, which is generated using the defined pulse width variables pw1 and pw2. These variables determine the duration of the high signal in the PWM cycle, effectively controlling the position of the servos.

The first servo is connected in accordance with the configuration from the previous program, ensuring a familiar setup for users. The second servo, however, introduces additional complexity by utilizing pin B3 for its PWM signal. Pins B4 and B5 are employed for an SPDT (Single Pole Double Throw) switch, which allows for alternate control modes or functionality. This arrangement can facilitate features such as switching between different servo positions or modes of operation, enhancing the versatility of the circuit.

The routines left1, left2, right1, and right2 are specifically programmed to manage the movement of the respective servos, allowing for coordinated control based on user input or pre-defined sequences. The overall design emphasizes modularity and scalability, enabling users to expand the system further by adding more servos if additional I/O lines are available. The use of pulse width modulation is critical in ensuring smooth and precise control of the servos, making this circuit suitable for applications requiring accurate positioning, such as robotics or automated systems.Using a modified version of the last program, we can control as many servomotors as we have I/O lines on port B. In the next listing, we will control two servos in the same manner as we controlled a single servo in the previous program.

The circuit is shown in figure 4 (below). The program uses two pulsewidth variables, pw1 and pw2; and two sets o f routines, left1 and left2, right1 and right2; one for each motor. As you can see in the schematic, the first servo is wired as per the previous circuit. The second servo is now using B3 as it`s pulse out, and B4 and B5 for the SPDT switch. 🔗 External reference