Software apps and online services
Hand tools and fabrication machines
PHASE 1 (Photon #1)
This project was focused on building an IOT (Internet of Things) controlled RC Car using 2 Particle Photon Microcontrollers. The first Photon would be in charge of driving the car and the second would need to trigger turn signals when appropriate (over the internet). The goal of this project in the end was to replicate the performance of a traditional RC Car via the IOT.
Before I get into describing any more of this, I urge you to check out the YouTube video here (https://youtu.be/c2Bw4nx5l6Q ), it hits everything in pretty deep detail, it might be easier to follow.
To begin the project (with 2 photons already on hand), a relatively cheap RC Car was purchased, along with a generic DC motor controller (all from a local Hobby Store). The car saw plenty of use in stock form, to evaluate the performance that we ultimately had to meet. From this point, with a good basis of comparison to start off with, the car was disassembled and examined
There were 2 internal DC motors, one smaller one for steering, and one larger, for Forward/Reverse. For reference, the car was full time Four Wheel Drive. Controlling the car originally was a small board with an RC Antenna, with power and ground, and 2 wires per motor. The car ran off of a 9.6V Ni-Cd battery with an ON/OFF switch interrupting power to the board.
From here wires were run from the power switch, the steering motor, and the drive motor through 6 holes which were drilled into the sealed case. This meant that the fragile gear assembly and motor connections wouldn't have to be messed with again and all that was left simple wiring
Now the DC Motor controller was mounted to the case with 2 sided tape.
A little bit about the motor controller we used. It is a L298N Dual H bridge type. There are other motor controllers out there, but this what I found at the Hobby Shop, and We knew it could get the job done. Basically this unit can turn 2 separate DC motors in different directions, at different speeds, independently of each other. It has a 12V input, (well, a max of 12V) we have a 9.6V battery so we are under that threshold, 2 outputs for the motors it can drive, and a 5V output( this will be perfect for powering both Photons).
So at this point, the obvious connections were made, output 1 of the motor controller went to the drive motor, and output 2 of the motor controller went to the steering motor. Also the switched power was run to the 12V input. The tricky part was the 6 "Control Pins", they took some time to figure out. See the video and schematic for a better explanation.
The ENA (Enable A ) pin is a kill switch for the first motor, it must be set to high to drive a motor in either direction. The IN1 Pin and IN2 Pin, in different combinations, power the Drive motor to turn in different directions. This is the same for the ENB Pin and IN3/IN4 Pins. The enable pins can also be Pulse Width Modulated (PWM) via a digital output on the Photon to control motor speed. This means you can force the car to drive around slowly in tight spaces to avoid hitting obstacles.
This will make a ton more sense if you're familiar with an Arduino or any other micro controller, but the HIGH and LOW commands (state might be a better way to put it) come from digital pins on the Photon.
The logic was tested with the first photon using the Tinker App/Firmware that comes installed on the Photon from the factory (Not sure what this is? https://docs.particle.io/guide/getting-started/start/photon/ follow this link). It makes it easy to turn outputs on the Photon High and Low. Once the correct logic was found, the car was reassembled, breadboard mounted, and Photon placed.
Now the car needed a better control strategy. With the Tinker App the car could be limped around moved forward and backwards and such but the car needed to be just as drivable as it was with the original RC Remote. The solution for this problem was a smartphone app called Blynk. Blynk is a free app available for Apple and Android Devices. Like Tinker, Blynk lets you control the Photon from your smartphone, but Blynk however, is fully user configurable. You can manipulate any pin on the Photon and control it with a push button, a slider or a joystick. These buttons can be set to be momentary, or ON/OFF. Ultimately Blynk creates an awesome interface with an amazing response time and minimal coding. It takes 7, that's right, only 7 lines of code to give Blynk full control over your Photon, and in our case, our Car.
All it takes to setup Blynk is to open the App and grab the authentication token from the project you create, Blynk will email this code to you. Then you need to open the Particle IDE and create a new program. You will need to include the Blynk library first. Next just copy the following code and flash your photon. This is a modified version of the Blynk example code found in the Particle IDE. You may notice I censored the authentication token.
Now all that's needed is for you to go on your smartphone and configure the app with 4 buttons and 2 sliders. The sliders scale the steering and drive motor outputs. The sliders are scalable from 0 to 255, so with the Boost Controller set at 255 the car will accelerate as fast as possible and at 120 it will creep along at a slow crawl (stall torque isn't much below 120). Scaling the Steering slider varies the max steering angle the car will see.
You can configure the buttons seen above with the following settings.
At this point, with the Blynk app as configured, the car was performing just as well as it did when it was RC. The driver is able to slide the car around, accelerate and turn as quickly as they desire. Here is a gif of some skids on a hard wood floor. The rears are taped up on this one, otherwise full time 4WD (with open diffs) makes for difficult drifting.
PHASE 2 (Photon #1 and #2)
Now we get into Phase 2. This Project was completed for credit in a school project (Instrumentation and Measurements Class) and one requirement for this project was to use a 2nd Photon. The second Photon would have to receive a variable from the first Photon. In this case the second Photon will be receiving a command to fire Left and Right Turn Signals on the car.
The first task in doing this was to get the two Photons talking to each other. This was accomplished using the Publish and Subscribe function. Ultimately this is a message that one Photon publishes to the Particle Cloud and then the other Photon listens for this message and when heard, responds accordingly. You can examine the code behind this project and see our example of doing this.
With this code the Second Photon will blink its onboard D7 LED when the First Photon blinks it's D7 LED. We used this code to test our Photons. Note that this is setup for the Blynk App to be able to make the D7 Pin blink and have the Second Photon react to this. If the D7 Pin goes HIGH, or blinks in other words, the event called "TEST" gets published to the Particle Cloud. The second Photon Subscribes to this event and when it sees this event published on the Particle Cloud, it turns its D7 pin HIGH. Now you can extend this logic to our current program and instead of the First Particle detecting whether or not the D7 Pin is HIGH, it detects whether or not the D4 (Turn Right) or D5 (Turn Left) Pins are HIGH and Publishes two seperate events (LEFT or RIGHT) for each one. You can check this out in the Code section and hopefully the logic can be seen.
As far as hardware goes, the second Photon was placed right behind the first on the same breadboard. This Photon used the same Power and Ground as the first Photon. Next, holes were marked and drilled into the body panels with a 3/16 Drill Bit (0.1875") LED's (0.195") were inserted. To prevent any shorts, the legs of the LED's were covered in Heat Shrink. Then scrap 22 Gauge Single Strand Phone wire, was soldered to the LED legs. These 8 wires were drawn together at each corner and soldered to 2 18 Gauge wires (+/-). These soldered joints and wire bundles were covered in more Heat Shrink for reinforcement The key to this part was layering Heat Shrink to strengthen all the connections and make the wires rigid enough to be mounted and run.
These 4 sets of positive/negative 18 Gauge wires were brought back to the breadboard and the second Photon. The Positive Left Side wires were run to Pin D0 and the Positive Right Side wires were run to Pin D6. All the Negative wires were run to the Ground Pin on the second Photon. NOTE, A 100 OHM RESISTOR IS REQUIRED FOR THESE LED'S. There were 100 Ohm resistor placed in front of the D0 and D6 Pins to protect the LED's and keep from burning them up.
In the end the LED's turned out great. They trigger on command and can be held on if desired by the user. Again these LED's are simply triggered off of the BLYNK app commanding a Left or Right turn from the First Photon and then the First Photon publishing a "Left" or "Right" based on the desired action. The second Photon listens for and receives these events then turns on the appropriate turn signal. There are no wires running between the two Photons except for Power and Ground, the Turn signals are triggered entirely off of wireless communication between the two Photons.
Last, but not Least...
Graphing. A portion of this project was to publish live data to some IOT based graphing platform such as Thingspeak or Atomidot or Azure. In our case we attempted to move data to graphs via Thingspeak via a Webhook, however this did not work out as we expected. Even though the particle console showed successful receive messages from Thingspeak, we were not getting graphed data. After being defeated by Thingspeak, with quite a lot of time invested, we turned to IFTTT. In our case if a Left turn event was published, then IFTTT would add a row to a spreadsheet in Google Docs. In all honesty, graphing isn't all too relevant to our project since we aren't receiving numerical data actively, or doing anything but actuating a couple of DC Motors.
The data shown in the below graph may seem irrelevant but it shows a left turn steering event being populated versus time. In our case, this is really all we're working with, a command to perform an action on the car, vs. Time. Here the Photon code was modified slightly and the event of "LEFT" was reprogrammed to have a message of "3". This was partly from troubleshooting the Webhook with Thingspeak, but that's beside the point. The value of 3 is published and shown vs. time in this case. The cluster of messages are from a "Purge" so to speak of left turn events that become published as soon as the Photon comes online. Pushing a command from the Blynk app breaks this purge. This is a minor quirk of the Internet Turn Signal implementation that otherwise has ZERO effect on performance.
In the end this project turned out great. The Particle Photon is an awesome little microcontroller with a great amount of support and tools that back it up. This project wasn't all that difficult, and nowhere near as difficult as we figured it would be. I think that the BLYNK app was probably the biggest help in doing this by providing us with an awesome smartphone interface. The car performs amazing. It's able to be inched back and forth and overall driven with a large amount of precision. The car can be operated remotely. I have driven it while being 60 miles from the car itself. This car is asking for a camera mounted interface that could be used to stream video back to phone and user. The BLYNK app supports this functionality and I may add it in the future. Ultrasonic distance sensors are also supported in the BLYNK app, so collision avoidance could also be added. If you've made it this far, thanks for reading!