Chapter 9: Tinkercad: Integrating Robot as a System
The robotics club of a school in Jaipur decides to build a robot that can follow a black line drawn on the floor of the corridor. The plan sounds simple. Four wheels, two sensors that look at the floor, a small board to do the thinking, and a battery.
Then the trouble starts. There is one robotics kit in the lab and twenty-two students in the club. Nobody wants to be the person who connects a wire wrongly and burns a sensor on the first day.
So the teacher opens Tinkercad on the lab computers instead. It is a free tool that runs in a web browser, and it lets you drag a board, motors, sensors and wires onto the screen, join them, write the program, and press a button to watch the whole thing run. Nothing gets hot. Nothing gets damaged. A wrong connection costs you a click.
By the end of the week every student has a working circuit on screen — and the club has one kit left, still unharmed. See Fig. 9.0-1.
Diagram
Fig. 9.0-1 – a small four-wheeled robot on a white floor with a black line curving ahead of it; two small sensors are shown pointing down at the floor from the front of the robot, and a board with a battery is shown mounted on top
This chapter answers all five of these questions, one at a time, as you build the robot yourself.
9.1 Putting the Pieces Together
So far you have met the parts of a robot one at a time. Gears that pass on turning force. Sensors that pick up something from the surroundings. Actuators that move a joint or a wheel. A controller that ties the two together.
A pile of good parts is not a robot. A sensor that reports a reading nobody reads, or a motor with no instruction to turn, does nothing useful on its own. The parts have to be joined, powered, and told what to do — and they have to be joined correctly.
That joining is called integration: bringing separate parts together so that they work as one system. This chapter is about doing exactly that, and doing it first on a screen.
9.1.1 What Integration Means in a Robot
Think of a school bus. It has an engine, wheels, brakes, a steering wheel and a driver. Each one is fine by itself, but the bus only moves people when all of them are connected and the driver is watching the road. Take away the link between the driver’s eyes and the brake pedal, and the rest is useless.
A robot is the same. Integrating a robot means getting three layers to agree with one another, as shown in Fig. 9.1-1.
Diagram
Fig. 9.1-1 – three stacked labelled blocks for one robot; bottom block “Mechanical layer – chassis, wheels, joints, mountings”, middle block “Electrical layer – board, sensors, motors, motor driver, battery, wiring”, top block “Program layer – instructions that read the sensors and drive the motors”; a two-headed arrow at the side labelled “each layer must match the one below it”
The mechanical layer decides where things sit. If the two floor-facing sensors are mounted too far apart, no program can fix that. The electrical layer decides what is joined to what, and where the current comes from. The program layer decides what the robot does with the readings it gets.
A mistake in any one layer stops the whole robot. That is why integration is treated as a skill of its own, and not as the last ten minutes of a project.
9.1.2 Testing a Robot Before You Build It
Building the real thing first is an expensive way to find out that your plan was wrong. Motors are costly, sensors are easily damaged, and a battery joined the wrong way round can end a project on day one. Most school labs also have only two or three kits for a whole class.
There is a better order of work. Build the robot on a computer first, watch it run there, fix what is wrong, and only then pick up the real parts. This is called a simulation — a model of a real system, run on a computer, that behaves in the same way as the real system for the things you are testing.
A simulated circuit costs nothing when it fails. You can join a wire wrongly, notice that the motor does not turn, and correct it with one click. You can also try a change that you would never risk on real hardware, and every student in the class can have their own copy of the robot at the same time.
A simulation is a useful copy, not a perfect one. It does not know that your floor is dusty, that one wheel drags slightly, or that the battery weakens after an hour. Those problems show up only when the real robot is on the real floor. So a simulation saves you from design mistakes, not from every mistake.
9.2 Tinkercad Circuits
You have already used Tinkercad to design and move the shapes of a robot. The same website has a second workspace, meant for the electronics rather than the shapes. It is called Tinkercad Circuits.
Tinkercad Circuits is a free online workspace, made by Autodesk, in which you place electronic components on a screen, wire them together, write the program for the board, and then run the whole circuit to see what it does. It runs inside a web browser, so nothing has to be installed on the lab computers. You do need to log in with an account.
9.2.1 Key Features of Tinkercad Circuits
Five features do most of the work.
Drag-and-drop workspace. Components are picked from a panel at the side and dropped where you want them. Nothing is typed in to place a part.
Component library. The panel holds the usual classroom parts — resistors, LEDs, push buttons, batteries, DC motors, servo motors, sensors, breadboards, and microcontroller boards such as the Arduino Uno.
Breadboarding. A breadboard is a plastic board full of holes, whose rows are joined underneath, so components can be connected by pushing them in instead of soldering. Tinkercad gives you the same board on screen, laid out exactly like the real one, which keeps a crowded circuit tidy.
Code editor. A board on the workspace can be programmed from inside Tinkercad itself, without any separate software.
Simulation. Pressing one button runs the circuit. An LED lights, a motor turns, a sensor value changes, and you watch it happen.
Diagram
Fig. 9.2-1 – screenshot of the Tinkercad Circuits workspace, with the components panel on the right, the Code and Start Simulation buttons at the top right, and a breadboard and an Arduino Uno sitting on the empty workspace
9.2.2 Creating a New Circuit
Getting a blank workspace takes a few clicks. See Fig. 9.2-1 for where these appear on the screen.
- Open Tinkercad in a browser and log in.
- On the dashboard, choose Circuits from the menu on the left.
- Click Create new Circuit.
- Give the design a name that says what it is, such as line follower test, so that you can find it again later.
The empty grid that opens is your workbench. Everything else in this chapter happens on it.
9.2.3 Adding and Connecting Components
Components come from the panel on the right of the screen. Type what you want into the search box at the top of that panel, then drag the part onto the workspace.
A few controls make this easier. The mouse wheel zooms in and out. The rotate button at the top left turns a selected part. A part can be renamed by clicking on it, so four identical motors can become motor_left_1, motor_left_2, motor_right_1 and motor_right_2 instead of four things that look the same. Parts that belong together can be grouped, so that they move together and stay in order.
To wire two parts, click on a pin of the first part and then on a pin of the second. A wire appears between them. The colour of a wire can be changed, and it is worth doing: keeping every supply wire red and every ground wire black makes a mistake easy to spot later.
9.2.4 Programming the Microcontroller
A circuit with a microcontroller board does nothing until the board is told what to do. Click the Code button at the top right of the workspace to open the editor.
The editor offers two ways of writing the same program. In block coding you drag coloured blocks together, the way you may have done in a visual programming tool, and Tinkercad turns them into instructions. In text coding you type the instructions yourself, in the Arduino form of C/C++.
Blocks are quicker to start with and hard to get wrong. Text is what real projects use, and it is what this chapter uses from Section 9.4 onwards. The editor can show both side by side, which is a useful way to move from one to the other.
9.2.5 Running and Pausing the Simulation
Click Start Simulation, at the top right, and the circuit comes alive. The simulation runs in real time, so what you see on screen takes as long as it would take on the bench. An LED blinks, a motor spins, a sensor reading changes as you move the slider on it.
If something does not behave as you expected, pause the simulation and change the circuit or the code. Check the connections first, then the component values — the resistance of a resistor, the voltage of a battery — and then the program. Start the simulation again and see whether the behaviour has changed. Making one change at a time is the fastest way to find the fault.
The simulation is honest about wiring and about your program, but it cannot warn you about everything. A wheel that slips on a smooth floor, a battery that runs low, or sunlight falling on a sensor are all real problems that the screen knows nothing about.
9.3 Single Board Computers
The computer in your school lab is really a box of separate pieces. A motherboard, a processor pushed into it, memory sticks, a hard disk, a power supply unit, and a fan over all of it. It works well, but it is heavy, it needs a wall socket, and you could not bolt it onto a robot that has to move about.
A robot needs the same kind of thinking done by something much smaller. That is what a single board computer is for.
9.3.1 What a Single Board Computer Is
A single board computer (SBC) is a complete, working computer built on one circuit board. The processor, the memory, the storage and the ports are all fixed on that single board instead of being separate parts joined by cables.
Because everything is in one place, an SBC is small, light, and runs off a low voltage supply — often the same 5 V that comes down a USB cable. A board the size of a postcard can sit on a robot chassis and still do the work of a computer.
Being small has a price. An SBC has a slower processor and less memory than a desktop computer, so it is not the machine to edit a video on. For reading sensors, running a small program and controlling motors, it is more than enough.
9.3.2 What a Single Board Computer Contains
Open the box of a desktop computer and you can point to each part. On an SBC the same parts are there, but soldered flat onto one board, as shown in Fig. 9.3-1.
Diagram
Fig. 9.3-1 – a labelled top view of a single board computer showing the processor chip in the middle, a memory chip beside it, a micro SD card slot on one edge, USB and HDMI and Ethernet ports along another edge, a USB power input, and a row of general purpose input/output pins along the top edge
Processor (CPU). The chip that carries out the instructions of the program and does the calculations.
Memory (RAM). Working space that holds the program and its data while the board is switched on. It empties when the power goes off.
Storage. The place where files stay even when the power is off. On most SBCs this is a micro SD card pushed into a slot, or flash memory built onto the board.
Input/output (I/O) ports. The connections to the outside world — USB sockets for a keyboard or a camera, HDMI for a display, Ethernet or Wi-Fi for a network, and a row of pins for sensors and motor drivers.
Power supply. Usually a USB lead or a small dedicated adapter, at a low voltage. There is no separate power supply unit.
Most SBCs also run an operating system, the master program that starts the board, manages its files and lets other programs run. Raspberry Pi boards, for example, run operating systems based on Linux.
9.3.3 Some Common Single Board Computers
Raspberry Pi. The best known of them, widely used in schools, in robotics and in Internet of Things (IoT) projects, where everyday objects are connected to a network so they can send and receive data. It runs Linux-based operating systems and has USB, HDMI and network ports.
BeagleBone. A more advanced board, used more often in industrial equipment, robotics and embedded work than in classrooms.
Two other boards are usually mentioned in the same breath, although they are not full computers.
Arduino Uno. A microcontroller board rather than a single board computer. It has no operating system and no HDMI or USB ports for a keyboard, but it is excellent at reading sensors and driving motors, which is why the robot in this chapter is built around it.
ESP32 and ESP8266. Small microcontroller boards with Wi-Fi built in, popular in IoT projects where a device has to report data over a network.
The difference between the two families is worth being clear about, because choosing wrongly wastes both money and effort. Table 9.1 sets them side by side.
Many real robots carry both: the SBC handles the camera and the heavy work, and the microcontroller board sits below it, reading sensors and driving the motors.
9.3.4 Applications of Single Board Computers
Education. Cheap enough for a school to buy several, so students can learn programming and electronics with a board of their own.
IoT devices. Smart home systems, weather and pollution monitors, and other devices that gather readings and send them over Wi-Fi.
Robotics. Controlling a robot — reading its sensors, running the decision program, and sending commands to its motors.
Media centres. Turned into a small media server or player attached to a television.
Embedded systems. Built into a larger machine as its control unit, in industrial equipment and control panels.
9.4 Single Board Computer Coding
A board on the workspace is only hardware. Until it is given instructions it will sit there doing nothing, whatever it is wired to. Those instructions are the third layer of the robot from Fig. 9.1-1, and this section is about writing them.
The program written for an Arduino board is called a sketch. It is written in the Arduino form of C/C++, typed into the code editor you opened in Section 9.2.4. The same ideas apply to a Raspberry Pi, where the program is usually written in Python instead, but the thinking behind it does not change: read the inputs, decide, switch the outputs, repeat.
9.4.1 The Two Parts of a Sketch
Think of a school watchman at a gate. When he comes on duty he does a few things once — unlocks the gate, checks the register, takes his seat. After that he repeats one round of work over and over: look at the gate, open it if someone has come, sit down again.
A sketch is built the same way, out of two blocks.
setup() holds the instructions that run once, the moment the board is powered or reset. This is where you say which pins are inputs and which are outputs.
loop() holds the instructions that run again and again, without stopping, for as long as the board has power. When the last line of loop() finishes, the board goes straight back to the first line of it.
That endless repetition is exactly what a robot needs. A line follower cannot check the floor once and then stop checking.
Before a pin can be used it has to be given a job, using pinMode(). A pin set to OUTPUT can be switched on or off by the board. A pin set to INPUT is read by the board. Switching an output is done with digitalWrite(), which takes either HIGH (the pin goes to 5 V) or LOW (the pin goes to 0 V).
Here is the smallest useful sketch there is. It needs an Arduino Uno with an LED wired to digital pin 13 through a 220 Ω resistor, the other leg of the LED going to GND, as in Fig. 9.4-1.
Diagram
Fig. 9.4-1 – an Arduino Uno with a wire from digital pin 13 to one end of a 220 ohm resistor, the other end of the resistor to the longer leg of an LED, and the shorter leg of the LED wired back to the GND pin of the board
delay(1000) makes the board wait and do nothing for 1000 milliseconds, which is one second. Without it, the pin would be switched on and off thousands of times a second and the LED would simply look dimly lit.
9.4.2 Inputs, Outputs and Simple Decisions
A blinking LED ignores the world. A robot cannot. The next step is to read something in, and let the reading decide what happens.
digitalRead() looks at a pin set as INPUT and reports one of two values: HIGH if the pin is near 5 V, LOW if it is near 0 V. A push button, a switch, or the output pin of a line sensor all give the board exactly this kind of yes-or-no reading.
An if … else statement then chooses between two sets of instructions, depending on that reading.
The wiring is shown in Fig. 9.4-2. One leg of the push button goes to digital pin 2 and the other to GND. The LED is on digital pin 8, again through a 220 Ω resistor to GND.
Diagram
Fig. 9.4-2 – an Arduino Uno with a push button on a breadboard, one side of the button wired to digital pin 2 and the other side wired to GND; separately, digital pin 8 wired through a 220 ohm resistor to an LED whose other leg goes to GND
There is one catch. A pin with nothing connected to it does not sit at a steady value, so the reading would jump about on its own. Setting the pin as INPUT_PULLUP fixes this: the board quietly holds the pin at 5 V through a resistor inside the chip, so an unpressed button reads HIGH, and pressing the button connects the pin to GND, making it read LOW.
Notice that the same three steps appear here as in any robot program: read an input, compare it, drive an output. Section 9.6 uses this shape once more, with two sensors instead of one button and four motors instead of one LED.
9.5 Building Simple Robotic Systems
A robot is best built up in stages. One joint that moves. Then two joints working together. Then a base that can carry the whole thing across the floor. Each stage adds one new idea, and each stage can be tested before the next one is added.
This section takes that path as far as a small four-wheeled robot, which is the machine the rest of the chapter is built around.
9.5.1 From an RR Mechanism to a Moving Robot
You have already built an RR mechanism — two links joined by two revolute joints, one after the other. Turn the first joint and the whole arm swings. Turn the second and only the far link swings. Between them, the tip of the arm can be brought to any point inside the area the arm can reach.
That area is the limit of the machine. An RR mechanism is bolted to a table, so whatever lies outside its reach may as well not exist. To pick up something two metres away, the base itself has to move.
Replacing the fixed base with wheels changes the machine completely. The same two motors that once swung an arm now turn a pair of wheels, and the reach of the robot becomes the whole floor instead of one circle around a table.
9.5.2 The Four-Wheeled Mobile Robot
The robot in this chapter has four wheels, each with its own small DC motor. There is no steering wheel and no steering linkage. Nothing on it can be pointed sideways.
So how does it turn? By running one side faster than the other. The two motors on the left are wired together and treated as one unit, and so are the two on the right. Steering is then done purely with speed. This arrangement is called differential drive, because the robot turns on the difference between the speeds of its two sides. Fig. 9.5-1 shows the three cases.
Diagram
Fig. 9.5-1 – three top views of the same four-wheeled robot; in the first, both sides have arrows of equal length pointing forward and the robot’s path is a straight arrow; in the second, the left side has a long forward arrow and the right side has none, and the path curves to the right; in the third, the left side arrow points forward and the right side arrow points backward, and the robot spins on the spot
Both sides forward at the same speed, and the robot runs straight. Slow down or stop the right side, and the left side keeps pushing while the right side lags, so the robot swings to the right. Drive the two sides in opposite directions and the robot turns on the spot without going anywhere, which is very useful in a narrow corridor.
Turning this way costs nothing in extra parts, but it is not free of trouble. The wheels have to scrub sideways a little as the robot turns, so a turn is never quite as neat as the arithmetic suggests, and a smooth floor makes the wheels slip.
It also helps to know roughly how far one turn of a wheel carries the robot.
9.5.3 Driving Motors Through a Motor Driver
It is tempting to wire a motor straight to a digital pin, the way the LED was wired in Section 9.4. Do not. It will not work, and it can damage the board.
The reason is current. A digital pin of an Arduino Uno is meant to supply about 20 mA, and 40 mA is its absolute limit. Even a small DC motor draws several hundred milliamperes while running, and more still at the instant it starts. A pin asked to supply that much can be destroyed.
The part that solves this is a motor driver. The board’s pins carry only the instruction; the motor’s current comes from the battery through the driver, as shown in Fig. 9.5-2.
Diagram
Fig. 9.5-2 – a block diagram with four blocks; “Arduino Uno” joined by a thin arrow labelled “control signals, small current” to “Motor driver (L293D)”; a “9 V battery” joined by a thick arrow labelled “motor current” to the same driver block; and the driver joined by two thick arrows to “left motors” and “right motors”
The driver used here is the L293D. Inside it are two H-bridge circuits. An H-bridge is an arrangement of four switches around a motor that lets the current be sent through the motor either way round. That is what makes reversing possible: the same motor runs forwards or backwards depending on which pair of switches is closed.
Because the four wheels are wired as two pairs, two channels are enough for the whole robot: one channel for both left motors, one for both right motors.
9.6 A Line Follower Robot in Tinkercad
Everything so far comes together here. A line follower robot is a mobile robot that keeps itself on a line marked on the floor. Factories use exactly this idea to move trolleys of goods along fixed paths between machines, with a painted or taped line doing the job of a rail.
The robot you will build has two sensors that look down at the floor, four wheels driven as two pairs, an L293D between the board and the motors, and a program that decides, many times a second, whether to go straight, swing left, swing right or stop.
Build it on the Tinkercad workspace one step at a time, and test after each step.
9.6.1 Components Required
Search the components panel for each of these and drag it onto the workspace.
- Arduino Uno — the brain of the robot, running the program
- Four DC motors — one for each wheel, wired as a left pair and a right pair
- L293D motor driver — passes the battery’s current to the motors on the board’s instructions
- Two infrared (IR) sensors — to look at the floor and report whether the line is under them
- 9 V battery — the power source for the motors
- Breadboard — to carry the driver and to share the supply and ground connections
- Wires — to join everything
9.6.2 Adding and Naming the Components
Place all of them on the workspace first, before wiring anything, and spread them out. Four motors near the four corners, the breadboard in the middle with the L293D pushed across its central channel, the Arduino below it, the battery to one side, and the two sensors at the front. See Fig. 9.6-1.
Diagram
Fig. 9.6-1 – screenshot of the Tinkercad Circuits workspace with four DC motors, an Arduino Uno, an L293D on a breadboard, a 9 V battery and two IR sensors placed but not yet wired
Now rename each part, because four identical motors on a screen are impossible to tell apart later. Call them motor_left_1, motor_left_2, motor_right_1 and motor_right_2. Call the sensors IR_left and IR_right.
Two small habits save a great deal of time from here on. Keep every supply wire red and every ground wire black. And once a group of parts is wired and working, group them, so that they move together and their wiring is not disturbed.
9.6.3 Connecting the IR Sensors
Before wiring the sensors, it is worth knowing what they actually do.
Each sensor has three pins: Vcc, GND and Out. The first two power it and the third carries the reading, as in Fig. 9.6-2.
Diagram
Fig. 9.6-2 – two IR sensor modules labelled IR_left and IR_right; the Vcc pin of each wired in red to the 5V pin of the Arduino Uno, the GND pin of each wired in black to a GND pin of the board, the Out pin of IR_left wired to digital pin 2, and the Out pin of IR_right wired to digital pin 3
- Connect the Vcc pin of each sensor to the 5V pin of the Arduino.
- Connect the GND pin of each sensor to a GND pin of the Arduino.
- Connect the Out pin of IR_left to digital pin 2, and the Out pin of IR_right to digital pin 3.
Sensors draw a very small current, so these two may safely be powered from the board itself. The motors may not.
9.6.4 Connecting the Motors to the Motor Driver
The L293D has two channels and the robot has two sides, so one channel takes the left pair and the other takes the right pair. Each channel has two output pins, and a motor sits across them.
- Connect motor_left_1 and motor_left_2 across pin 3 and pin 6 of the L293D. Both left motors go on the same two pins, so they always turn together.
- Connect motor_right_1 and motor_right_2 across pin 11 and pin 14 of the L293D.
Take care with the order of the two terminals within a pair. If one left motor is wired the opposite way round to the other, the two will work against each other and the robot will crawl or stall instead of driving. Fig. 9.6-3 shows the pairs wired correctly.
Diagram
Fig. 9.6-3 – an L293D on a breadboard with motor_left_1 and motor_left_2 both wired across pins 3 and 6, and motor_right_1 and motor_right_2 both wired across pins 11 and 14; the two motors of each pair are wired the same way round as each other
9.6.5 Connecting the Driver, the Board and the Battery
The driver now needs three things: instructions from the Arduino, permission to run, and current from the battery.
Each channel is told what to do through two input pins. Pin 2 and pin 7 control the left channel, and pin 10 and pin 15 control the right channel. Each channel also has an enable pin — pin 1 for the left channel and pin 9 for the right — and a channel passes no current at all unless its enable pin is held at 5 V.
Two supply pins remain. Pin 16 is the driver’s own logic supply and takes 5 V from the Arduino. Pin 8 is the motor supply and takes the 9 V from the battery. Table 9.2 lists every connection in one place.
Use the two long rails of the breadboard for the shared connections. Run the 5V pin of the Arduino to the red rail, and run the GND pin of the Arduino, the negative terminal of the battery and the ground pins of the driver all to the black rail. The completed circuit is shown in Fig. 9.6-4.
Diagram
Fig. 9.6-4 – screenshot of the completed Tinkercad circuit, showing the four motors wired to the L293D on the breadboard, the Arduino wired to the driver inputs and enable pins, the two IR sensors wired to digital pins 2 and 3, and the 9 V battery wired to the breadboard rails
9.6.6 The Control Logic
The wiring is done. Now for the thinking.
Each sensor gives one of two readings. LOW means the black line is under it. HIGH means it is over the white floor. Two sensors with two possible readings each gives four cases, and the robot needs an answer for all four. Table 9.3 sets them out.
The two middle rows are worth pausing over. If the left sensor has slipped onto white floor while the right one is still on black, the robot has wandered to the left of the line. To get back, it must swing to the right — towards the side that can still see black. The correction is always towards the sensor that is still on the line.
Stopping when both sensors read HIGH is a deliberate choice, not a failure. A robot that cannot see the line has no way of knowing which way to go, and one that keeps driving blindly ends up further away and harder to recover.
9.6.7 The Program
Click the Code button and switch the editor to text. The sketch below follows Table 9.3 exactly. It is written for the wiring given in Sections 9.6.3 to 9.6.5 — sensors on digital pins 2 and 3, driver inputs on digital pins 5, 6, 9 and 10.
Each of the four small functions does one job and is given a name that says what that job is. This is worth copying as a habit: loop() stays short enough to read at a glance, and a wiring mistake can be traced to one function instead of being hunted through a long block of digitalWrite() lines.
9.6.8 Simulating and Correcting the Circuit
Click Start Simulation. The IR sensors on the workspace can be set to the reading you want, so you can walk the robot through all four rows of Table 9.3 and watch what the motors do each time.
Work down a checklist when something is wrong.
- Do the motors turn at all? If not, check the enable pins and the battery connection to pin 8. A channel whose enable pin is unconnected stays silent however correct the program is.
- Do all four motors turn the same way when both sensors read LOW? If one runs backwards, its two terminals are swapped.
- Does the robot swing the wrong way? The two sensor wires have probably been swapped between digital pins 2 and 3.
- Does nothing respond to the sensors? Check that the sensor Out wires reach pins 2 and 3, and that the ground rail is shared.
Change one thing, run the simulation again, and see what happened. Changing three things at once tells you nothing about which one mattered.
One honest limitation to carry into the real world: this robot has only two levels of speed, full and stopped, so it corrects in jerks rather than smoothly. A real line follower usually changes motor speed gradually instead of switching a side fully off, which gives a much steadier run.
9.7 From Simulation to a Physical Robot
The circuit on the screen works. Every row of Table 9.3 does what it should. That is the design proved — but the robot still has no body, and a pile of motors and wires on a bench cannot follow anything.
Tinkercad’s other workspace, 3D Design, is where the body is made. It is the same tool you used to draw and move the parts of a mechanism, used now for one flat plate: the chassis that everything is bolted to.
The chassis is not just a piece of plastic to fix things onto. Its measurements decide how the robot behaves. Where you place the holes for the two sensors decides how early the robot notices a drift. Where the motors sit decides how wide the robot is and how sharply it can swing. Fig. 9.7-1 shows what a plate for this robot has to carry.
Diagram
Fig. 9.7-1 – top view of a flat rectangular chassis plate with labelled hole groups: four pairs of motor mounting holes at the corners, two small sensor mounting slots close together at the front edge, a set of four holes matching the Arduino Uno board in the middle, a cut-out for wires to pass through to the underside, and a strap slot for the battery at the rear
Work through it in a fixed order. Draw the outline of the plate first. Then add mounting holes for the four motors, for the two IR sensors at the front edge, and for the Arduino board. Leave a slot or a cut-out for the wires to pass from the top of the plate to the motors below it, so that nothing is trapped under a wheel. Finally, export the finished design as an .stl file, which is the file format a 3D printer reads, and print the plate if a printer is available. A plate cut from thick cardboard or acrylic works just as well for a first robot.
Once the plate exists, the electronics come off the screen and onto it. The wiring is copied from the simulated circuit, connection by connection, and the battery is connected last. The sketch you typed in Section 9.6.7 is ordinary Arduino code, so the same lines can be uploaded to the real board through its USB cable and will run unchanged.
What will not be unchanged is the behaviour. Table 9.4 sets out where the two differ.
The commonest surprise is the sensors. A module that reported the line cleanly on screen may report nothing at all on a real floor, because it sits too high above it, or because the floor is shiny, or because sunlight from a window is falling on the line. Set the sensors a few millimetres above the floor, use matt black tape on a light floor for the line, and adjust the small screw on each module until it switches reliably as you slide it from the floor to the tape.
None of this means the simulation was wasted. It settled the design, the wiring and the program, so that the only problems left on the floor are the physical ones. That is the sensible order of work for any robot: prove it on the screen, then build it, then tune it.
9.8 Summary
- Integration means joining a robot’s mechanical parts, its electrical parts and its program so that they work as one system. A mistake in any one of the three layers stops the whole robot.
- A simulation is a computer model of a real system that can be run and watched in place of the real thing. It lets a design be tested before any component is bought or wired.
- Tinkercad Circuits is a free online workspace for building, programming and running electronic circuits. Its main features are a drag-and-drop workspace, a component library, virtual breadboards, a built-in code editor and a simulation button.
- A new circuit is made by logging in, choosing Circuits on the dashboard and clicking Create new Circuit. Components are dragged from the panel, joined by clicking on their pins, renamed for clarity, and grouped once they are correct.
- A microcontroller board on the workspace is programmed from the Code button, using either block coding or text coding in the Arduino form of C/C++. Start Simulation runs the circuit in real time, and it can be paused to correct the circuit or the code.
- A single board computer (SBC) is a complete computer built on one circuit board, carrying its processor, memory, storage, input/output ports and power input together.
- Raspberry Pi and BeagleBone are single board computers and usually run an operating system. Arduino Uno, ESP32 and ESP8266 are microcontroller boards, which run one program and are better suited to reading sensors and switching outputs.
- Single board computers are used in education, in Internet of Things devices, in robotics, as media centres and inside embedded systems.
- An Arduino sketch has two parts.
setup()runs once and gives each pin its job withpinMode().loop()repeats endlessly, reading inputs withdigitalRead()and switching outputs withdigitalWrite(). - A wheeled mobile robot carries its whole body about on driven wheels, which lets it work far beyond the reach of a fixed arm.
- A four-wheeled robot with fixed wheels steers by differential drive: driving its left and right sides differently. Its wheels must scrub sideways as it turns, so a turn is never exactly repeatable.
- An Arduino pin can supply only about 20 mA, far less than a DC motor needs, so a motor driver such as the L293D is placed between the board and the motors. The board sends signals; the battery supplies the motor current through the driver.
- The board, the driver and the battery must share a common ground, and the driver’s logic supply and enable pins take 5 V while its motor supply takes the battery voltage.
- A line follower robot uses two infrared sensors that report whether the floor below them is dark or light. Both dark means go forward, one light means swing towards the side that still sees the line, and both light means the line has been lost and the robot should stop.
- Once the simulated circuit behaves correctly, the chassis is designed in the 3D Design workspace with mounting holes for the motors, sensors and board, and exported as an
.stlfile for printing. - The real robot still needs tuning, because sensor readings depend on the floor and the lighting, wheels slip, and a weakening battery slows the motors. The simulation removes the design faults, not the physical ones.
9.9 Key Terms
Breadboard — A board full of holes whose rows are joined underneath, used to connect components by pushing them in instead of soldering.
Chassis — The flat base of a mobile robot, to which the motors, sensors, board and battery are fixed.
Differential drive — A way of steering a robot with fixed wheels by driving its left and right sides at different speeds.
Infrared (IR) sensor — A module that sends out infrared light and reports how much of it comes back, used here to tell dark floor from light floor.
Integration — Joining a robot’s mechanical parts, electrical parts and program so that they work together as one system.
Internet of Things (IoT) — Everyday objects connected to a network so that they can send and receive data.
Line follower robot — A mobile robot that keeps itself over a marked path by watching the floor and correcting its own direction.
Motor driver — A chip placed between the controller and the motors, which uses the controller’s weak signals to switch a much larger current from a separate battery.
Operating system — The master program that starts a computer, manages its files and lets other programs run on it.
Simulation — A computer model of a real system that can be run and observed in place of the real thing.
Single board computer (SBC) — A complete computer whose processor, memory, storage and input/output ports are all built onto one circuit board.
Sketch — The program written for an Arduino board, made of a
setup()part that runs once and aloop()part that repeats.Tinkercad Circuits — A free online workspace in which electronic circuits are built, programmed and run without any real components.
Wheeled mobile robot — A robot whose whole body moves from place to place on wheels driven by its own motors.
9.10 Objective Questions
Which of these is a single board computer?
- Arduino Uno
- Raspberry Pi
- L293D
- Breadboard
In Tinkercad Circuits, the component that lets parts be connected without soldering is the __________, and the button that makes the circuit run is __________.
State whether true or false: a digital pin of an Arduino Uno can supply enough current to run a small DC motor directly.
The enable pins of an L293D should be connected to:
- the positive terminal of the 9 V battery
- the 5V pin of the Arduino
- the ground rail of the breadboard
- digital pin 13 of the Arduino
Match each item in Column A with its description in Column B.
| Column A | Column B |
|---|---|
a. setup() |
i. Holds files on a single board computer even when the power is off |
| b. Micro SD card | ii. Switches motor current from the battery |
| c. L293D | iii. Runs once when the board is powered or reset |
| d. Chassis | iv. The flat base that carries the motors, board and battery |
Both infrared sensors of a line follower robot report LOW. In one line, state what the robot does next and why.
Which part of an Arduino sketch repeats endlessly for as long as the board has power?
pinMode()setup()loop()digitalWrite()
9.11 Concept Questions
Define a single board computer, and name any two examples of one.
Give two differences between a single board computer and a microcontroller board.
Why must the Arduino, the motor driver and the battery all share a common ground? What goes wrong if they do not?
Explain what differential drive means, describe how a four-wheeled robot with fixed wheels turns to the left, and state one limitation of steering this way.
A small mobile robot has wheels of diameter 70 mm, and its motors turn the wheels at 120 revolutions per minute. Work out the speed of the robot in metres per second, showing your steps.
In the line follower program, a student writes
if (leftReading = LOW)instead ofif (leftReading == LOW). What will the robot do, and why?A circuit has been tested fully in Tinkercad and behaves correctly. Give two reasons why the real robot built from it may still not follow the line properly.
9.12 Case-Based Questions
- A school library uses a small four-wheeled robot to carry returned books from the counter to the shelves. It follows a black line taped along the floor, using two infrared sensors mounted close together at the front. Each sensor reports LOW over the black tape and HIGH over the light floor. The readings taken at three moments during one trip are given below.
| Moment | IR_left | IR_right |
|---|---|---|
| 1 | LOW | LOW |
| 2 | HIGH | LOW |
| 3 | HIGH | HIGH |
- State what the robot should do at each of the three moments.
- Explain why stopping is the sensible action at moment 3, rather than guessing a direction.
- The robot works on the corridor floor but loses the line on the polished floor near the entrance. Suggest one change that could improve its behaviour there, and give a reason for it.
- A school wants a small robot that drives slowly along the corridor during break, carrying a camera, so that the wet patches on the floor can be spotted and cleaned. The team has one Raspberry Pi, one Arduino Uno and one L293D motor driver.
- Which board would you use for handling the camera, and which for driving the motors? Give one reason for each choice.
- Explain why the motors cannot be wired straight to the pins of either board.
- The camera will record students as it moves. State two things the team should do so that this is handled responsibly.