# 8.3. Implementation¶

This section of the book presents the core code which implements the CellBot’s ability to connect a smart device to the mobile base and to access sensors on a smart device. It consists of three components:

• JavaScript code which runs in a web browser and send commands to the ESP32 microcontroller on the mobile base. This is available in Runestone Components.

• A Skulpt wrapper around this JavaScript to make it available in Python.

• Arduino/C++ code which runs on the ESP32 mobile base which receives commands from the web browser, executes them, then returns the results back to the browser.

It also contains files used to create this book.

## 8.3.1. To do¶

• Write up basic hardware connection instructions, software install to do ESP32 development if desired.

• Add a 10 uF cap between EN and GND to avoid flaky reprogramming.

• Provide some kind of version/CPU info, so we could talk to an older version of the code or to other types of chip.

• Fix the reset function to actually reset all pins.

• Include a disconnect function so that everything will be turned off after “running” a Python program.

• Find a cheaper ESP32 – some possibilities at https://makeradvisor.com/esp32-development-boards-review-comparison/.

• Put the ESP32 to sleep when not paired or no BLE running.

## 8.3.2. Hardware¶

This gives one realization of a CellBot; however, it can easily support a wide variety of motors and be equipped with additional sensors and actuators.

### 8.3.2.1. Bill of Materials¶

Qty

Vendor

SKU

Description

Price (USD)

1

Sparkfun

PRT-12083

Battery Holder 4xAA with Cover and Switch

$1.95 1 Sparkfun ROB-13258 Hobby Gearmotor - 65 RPM (Right Angle, Pair)$4.95

1

Sparkfun

ROB-13259

Wheel - 65mm (Rubber Tire, Pair)

$2.95 1 Sparkfun ROB-14450 SparkFun Motor Driver - Dual TB6612FNG (with Headers)$5.45

1

Sparkfun

PRT-00124

Jumper Wire Kit - 140pcs

$5.95 1 Amazon/HiLetgo B00LSG5BJK 400 point solderless breadboard, pack of 3$5.99

1

Amazon/HiLetgo

B0718T232Z

HiLetgo ESP-WROOM-32 Development Board 2.4GHz

$10.99 Total Includes 3 breadboards; need only 1. No quantity discounts.$38.99

### 8.3.2.2. Design notes¶

The design presented here is driven by cost and simplicity. Other technical considerations:

#### 8.3.2.2.1. Battery voltage¶

At the heart of the design is an ESP32-WROOM-32D. This development kit contains an AMS1117-3.3 linear regulator, so its minimum input voltage is 3.3 V + Vdrop, the dropout voltage, where Vdrop = 1.5 V at 1 A. Therefore, the minimum allowable battery voltage is 4.7 V. The recommended maximum input voltage to the AMS1117 is 18 V, which defines the maximum battery voltage for the ESP32.

The DC motors must operate within the provided battery voltage as well. The motors selected above operate between 3 V - 6 V.

Finally, the TB6612FNG motor drivers allow a motor voltage (VM) from 2.5 V to 13.5 V.

Combining all three ranges (4.7 V - 18 V, 3 V - 6 V, and 2.5 V - 13.5 V) gives an allowable range of 4.7 V - 6 V for the batteries.

#### 8.3.2.2.2. Other notes¶

While many motor drivers (also termed an H-bridge) exist, the TB6612FNG is one of the few that operates at a logic supply voltage (VCC) of 3.3 V. Since the ESP32 development kit already provides 3.3 V, this voltage drives the selection of a motor driver. For example, the LM298N provides higher drive current, a wider range of motor voltages, and a sense output to allow determination of the drive current (a very nice feature). However, its minimum VCC is 4.5 V.

With a wheel diameter of 65 mm and a no-load speed of 65 RPM for the motors, this robot’s max speed is π·65 mm·65 RPM·1 min/60 sec = 0.2 m/s, compared to a typical walking speed of 1.4 m/s.