Introduction: HackerBoxes 0013: Autosport
AUTOSPORT: This month, HackerBox Hackers are exploring automotive electronics. This Instructable contains information for working with HackerBoxes #0013. If you would like to receive a box like this right to your mailbox each month, now is the time to subscribe at HackerBoxes.com and join the revolution!
Topics and Learning Objectives for this HackerBox:
- Adapting the NodeMCU for Arduino
- Assembling a 2WD Car Kit
- Wiring a NodeMCU to control a 2WD Car Kit
- Controlling a NodeMCU over WiFi using Blynk
- Using Sensors for Autonomous Navigation
- Working with Automotive On-board Diagnostics (OBD)
HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. Hack the Planet!
Step 1: HackerBoxes 0013: Box Contents
- HackerBoxes #0013 Collectable Reference Card
- 2WD Car Chassis Kit
- NodeMCU WiFi Processor Module
- Motor Shield for NodeMCU
- Jumper Block for Motor Shield
- Battery Box (4 x AA)
- HC-SR04 Ultrasonic Ranging Sensor
- TCRT5000 IR Reflectivity Sensors
- DuPont female-female jumpers 10cm
- Two Red Laser Modules
- Mini-ELM327 on-board diagnostics (OBD)
- Exclusive HackerBoxes Racing Decal
Some other things that will be helpful:
- Four AA Batteries
- Double-Sided Foam Tape or Velcro Strips
- microUSB Cable
- Smart Phone or Tablet
- Computer with Arduino IDE
Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Hardcore hobbyist electronics isn't always easy, but when you persist and enjoy the adventure, a great deal of satisfaction may be derived from persevering and getting your projects working. Just take each step slowly, mind the details, and don't hesitate to ask for help.
Step 2: Automotive Electronics and Self Driving Cars
Automotive electronics are any electronic systems used in road vehicles. These include carputers, telematics, in-car entertainment systems, and so forth. Automotive electronics originated from the need to control engines. The first were used to control engine functions and were referred to as engine control units (ECU). As electronic controls began to be used for more automotive applications, the acronym ECU took on the more general meaning of "electronic control unit", and then specific ECUs were developed. Now, ECUs are modular. Two types include engine control modules (ECM) or transmission control modules (TCM). A modern car may have up to 100 ECUs.
Radio-controlled cars (R/C cars) are cars or trucks that can be controlled from a distance using a specialized transmitter or remote. The term "R/C" has been used to mean both "remote controlled" and "radio controlled", but common use of "R/C" today usually refers to vehicles controlled by a radio-frequency link.
An autonomous car (driverless car, self-driving car, robotic car) is a vehicle that is capable of sensing its environment and navigating without human input. Autonomous cars can detect surroundings using a variety of techniques such as radar, lidar, GPS, odometry, and computer vision. Advanced control systems interpret sensory information to identify appropriate navigation paths, as well as obstacles and relevant signage. Autonomous cars have control systems that are capable of analyzing sensory data to distinguish between different cars on the road, which is very useful in planning a path to the desired destination.
Step 3: Arduino for NodeMCU
NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems and hardware based on the ESP-12 module.
The Arduino IDE can now be easily extended to support programing NodeMCU modules as though they were any other Arduino development platform.
To start, make sure you have the Arduino IDE installed (www.arduino.cc) as well as drivers for the appropriate Serial-USB chip on the NodeMCU module you are using. Currently most NodeMCU modules include the CH340 Serial-USB chip. The manufacturer of the CH340 chips (WCH.cn) has drivers available for all popular operating systems. Check out the Google translation page for their site.
Run the Ardino IDE, go into preferences,and locate the field for entering "Additional Board Manager URLs"
Paste in this URL:
To install the Board Manager for ESP8266.
After install, close the IDE and then start it back up.
Now connect the NodeMCU module to your computer using a microUSB cable (as used by most mobile phones and tablets).
Select the board type within the Arduino IDE as NodeMCU 1.0
We always like to load and test the blink demo on a new Arduino board just to get some confidence that everything is working correctly. The NodeMCU is no exception, but you have to change the LED pin from pin13 to pin16 before compiling and uploading. Make sure this quick test works correctly before moving on to anything more complicated with the Arduino NodeMCU.
Here is an instructable that goes over the setup process for Arduino NodeMCU with some different application examples. It is a bit astray from the objective here, but it may be helpful to look at for another point of view if you get stuck.
Step 4: 2WD Car Chassis Kit
2WD Car Chassis Kit contents:
- Aluminum Chassis (colors vary)
- Two FM90 DC Motors
- Two Wheels with Rubber Tires
- Freewheel Caster
- Assembly Hardware
- Mounting Hardware
The FM90 DC Motors look like micro servos because they are built in same plastic housing as common micro servos, such as the FS90, FS90R, or SG92R. However, the FM90 is not a servo. The FM90 is a DC motor with a plastic gear-train.
The FM90 motor's speed is controlled by pulse width modulating (PWM) the power leads. Direction is controlled by swapping the power polarity as with any brushed DC motor. The FM90 can run on 4-6 Volts DC. While small, it does draw enough current that it should not be driven directly from a microcontroller pin. A motor driver or H-bridge should be used.
FM90 DC Motor Specs:
- Dimensions: 32.3mm x 12.3mm x 29.9mm / 1.3" x 0.49" x 1.2"
- Spline Count: 21
- Weight: 8.4g
- No load speed: 110RPM (4.8v) / 130RPM (6v)
- Running Current (at no load): 100mA (4.8v) / 120mA (6v)
- Peak Stall Torque (4.8v): 1.3 kg/cm / 18.09 oz/in
- Peak Stall Torque (6v): 1.5 kg/cm / 20.86 oz/in
- Stall Current: 550mA (4.8v) / 650mA (6v)
Step 5: Car Chassis: Mechanical Assembly
The Car Chassis can be easily assembled according to this diagram.
Note that there are two small bags of hardware. One includes Mounting Hardware with six brass 5mm-M3 standoffs along with matching screws and nuts. This mounting hardware may be useful in later steps of mounting controllers, sensors, and other items to the chassis.
For this step, we will use the Assembly Hardware which includes:
- Four thin M2x8 bolts and small matching nuts for affixing the motors
- Four thicker M3x10 bolts and larger matching nuts for affixing the caster wheel
- Two PB2.0x8 screws with coarse threads for affixing the wheels to the motors
Note that the FM90 motors are oriented such that the wire leads extend from the rear of the assembled chassis.
Step 6: Car Chassis: Add Power Pack and Controller
The ESP-12E motor shield board supports directly plugging the NodeMCU module. The motor shield includes an L293DD push-pull motor driver chip (datasheet). The motor wire leads should be wired to the A+/A- and B+/B- screw terminals on the motor shield (after removing the connectors). The battery leads should be wired to the battery input screw terminals.
If one of the wheels turns in the wrong direction, the wires to the corresponding motor can be swapped at the screw terminals, or the direction bit can be inverted in the code (next step).
There is a plastic power button on the motor shield to activate the battery input supply. The jumper block can be used to route power to the NodeMCU from the motor shield. Without the jumper block installed, the NodeMCU can power itself from the USB cable. With the jumper block installed (as shown), the battery power supplies the motors and is also driven to the NodeMCU module.
The motor shield and the battery pack can mounted to the chassis by lining up the screw holes with available openings in the aluminum chassis. However, we find it easier to just affix them to the chassis using double-sided foam tape or adhesive velcro strips.
Step 7: Car Chassis: Programming and Wi-Fi Control
Blynk is a Platform with iOS and Android apps to control Arduino, Raspberry Pi, and other hardware over the Internet. It's a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets. It's really simple to set everything up and you'll start tinkering right away. Blynk will get you online and ready for the Internet Of Your Things.
The HBcar.ino Arduino script included here shows how to interface four buttons (forward, reverse, right, and left) on a Blynk project to control the motors on the 2WD car chassis.
Prior to compiling, three strings need to be changed in the program:
- Wi-Fi SSID (for your Wi-Fi access point)
- Wi-Fi Password (for your Wi-Fi access point)
- Blynk Authorization Token (from your Blynk project)
Note from the example code that L293DD chip on the motor shield is wired up as follows:
- GPIO pin 5 for motor A speed
- GPIO pin 0 for motor A direction
- GPIO pin 4 for motor B speed
- GPIO pin 2 for motor B direction
Step 8: Sensors for Autonomous Navigation: Ultrasonic Range Finder
The HC-SR04 ultrasonic range finder (datasheet) can provide measurements from about 2cm to 400cm with an accuracy up to 3mm. The HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.
After attaching four female-female jumpers to the pins of the HC-SR04, wrapping some tape around the connectors can help to both insulate the connections from shorting to the aluminum chassis and also provide a pliable mass to wedge into the slot at the front of the chassis as shown.
In this example, the four pins on the HC-SR04 can be wired to the motor shield:
- VCC (on HC-SR04) to VIN (on motor shield)
- Trigger (on HC-SR04) to D6 (on motor shield)
- Echo (on HC-SR04) to D7 (on motor shield)
- GND (on HC-SR04) to GND (on motor shield)
VIN will supply about 6VDC to the HC-SR04, which only needs 5V. However, that seems to work fine. The other available power rail (3.3V) is sometimes adequate to power the HC-SR04 module (certainly give it a try), but sometimes it is not enough voltage.
Once this is wired up, try out the example code NodeMCUping.ino to test operation of the HC-SR04. The distance from the sensor to any object is printed on the serial monitor (9600 board) in centimeters. Get our ruler and test the accuracy. Impressive isn't it?
Now that you have this hint, try something like this for a collision-avoiding, autonomous vehicle:
- forward until distance < 10cm
- reverse a small distance (optional)
- turn a random angle (time)
- loop to step 1
For some general background information, here is a tutorial video full of details for using the HC-SR04 module.
Step 9: Sensors for Autonomous Navigation: Infrared (IR) Reflectivity
The IR Reflective Sensor module utilizes a TCRT5000 (datasheet) to detect color and distance. The module emits IR light and then detects if it receives a reflection. Thanks to its ability to sense if a surface is white or black, this sensor is often used in line following robots and auto data logging on utility meters.
The measuring distance range is from 1mm to 8mm, and the central point is about 2.5mm. There is also an on-board potentiometer to adjust the sensitivity. The IR diode will emit IR light continuously when the module is connected to power. When the emitted infrared light is not been reflected, the triode will be in the off state causing the digital (D0) output to indicate a logic LOW.
Step 10: Laser Beams
These common 5mW 5V laser modules can be used to add red laser beams to pretty much anything that has 5V power available.
Note that these modules can be easily damaged, so HackerBox #0013 includes a couple to provide a back-up. Take care with your laser modules!
Step 11: Automotive On-board Diagnostics (OBD)
On-board diagnostics (OBD) is an automotive term referring to a vehicle's self-diagnostic and reporting capability. OBD systems give the vehicle owner or repair technician access to the status of the various vehicle subsystems. The amount of diagnostic information available via OBD has varied widely since its introduction in the early 1980s versions of on-board vehicle computers. Early versions of OBD would simply illuminate a malfunction indicator light if a problem was detected but would not provide any information as to the nature of the problem. Modern OBD implementations use a standardized digital communications port to provide real-time data in addition to a standardized series of diagnostic trouble codes, or DTCs, which allow one to rapidly identify and remedy malfunctions within the vehicle.
OBD-II is an improvement in both capability and standardization. The OBD-II standard specifies the type of diagnostic connector and its pinout, the electrical signalling protocols available, and the messaging format. It also provides a candidate list of vehicle parameters to monitor along with how to encode the data for each. There is a pin in the connector that provides power for the scan tool from the vehicle battery, which eliminates the need to connect a scan tool to a power source separately. OBD-II Diagnostic Trouble Codes are 4-digit, preceded by a letter: P for engine and transmission (powertrain), B for body, C for chassis, and U for network. Manufacturers may also add custom data parameters to their specific OBD-II implementation, including real-time data requests as well as trouble codes.
The ELM327 is a programmed microcontroller for interfacing to the on-board diagnostics (OBD) interface found in most modern cars. The ELM327 command protocol is one of the most popular PC-to-OBD interface standards and is also implemented by other vendors. The original ELM327 is implemented on the PIC18F2480 microcontroller from Microchip Technology. The ELM327 abstracts the low-level protocol and presents a simple interface that can be called via a UART, typically by a hand-held diagnostic tool or a computer program connected by USB, RS-232, Bluetooth or Wi-Fi. The function of such software may include supplementary vehicle instrumentation, reporting of error codes, and clearing error codes.
While Torque is probably the most well known, there are many applications that can be used with the ELM327.
Step 12: Hack the Planet
Thank you for sharing our adventure into automotive electronics. If you have enjoyed this Instrucable and would like to have a box of electronics projects like this delivered right to your mailbox each month, please join us by SUBSCRIBING HERE.
Reach out and share your success in the comments below and/or on the HackerBoxes Facebook page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of HackerBoxes. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!