Arduino Robot Speed and Direction

Arduino Robot Speed and Direction, we will examine robot motor control fundamentals for both two and four-wheeled platforms. The detailed motor controller hardware and the code utilized to enable this feature are included in the drawings.

All sketches use the RobotMotor library, which offers a uniform interface to the hardware-specific motor system. Move, an optional software module, simplifies programming in complex designs by providing high-level methods for robot movement.

MyRobotMove.ino—This sketch demonstrates how to use advanced movement features. The robotDefines tab now includes constants that define the robot’s current movement. The high-level movement features are now accessible through the new Move tab. The IrSensor tab and RobotMotor library remain intact (Fig 7-1).

Arduino Robot

Arduino Robot

Types of Motors

Brushed DC motors, found in two and four-wheeled platforms (see to Figure 7-2), are the most commonly employed in Arduino robots. These have two leads attached to brushes (contacts) that regulate the magnetic field of the coils driving the motor core (armature). To reverse the direction of a motor, reverse the polarity of its power source. Gear reduction is used to lower speed and boost torque in motors that rotate too quickly to directly drive robot wheels or rails.

Arduino robot

Fig 7-2: DC motor with gearbox.

The Robots can be powered by several motor types, including:

Continuous rotation servo

These motors are utilised in miniature robots. The motor controller, motor, and gearbox are all housed in a single enclosure, making them easy to attach to a robot and drive directly from Arduino pins. However, they often provide less torque than standard brushed motors.

Continuous Rotation Servo [FeeTech FS5103R] : ID 154 : Adafruit Industries, Unique & fun DIY electronics and kits

Brushless motors

These motors offer more torque and efficiency than brushed motors, but are more costly and hard to regulate. However, costs are lowering, making them a viable option for bigger robots.

Brushless BLDC Electric Motor Model NFP-BL3229

Stepper motors

These motors are used in large robots that require precision control.
Small battery-powered robots seldom employ motors that require 12 or 24 volts. The current availability of low-cost 5 volt steppers may boost their popularity.

Small Reduction Stepper Motor - 12VDC 32-Step 1/16 Gearing

 

Motor controllers Arduino

The two and four wheel platforms use small DC motors controlled by an H-Bridge. The article features the Adafruit Industries AFMotor shield, which includes the H-Bridge. This can drive up to four motors individually, although only two are used for the two-wheeled robot. This shield requires a library to interface sketch code with hardware.

H-Bridge

To interact with additional H-Bridge hardware, a library called RobotMotor is included with the sample code. This library transforms generic control functions into particular directives for the AFMotor shield or other hardware.

The following diagrams demonstrate the operation of an H-bridge and the RobotMotor functions for controlling motors:

Arduino Motor

Fig 7-3: A motor idled HBridge

Figure 7-3 depicts the schematic of an H-bridge. There are four switches link the motor to the positive supply voltage and ground, while the real H-bridge uses transistors for switching. When all switches are open, no current flows, and the motor will stops. The code for stopping a motor is:  motorStop(motor);

The constant that indicates which motor (MOTOR_LEFT or MOTOR_RIGHT) to control is the parameter enclosed in brackets, motor. The two motors on the same side are handled by the four-wheeled robot’s software as though they were a single motor.

Arduino RobotFigure 7-4 shows the HBridge with the motor running forward.

Figure 7-4 displays two switches that, when closed, cause the motor to go forward. The designated A wire connects the positive motor terminal to the positive power supply. Switch D links the negative motor terminal to the ground. To move a motor forward at the specified speed, use the following code:

motorForward(motor, speed);

The constant speed represents speed as a percentage of maximum speed.

HBridge with motor running in reverse, Figure 7-5

“In Figure 7-5, it is demonstrated that activating the opposite switches leads to the reversal of the motor’s direction. Specifically, Switch C facilitates the connection of the positive supply to the negative terminal of the motor, while Switch B establishes a connection between the positive terminal of the motor and the ground. The following code can be utilized to operate the motor in reverse at the specified speed:”

motorReverse(motor, speed);

 

Arduino Robot

“Figure 7-6 illustrates an H-Bridge configuration featuring Motor Brake functionality.”

“In Figure 7-6, switches B and D are depicted as closed. In this configuration, both motor terminals are effectively shorted together, with neither terminal connected to the positive supply voltage. This operational mode, supported by certain H-bridge hardware, facilitates a quicker stopping of the motor compared to simply disconnecting it from the power source. Due to the shorted motor terminals, the motor will actively resist rotation. Transitioning the motor from a spinning state to this braking mode results in a faster halt than if the terminals were merely disconnected. The following code can be used to implement motor braking:” motorBrake(motor);

“Not all H-bridges, such as the one employed in the Adafruit library, support this braking mode. In the RobotMotor library, when the motor Brake function is called, the library will invoke the motorStop function to halt the motor’s operation.”

Arduino Motor Speed Control

Principles of Arduino Motor Speed Control

Control over motor speed is achieved through Pulse Width Modulation (PWM), a technique that adjusts the ratio of on-time to off-time of the motor. Increasing the proportion of on-time results in greater motor power and faster movement of the robot (refer to Figure 7-7).

Arduino robot

Pulse Width Modulation in Motor Power Control (Figure 7-7)

All code provided in this book adopts a percentage-based approach to denote motor speed. This percentage represents the power allocated to the motors, technically known as the duty cycle. The use of percent speed, rather than raw PWM values, serves to segregate the sketch logic from the intricacies of low-level motor control. Different motor hardware employs varied techniques for regulating motor rotation speed. For instance, continuous rotation servos may utilize servo angles (where 90 denotes a halt and 0 initiates full reverse rotation), while stepper motors do not rely on PWM for speed control. By consistently employing percent values at the high-level logic, which are then mapped to the appropriate range required by the hardware in the motor interface code, the same high-level code can seamlessly function with alternative hardware configurations simply by swapping out the corresponding motor interface module.

you can find the code of Arduino Motor Control here

 

Leave a Reply

Your email address will not be published. Required fields are marked *