Electronics
Components used
ESP8266(1 as server and 1 for each bot)
L298N Motor Driver(1 for each bot)
Voltage Regulator(1 for each bot)
Switch(1 for each bot)
Servo Motor(1 for each bot)
Speed Motor Sensor with encoder disk(2 for each bot)
Bo motor(2 for each bot)
Wheels(2 for each bot)
Communication System
ESP-NOW communication protocol to send data from one ESP32 to multiple ESP32 or ESP8266 boards (one-to-many configuration). The boards was programmed using Arduino IDE.
One ESP32 to multiple ESP32 or ESP8266 boards using ESP-NOW (one-to-many configuration).

- One ESP32 acts as a sender;
- Multiple ESP32 or ESP8266 boards act as receivers. We tested this setup with two ESP32 boards and one ESP8266 board simultaneously. You should be able to add more boards to your setup;
- The ESP32 sender receives an acknowledge message if the messages are successfully delivered. You know which boards received the message and which boards didn’t;
- You need to upload a slightly different receiver code depending if you’re using an ESP32 or ESP8266
Optical Interrupter Sensor
If you are not familiar with opto interrupters (also referred to as an “opto isolator” or “optical source-sensor”) don’t worry, they are actually pretty simple devices and they are used in a variety of applications. In fact you’re probably using one right now without even being aware of it, as a mouse with a scroll wheel and most non-laser printers make use of them.
An opto interrupter consists of a source of light, usually an infrared LED, and a phototransistor sensor. The light source is mounted facing the sensor with a gap between them. In the case of the H206 that gap is about 6 millimeters.
In operation the LED is illuminated and it shines onto the phototransistor, which detects its light and allows current to pass from the collector to emitter. Essentially a phototransistor is like a regular bipolar transistor except instead of reacting to current applied to the base it reacts to photons of light.
If a solid non-transparent object is placed in the slot between the LED and phototransistor it will interrupt the light beam, causing the phototransistor to stop passing current.
In our application the opto interrupter will be positioned with the rotating encoder wheel in the gap between the LED and transistor. As the wheel spins the slots in the wheel will allow pulses of light to reach the phototransistor, causing it to switch on and off in time with the wheel rotation.
Each pulse will represent a slot in the encoder wheel, so if your encoder wheel has 20 equally-spaced slots (a pretty common value) then each pulse indicates that the wheel has turned 18 degrees (360 degrees divided by 20).
Add an LM393 Comparator
You could just purchase a couple of H206 opto interrupters and wire them up to your microcontroller, however you’d probably wouldn’t be satisfied with the results. That’s because in the real world the output pulses directly from the phototransistor are poorly formed and as a result your code would end up giving a lot of errors.
What is needed is a way to clean up the output a bit and generate some nice clean 5-volt pulses suitable for using with an Arduino or other microcontroller. And the perfect component to do that is a “comparator”.
A comparator is a device that has two inputs and one output. One of the inputs is a “reference voltage” input, the other input is where you would connect the output of the phototransistor. The output of the comparator is digital, so it can go either high (5-volts) or low (Ground).
The key is the reference voltage. If the input (in our case from the phototransistor) is below the reference voltage then the digital output of the comparator remains low. If the input equals or exceeds the reference voltage then the output goes high.
To put it another way, a comparator is a good way to clean up a “weak” or “dirty” digital signal, as well as a way of determining if an input voltage has reached a preset threshold.
The LM393 is a dual comparator, meaning two independent comparators in the same tiny package. It’s perfect for the job of cleaning up the output from the opto interrupter.
Because the combination of the H206 and LM393 is so common there are a number of small inexpensive sensor modules constructed with these two components (plus a handful of resistors and capacitors). These sensors are often called “LM393 Speed Sensors” although the name is a bit of a misnomer as the LM393 is just one of the components. However as it’s a common name I’ve chosen to stick with it.

Calculating Wheel Speed
Calculating the speed that the wheel spins is pretty simple really. If we use the example of an encoder wheel with 20 slots then for every 20 pulses from the LM323 Speed Sensor our motor has spun the wheel one revolution. Knowing that we can count how many pulses we get in a second and use that to determine the actual wheel speed.
Notice that I’m saying “wheel speed” and not “motor speed”, they are different as the motor has internal gearing that slows it down.
As a simple example if I measure exactly 20 pulses every second then our wheel is spinning a one revolution per second. Multiplying that by 60 gives us the speed in RPM, which in this case is 60 RPM.
Once we determine the wheel speed we can use the wonderful power of mathematics to calculate a couple of other useful parameters:
- We can get the actual speed (in Kilometers or Miles per hour) of our robot car.
- We can determine how far our robot has travelled.
- We also know that the wheel is actually spinning, as opposed to being stuck and not moving.
To get those first two parameters we need to know one other thing – the circumference of the wheel itself. There are two ways to get that value:
- Measure it! Use a flexible measuring tape or a piece of string wrapped around the outside of the wheel and see how long it is.
- Calculate it. Multiply the diameter of the wheel by pi (3.14) to get the circumference.
You can probably see why this value is so important, the circumference of the wheel is equal to the distance that the wheel will travel in one rotation (assuming you have perfect traction with the surface you’re travelling on).
I measured one of the wheels in the kit I’m working with and it had a diameter of 66.1 mm. So using the formula I arrive at the following:
66.1 x π = 207.6
So my wheel has a circumference of 207.6 mm. A tape measure wrapped around the wheel confirms that this is the correct value.
You could also do the math using imperial measurements if you really insist, but the metric measurements are much easier to work with.
Comments
Post a Comment