In a Nutshell
Our ECE 4760 final project was a car made of K'NEX that follows a LED strip.
What We Did
For this project we made a K’NEX car that follows a path made by a LED strip. We used two phototransistors to detect the lights from the LED, while considering ambient light. The voltage generated by the phototransistors were sent to an A-to-D converter so that we could calculate the car’s relative position compared to the LED strip and decide when to turn in software. We then controlled the car by sending the appropriate signals to the motors.
Why We Did It
The initial inspiration for this project came from the movie TRON: Legacy.
In the movie, there are trains called "Solar Sailers" whose destinations are directed by a beam of light.
Here is an image of a solar sailer:
After some brainstorming, we came up with the idea of a car that could drive by itself by following a path of light. We thought this could be a practical and cool project. We initially envisioned the road to be made of two LED paths: one on the left and one on the right of the car. This would be like the lane markers on a road that we see today. A transportation system like this has several benefits:
For example, LEDs consume much less power than lightbulbs. Therefore, we can save power by switching to LED lit roads from regular streetlamps. We an also implement traffic systems by having multicolor LEDs. Green LEDs mean the car can go at the speed limit. Red LEDs mean the car will stop. The lights can change to yellow to make the car slow down. The lights can dynamically change so that a certain distance before and after a car is yellow. This could prevent bumper-to-bumper accidents. This system can also combat drunk driving and other traffic accidents, since the driver is no longer a human.
Back to top
High Level Design
For our project, we used an Emitter-Follower (or Common Collecter) setup for the phototransistors. We set up the circuit as shown on this page. We desired a circuit that generated an output that "moves from the low state to a high state when light is detected." When light was not detected, we wanted the ADC to output a lower number, and a higher number when light was detected. The emitter-follower circuit will output approximately Vout=Ie*Re, where Re is the emitter resistor and Ie is the emitter current.
Our hardware logic structure looks as follows:
In our project, the phototransistors sent their outputs to the ATMEL Mega644 microcontroller. The MCU then calculates which motors should move based on the phototransistors and sends a signal to the optoisolators telling which motors to turn on. Depending on which optoisolator is turned on, the motor control will tell which motor to move. We used optoisolators to separate the MCU from the motor circuitry. Optoisolators isolate the LED side of the circuit from the phototransistor side of the circuit, ideally protecting the MCU from any unknown outputs from the motor controller.
Snce we used K'NEX to build our car, we had to deal with an imperfect steering system.
This steering system had a very limited turning angle.
However, since the parts were preowned, it was free, as opposed to buying a toy car.
Another tradeoff we had to make was the LED strip color and photodetector. In our project description, we talked about how we wanted green LEDs to mean go and red LEDs to mean stop. We found that multicolor LEDs were more expensive than single color LED strips. We also had trouble finding LED strips that were sideways flexible, long, and cheap. We did not want orange LEDs, but orange LEDs were the cheapest available option. Additionally, there were phototransistors in stock that were sensitive to the dominant wavelength of the LED strip. Therefore, we chose the orange LED strip.
We used USART to communicate with PuTTY when debugging our project. However, we took it out in the final stages, after it was no longer necessary.
Patents, Copyrights, Trademarks
K'NEX Car Design
We wanted to make a car out of K'NEX because we owned a lot of K'NEX that we could use for free in our project. The K'NEX car motors and motor controller came from the Cyber K'NEX Ultra 2.0 Robot Kit which goes for $350 on Amazon at the time of this report. This is because the set is no longer sold. Therefore, reproducing our project is probably not viable. Also, we customly built our K'NEX car, meaning there is no instruction set for the car. However, if one has the correct parts, it is probably possible to rebuild the car from the pictures.
Our project used two motors, which were encased in a K'NEX fitting and were connected to a motor controller (also from K'NEX).
Since the motors were from a set that had three motors, the motors are numbered on the K'NEX fitting.
We used motors 2 and 3, because they are connected to the same controller (motor 1 has its own controller).
The motor controller had 6-pin port which one could use to drive the motors.
This is because the K'NEX set has a parent controller that sends instructions to the motor controller through these pins.
We experimented with low voltages to see how we could interact with the pins to make the motors turn.
The following diagram shows the pin diagram of the motor controller:
The following table maps the motor control pins to their function:
|Motor Cotroller Pin #||Voltage Required (V)||Function|
|2||3||Turn Motor 3 Clockwise|
|3||3||Turn Motor 3 Counter-Clockwise|
|5||3||Turn Motor 2 Counter-clockwise|
|6||3||Turn Motor 2 Clockwise|
To tell if a motor is spinning clockwise or counter-clockwise, we put the wire on the left side and position the motor casing so that we can read the number on it.
Our initial tests found that Pin 1 is ground, and a voltage of -1.5V was required on Pin 4 for the motors to turn in the opposite direction. However, when we raised the pin voltages to 3, we found that we did not need Pin 1 to drive the motors. Thus, we left Pin 1 empty, since we were able to control the motors fine using only pins 2-6.
The circuitry for the motor control is in the appendix. We measured the resistance of the motor controllers and it turned out to be around 47kOhms. To be safe, we used an optoisolator (4N35) to separate the microcontroller from the motor controller. We used 330Ohm resistors in series with the input of the optoisolator to prevent the microcontroller side of the circuit from shorting when the internal LED was on. The actual resistor values were 331Ohms, 328Ohms, 326Ohms, and 324Ohms. We drove the optoisolators from Port B0 to B3 on the microcontroller. If we put an active high on the port, the motor would spin.
On the motor control side of the optoisolator, we connected the collecter to a 3V battery source and the emitter of each optoisolator to the motor control pin. We did not bias the base, because the light from the internal LED was enough to drive the optoisolator.
Motor 2 controls the front steering wheels and motor 3 controls the back driving wheels.
The circuitry for the phototransistor is in the appendix. We got two phototransistors that were sensitive around the 615nm wavelength our LED strip was emitting. We used an emitter-follower setup to amplify the current that was produed by the phototransistor when it was turned on. The datasheet stated that the current when turned off was around 0.5 microAmps at most, and when turned on, would range between 0.25 to 0.6mA at Vce=5V. Since our MCU Vcc is 5V, we could simply use the numbers from the datasheet. The ADC reference voltage was set to 2.56V, so we had to find a resistor that was between 4266.6 to 10240 Ohms. We tried a resistor of 10kOhms, which worked well so we decided to stick with it. The actual resistor values were 10.2kOhms and 9.86kOhms. We connected the output of the emitter-followers to Port A0 and A1 so that we can use the ADC on the MCU.
Since our project was a car, we could not use the STK500 for our final design.
Therefore, we built the cutom PC board, which can be seen here.
However, we left out the MAX233 and RS232 because we did not need a serial interface on our final board.
This posed some difficulties in debugging in the later phases, but saved money, since our final design did not need a serial interface.
We used an ATMEL Mega644 with a 16MHz crystal because this is what we used throughout the semester. Although we probably could have used a less-powerful MCU, we decided to stick with what we knew best.
For the project, we used ports A0 and A1 for analog inputs from the phototransistor circuit. We used ports B0 to B3 to control the motors, and port D2 to control the test LED on the custom PC board.
We made our test track using the LED strip and some cardboard boxes we had lying around in our dorm.
We flattened the cardboard and put the LED strip in the center.
To make sure that we can still configure the track in different paths, we only tied down one end of the LED strip.
This side was attached to a 9V battery.
Even though the LED strip required a 12V source, 9V was enough to light the LEDs, so we used one 9V battery.
Back to top
Our software consisted of test components and the final design.
We started off with code to turn the motors after we figured out how the K'NEX motors worked.
This test code spun the two motors in two different directions.
We used PORT B to do this, since PORT A was reserved for the ADC necessary for the phototransistors.
We used C macros to keep track of which port was assigned to which motor/direction.
Once we got the motors working, we switched over to the phototransistors. After we got the hardware prepared, we put one output of the phototransistor into PORT A0 and the other into PORT A1. We initiallized the ADC like we did in lab 3 for the trimpot controller (Lab 3). To test if the phototransistors worked, we used uart.c and uart.h to communicate with PuTTY. We printed out the ADC output from one phototransistor, and then the other. Since the conversions take time, we found that in order to do two conversions, we needed to wait several cycles between reading and starting the conversions. Therefore, we created a task adc() which runs every 10ms to read one output (so it takes 20ms to read both). This was more than enough time to read the outputs and since our car was not very fast, we did not ned to sample the phototransistors any faster.
One thing we needed to take care of was to make sure the ADC did not respond to ambient light. Since the phototransistors were underneath the car, ambient light did not pose a large problem. Underneath our car, the phototransistors only outputted between 3 and 10 when the LED was turned off. When the lights were turned on, it detected between 3 and 230, depending on where the LED strip was. If the phototransistor was only detecting 3, it meant that the LED strip went out of the phototransistor's detection range (which falls after around >30 degrees). To kill ambient noise, we set a threshold so that if the output of the ADC was less than the threshold, the software did nothing with the motors. This threshold was set to 20, since it was signifcantly greater than 10 and it worked well.
The greatest challenge was putting the two parts of our hardware together in software. First, we made a simple test program that would spin only one motor in only one direction. By doing so, we were able to test whether or not the phototransistors and the motors were still working properly. This test was important, because we decided not to add a USB connection to our custom PC board to save money. Thus, once our hardware was soldered together and placed on the car, we could no longer communicate through PuTTY for easier debugging.
While testing our car, we noticed that the motors did not have enough power from the batteries to spin two motors at a time. To get around this, we made our software such that only one motor could spin at any given time. We first checked if the value in Ain0 or Ain1 were greater than the ambient light threshold. We then took the difference of the two outputs. If the difference was between right_bound and left_bound, then the LED strip was centered with the car. Therefore, we drove the back wheels to go forward. If the difference was greater than right_bound, then we made the car turn its front wheels right. If the difference was less than left_bound, we made the car turn its front wheels left. To make sure the steering motor did not keep spinning (since this would cause our car to break) we limited how long the motor was allowed to spin by using a counter. If the steering motor spun for its limit, we made the car drive the back wheels again. We tried spinning both the steering motor and the driving motors at the same time but it did not work. We also tried alternating between steering and driving, but this failed as well.
Much later in the debugging stage, we replaced the batteries in the K'NEX battery pack and noticed that fresh batteries could spin two motors at the same time.
**DO NOT USE BATTERIES FROM WHEN YOU WERE 10 YEARS OLD!!!**
The fresh batteries spun the motors much faster, so we had to change some of the timings in our code. Additionally, we could now apin both motors at the same time, allowing us some freedom. However, since we already had something that was remotely working, we decided to keep the only-one-motor-at-a-time setup.
One problem that rose with the new batteries was speed. The car motors ran much faster with new batteries. This was fine if the car was going straight, but on turns, the car would drive too fast and it would often go off the LED strip. To fix this, we implemented a simple software Pulse-Width Modulator (PWM) to control the driving wheel speed. If the car was going straight, it would drive at full speed. On turns, we made the car drive at 25% of full speed, meaning the PWM was on for 1/4 of the time. This causes the car to move slowly and to look like it is stuttering. However, we could not drive the motors too slowly because the motor control circuit and the motors react slowly.
Now that we could drive two motors at the same time, we added in a function that would recenter the wheels when the car was coming out of a turn while still driving. This made some turns smoother but also added some limitations on S-shaped tracks because the car would now go straight a tiny bit more before turning in the opposite direction.
Lastly, we made our car recenter its steering wheels and stop driving when the phototransistors detected less than the ambient threshold. If the phototransistors detected less than ambient, it meant that the car was off the LED strip for whatever reason. By recentering the wheels, it allowed us to test our car again without manually centering the wheels. We were able to do this by using the turning limits we used on the wheels mentioned earlier. We simply made the steering counter go back to 0 if it was not at zero. If the counter was less than 0, we made the steering motor turn right. If the counter was greater than 0, we made the steering motor turn left.
Back to top
Speed of Execution
Overall, our project responded very quickly to the LED strip. The motor state was updated every 25ms, which was fast enough for practical purposes. The PWM made the car slowly on turns, but this slow speed was necessary for the car to turn without overshooting the track.
Our car, due to its design, had a very limited turning range.
The phototransistors would detect the light, but if a turn was too sharp, the car would drive off the road, often hooking the LED strip and dragging it.
However, for turns within its range, the car would be able to make the turn properly.
Another problem was a straight line. Again, because of it's design, the car would never actually drive perfectly straight. It would always be biased a bit to the left or right. This caused some problems on straight paths, because it would still not drive straight. On straight paths, sometimes, the path is short enough, or the car is straight enough that it would drive fine. However, the car would sometimes oscillate on the straight path.
Our car was relatively safe, since our car was designed to stop if the phototransistors were not detecting above ambient light. This meant that our car would not run into other people or run amok in the classroom. Once the car ran off the track, it would immediately stop. Our car, unfortunately did not have airbags for our driver, but I think he is okay.
Interference with Other People's Designs
Our car had two motors that could have created some noise for other people.
However, since our circuit was right over the motors and it was running fine, we highly doubt it was causing problems for others.
We also used an LED strip that emiited orange light, which may have caused problems for other people if they had projects operating on a similar wavelength. If we were to interfere, it was probably the amount of space our car required. The LED strip was 38" long. We were able to test it underneath our workbench, but we may have gotten in the way of other people. Later in testing, we took our project outside the lab room and tested in the hallway.
Our project is usable, but the limited turning angle may pose a problem.
If the LED strip turns too sharply, the car will react, but not be able turn sharply enough.
This turning angle is approximately 30 degrees.
Another thing we realized is that the car can catch the LED strip and drag it if it got close enough. To fix this flaw, we would need the LED strip to be embedded into the path so that it is on the same elevation as the road. That way, the car can drive over it easily. We couldn't really do that with this project while keeping the road configurable. One option we had was to take a large sheet of glass (or some other stiff, transparent sheet) and put it over the LED strip. However, this would take time and money to get. According to google, a large sheet of glass goes for at least $100.
Back to top
Our project met our expectations fairly well.
After building our K'NEX car, we realized that it would have a limited turning angle.
The final design only reinforced this, because our car would go off the LED strip path for sharp turns.
However, if the angles were within the car's turning angle, the car would behave as expected.
One thing we did not account for was the height of the LED strip. The LED strips we used in other classes were rounded and low, so our car would be able to go right over it. However, those strips are not designed to bend left and right. Thus, we bought an LED strip that was flexible in the left and right directions. This LED strip ended up being tall and were straight, so the car could not go over the light. Instead, the car would end up grabbing the LED strip and dragging it.
Conform to Applicable Standards
When testing our project, we used USART to handle communication between the computer and the microcontroller. In our final design, to the best of our knowledge, we did not have any standards that we needed to follow.
Our project referenced some code from
ECE 4760 - Spring 2010 Final Project - Image Scan Using Phototransistor Array
and some code from our ECE labs,
although we modified the code to fit our own needs.
We did not use any open-source code from the public domain.
Our design is original, although we got ideas from the movie TRON: Legacy.
We built the steering mechanism of the K'NEX car using images found at
K'NEX Steering Mechanism.
We do not believe there were any patent or trademark issues we had to deal with.
We did not receive any sample parts for this project.
We are not certain if there are patent or publishing opportunities for our project. Since there are no LED strip following cars seen in public, it may be possible to get a patent on this idea.
We followed the IEEE Code of Ethics to the best of our knowledge.
Since our project was a moving object, we had to make sure it would not endanger the well-being of the public and environment.
We made sure that if the car was not detecting light significantly above the ambient threshold, it would not move.
If the car was moving previously, but stopped detecting light, it would stop moving as well.
That way, our car was guaranteed to stay within our testing area, which we made sure people would not enter.
The motors were from a K'NEX set that was meant for ages 10+, meaning our car is not suited for children under the age of 10. Our car also has small parts, meaning it poses choking hazard for small children. We made sure there were no small children nearby when working on our project. If our car is to be replicated by some other party, they must make sure to follow the age restrictions.
Our car and LED strip required 9 Volts, which is within safe range. Our components can produce low amounts of heat and magnetic fields, both of which cannot be helped and should be safe. The LED strip should not be stared at for long periods of time, for the light emitted are quite bright. However, there are no health warnings for the LED strip on the vendor website.
All of our claims in this report are honest and realistic. We are quite inexperienced, with this project being the first real ECE design project. We tried our best to do our best while keeping any legal restrictions, ethics, and standards in mind. If our project did not follow any rules, it would be because we were unaware of them, even after our research.
We did not accept any bribery in any form, nor did we bribe others in any form. We tried to learn as much as we could from this lab. We thought of appropriate applications of our project. Modern cars can be very dangerous if misused, so a car that could drive itself could be beneficial to the world. LEDs are much more energy efficient than street lamps, so LED-lit roads would be much more energy efficient. Furthermore, LED-lit roads can be placed on any road, where as street lamps would have to be placed next to roads, requiring more space. If cars could follow LED strips, then people would no longer have to worry about drunk driving or reckless drivers. These cars would also benefit disabled people who cannot drive as well.
We have also considered the limitations of our project. For instance, we have to make sure our project is weather-proof. The LED strip we bought was IP67, which means that it is "Totally protected against dust" and "Protected against the effect of immersion between 15cm and 1m" Ingress Protection However, we have to make sure the lights would not be covered by physical objects such as rocks and snow.
Since we are still inexperienced ECE majors, we are still in the process of learning much about the field. We are working hard to improve our technical competence and will only take on tasks when we are fully qualified. We are willing to take any constructive criticism and will acknowledge and correct any errors we have made. We will also credit all who have contributed to our project.
We will not discriminate based on race, religion, gender, disability, age, or national origin. Our product is for all to use and learn from, as long as they are above the age of 10. Any real-world implementation of our project will be for all groups of people. We will not endanger the physical, mental or social well-being of others and will support all of our colleagues and co-workers.
We made sure to follow any legal restrictions we found that applied to our lab.
We researched if there were any limitations on using the dominant 615nm wevelength of light that our LED strip emitted.
We also researched if there were any restrictions for toy cars, such as maximum toy car speed.
We were unable to find any legal restrictions that limited either of these.
The K'NEX pieces we used are for ages 10+ so our project is for ages at least 10+ as well. If we were to scale our project to a real car, we must follow the legal speed limits imposed on streets.
Back to top
Custom PC Board
|Part||Part Number||Vender||Quantity||Unit Price||Price|
|3V AA battery pack||Lab||1||$0.50||$0.50|
|9V Battery clips||Lab||2||$1.00||$2.00|
|Custom PC board||Lab||1||$4.00||$4.00|
|K'NEX Cyber Ultra 2.0 Robot Kit||Preowned||1||$0.00||$0.00|
|K'NEX Spare Pieces||Preowned||1||$0.00||$0.00|
|Large solder board||Lab||0.5||$2.50||$1.25|
|LED mounting clip||WFLB-X96-MB||SuperBrightLED||10||$0.15||$1.50|
|Small solder board||Lab||1||$1.00||$1.00|
Appendix: Task Distribution
|K'NEX Car||James Miyamoto|
|Test Track||Gloria Lu|
|Hardware Design||James Miyamoto|
|Hardware Fabrication||Gloria Lu|
|Hardware Testing||Gloria Lu|
|Software Design||James Miyamoto|
|Website Design||James Miyamoto|