CxD Archive
Code: Robotics
Code: Robotics
  • Code Introduction
  • TUTORIALS
    • A. Meet Your Robot
      • A-1 Circuit Board
      • A-2 Motors and Wheels
      • A-3 Other Components
    • B. Hello World Test
      • B-1 Arduino Code Editor
      • B-2 New App Template
      • B-3 Global Variable
      • B-4 Setup Function
      • B-5 Loop Function
      • B-6 Upload App to Robot
      • B-7 Add Sound
      • B-8 Use Button
    • C. Driving and Turning
      • C-1 Driving
      • C-2 Turns (Pivoting)
      • C-3 Test Wheel Encoders
      • C-4 Drive for Specific Distance
      • C-5 Pivot By Specific Angle
      • C-6 Drive Straight Continuously
    • D. Detect Objects in Path
      • D-1 Test Mechanical Bumpers
      • D-2 Detect Collisions
      • D-3 Test Ultrasonic Sensor
      • D-4 Avoid Collisions
    • E. Detect Lines on Surface
      • E-1 Test IR Line Sensors
      • E-2 Follow Line
      • E-3 Avoid Line
      • E-4 Count Lines Crossed
      • E-5 Follow and Count Lines
    • F. Detect Other Conditions
      • F-1 Detect Surface Drop-Off
      • F-2 Test Accelerometer
      • F-3 Detect If Upside-Down
      • F-4 Detect If Bumped
  • REFERENCES
    • Arduino Language
    • Arduino Code Editor
      • Create New App
      • Save and Rename App
      • Include RedBot Library
      • Verify App Code
      • Upload App to Robot
      • Download Copy of App
      • Use Serial Monitor to View Data
      • Robot Demo App Template
    • Physical Inputs
      • Push Button (D12)
      • Mechanical Bumpers
      • IR Line Sensors
      • Wheel Encoders
      • Accelerometer
      • Ultrasonic Sensor *
    • Physical Outputs
      • LED Light (D13)
      • Speaker (Buzzer)
      • Motors
    • Robot Behaviors
      • Producing Alerts
      • Driving
      • Turning
      • Detecting Objects
      • Detecting Lines
      • Detecting Other Conditions
    • Navigation Modes
      • Distance Navigation
      • Line Counting Navigation
      • Line Following + Counting Navigation
      • Autonomous Navigation
  • LINKS
    • Robotics Project Guidebook
    • Arduino Create Web Editor
    • Arduino Language Reference
    • RedBot Experiment Guide
  • ELEGOO Experiments
    • Getting the Arduino IDE
    • Starting with the `techCar` Template
    • Template Code for techCar.ino
    • Template Experiments
    • Reinstall the Original Remote App Functionality, If Needed
Powered by GitBook
On this page
  • Motors and Wheels
  • Wheel Encoders
Export as PDF
  1. TUTORIALS
  2. A. Meet Your Robot

A-2 Motors and Wheels

PreviousA-1 Circuit BoardNextA-3 Other Components

Last updated 6 years ago

Motors and Wheels

The RedBot is a two-wheeled robot. It also has a semi-circular plastic "nub caster" on the underside of its chassis at the back. This caster acts as a third point of contact to balance the robot (similar to a third wheel, except the caster doesn't rotate).

Each wheel is driven by its own motor, which is connected to the RedBot circuit board by a pair of red and black wires. These left and right motors can be controlled as a set or independently, in order to make the robot drive forward, backwards, or make turns.

You can also determine how much power each motor receives, in order to rotate the wheels faster or slower, to control the speed of your robot as it drives and turns.

Wheel Encoders

Located directly behind each wheel motor is a wheel encoder. The wheel encoder is used to count exactly how many times that motor has rotated. These wheel encoder counts can be used to:

  • make the robot drive in a straight line (by adjusting the motor powers if one motor happens to be rotating slightly faster than the other)

  • calculate how far the robot has driven (by determining how many times the wheel has turned and multiplying that by the wheel circumference)

The wheel encoder actually consists of two parts:

  • a Hall Effect sensor that can measure the strength of a magnetic field

  • a ring magnet (looks like a metal washer) attached to the motor shaft

When the motor rotates the wheel, it also rotates the ring magnet. The Hall effect sensor positioned near the ring detects changes in the magnetic field as the ring rotates. This is how the sensor can count how many times the motor has rotated.

When you think of a magnet, you probably think of a magnet that has 2 poles: north and south. It is true that magnets have pairs of N-S poles. However, a magnet can be created with multiple pairs of N-S poles. The ring magnets attached to the RedBot motors each have 4 pairs of N-S poles, similar to the diagram below.

So as the ring magnet completes one full rotation, the Hall effect sensor detects 4 changes (or "ticks") in the magnetic field as each magnetic pole passes by the sensor.

Each wheel encoder is connected to the RedBot circuit board by a 3-wire jumper cable (white, red, and black wires for data, power, and ground):

  • The left wheel encoder data wire should be connected to I/O pin A2

  • The right wheel encoder data wire should be connected to I/O pin 10

The wheel encoders are one of the most useful sensors on your robot because they can allow your robot to drive straight for specific distances and to make turns of specific angles (such as: 90° right, 90° left, 180° around, etc.).

Motors