Showing posts with label microcontroller. Show all posts
Showing posts with label microcontroller. Show all posts

Thursday, September 17, 2015

How to add intelligence to our homes? - Part 2

This is the long overdue update of the house project conceptualized a while back with my kids.  In this project, a model house was wired for simple lighting using LED's.
 
The USB home
Each part or room in the model house will be lit by a dedicated LED and each LED will be directly connected to the pins of the microcontroller, in this case, the Arduino Uno.
 
The Arduino Uno wired using a recycled IDE cable


The Arduino being wired
The Arduino will act as a hardware controller/driver to power up the LED's but commands will come from a PC.  This whole architecture can be ported to a real, full sized house and control is not limited to lighting only but for the purposes of demonstration, the model house should be sufficient to illustrate.
The GUI in a Windows PC



The GUI showing the check boxes and sliders as control inputs

The model home is connected to the PC via the USB port.  The Uno will function as a slave unit with the PC as the master.  If a user clicks on the GUI, the corresponding LED will light up (or toggle off) in the actual model home.  This therefore illustrates how a real USB controlled home can be made possible.

Wednesday, December 25, 2013

Line tracking truck upgraded

Well, it's Christmas and the kids and I have more time together.  We exchanged gifts and I got this gift below.  This is a collection of comics pages from newspapers!  :-)  This is probably the funniest I got so far so I can really look forward to the next year and be excited about what to expect again next.



After the gift giving part was through and the funny talk has subsided, we were back to the line tracking truck project.  After the code was tested and optimized for actual runs (considering motor speeds and sensor feedback triggering, etc), it was time for some UPGRADE.   One interesting upgrade is how to incorporate a reasonable degree of recovery in cases of overshooting the line.  Thus, a "recovery" routine must be integrated into the code so that the truck will try to "look for" the line back once an overshoot is encountered.  Several code modifications were needed to make this workable.

1.  The overshoot should be minimum.  Thus a quick stop code is to be designed to react quickly once overshooting is detected.
2.  Overshoot must be defined.  The idea is to try to recover from a turning overshoot.  If the line/tape ends in a straight line, the assumption is that the end of the line is reached and no need to "recover."  However, if the overshoot happens in a turn, the truck should try to get back into the path.
3.  There must be a limit to the recovery procedure.  If after a certain number of tries, success is still not achieved, the truck should stop trying in the end.


In this upgrade, the truck was already provided with an auto-detect function.  In the previous run, the tape was white and the floor was dark.  This time, black "tape" is used against a white floor.  The truck will auto-detect a bright or dark floor and then use that information to sense the line/tape.  If it cannot calibrate, it will flash an LED so the user will know that a calibration error occurred.  A manual reset is needed (so it can try to calibrate again)


Looking for a black tape however was not as easy as I thought.  I cannot find a black tape at home wide enough for the sensor spacing design and stores are closed for the holidays so some improvisation was required.  So finally, some scrap black strip and a laptop bag strap were used for the testing.  A bend was introduced into the path so that the truck will overshoot on purpose during the execution of the turn.  If you remember, the minimum turn radius of the truck is only 2 feet.  The bend below is definitely with a much smaller radius than the supposed smooth turn of 2 feet. 


To come up with the logic of the recovery, the assumption was that there must be first a "detected" turn event.  This will be the basis for action.  The recovery will involve a reverse move with a matching steer to the opposite direction.  (the steering for this reverse motion is currently set at 10degrees only)  The truck then will stop at an instant of tape/line detection.  This is the desired success criteria for the recovery procedure so that the truck can go back into tracking the line.  If the truck cannot find anything after a certain number of search cycles (this time it is set to 5), the failure will be acknowledged and the search will stop.


After several erroneous codes and some funny truck behavior, the serial monitor was used (and abused) to understand where the erroneous values came from.  Then it was found that the sensor values in the "recovery" routines were conflicting with the initial calibration logic and modifications were made for consistency.  The timings for the quick stop motion was also not right.  In the end, for the truck to stop, I have to introduce a reverse motion at full motor power for 500ms.  This is enough to "kill" the momentum but not enough to cause much reverse movement.


Finally, below is the video of the truck overshooting and trying to recover.  Notice how it stops and reverses in the bend, then recovering back to tracking the line.  Then, it makes a quick stop after the line ends (this time in a straight line fashion). 


Merry Christmas to all.  May God richly bless everyone and more projects to come for 2014!

Saturday, December 21, 2013

Line tracking truck update

This is a sequel to the line tracking truck project previously posted.

Calculating minimum turning radius:

By design, the steering front wheels can turn by as much as 18 degrees.  The wheelbase is measured at 185mm.  Based on design geometry, we calculate "r" as the minimum turning radius of the truck.  At maximum steering angle of 18 degrees on a wheelbase of 185mm, the minimum turn radius is calculated as per below to be around 600mm (2 feet). 


Thus, by mechanical design, the minimum turn radius that the tape can be laid out so that the truck can follow without overshoot is at 600mm.  A bigger radius or curvature will of course ensure that the truck will not overshoot in the turn.

This seems to be a reasonable design limit so the project can proceed to reality.  Using the same electronics already built into the truck in the light seeking truck project, we just modify the software inside the microcontroller to make this work.  This time, we will make use of the 4-channel IR sensor that was previously installed in the front bumper of the truck.



The first prototype of code made a lot of overshooting.  The steering cannot cope up with the forward motion thus causing overshoots.  As there are four sensors in the front of the truck, the logic was programmed to be as follows: (values were made by initial performance estimates)


To make sure the steering can compensate, the code was optimized for minimum cycle time.  The faster the code can run, the more that the truck can stay on the tape.  After corrections, the prototype code was ready to run.


The next development to this project is overshoot correction and recovery.  That can be a little tricky but that will be available soon.  Watch out for the next sequel...

Saturday, December 14, 2013

Cruise control for an old truck

Cruise control is to maintain a car's speed at a certain number during long drives.  The system is designed so that the throttle is electronically controlled to adjust and respond to the load demand.  As the car cruises along a gentle climbing road, the throttle should open up to maintain speed.  Inversely, as the road gently slopes down, cruise control will close the throttle to still maintain set speed.  The key is proportional throttle control as well as closed loop speed sensing.  

I happen to own an old truck with a manual throttle control as shown below.  For this project, this manual throttle control is the perfect candidate for automation.


To make it work:

1.  High torque servo motor drive mechanism
2.  Hall effect speed sensing
3.  Lots of speed calibration values
4.  Mechanical system to link the throttle to the control servo
5.  Stepping on the brakes to immediately disengage the system

For safety, the project will not tamper with existing electrical circuits and mechanical systems but will be a full piggy back system.  The servo mechanical drive will be fully override capable in case of abnormal behavior.  Power failure will also put all mechanisms back to manual default.

Project milestone:
Completion by end Q2, 2013

Ideas are welcome if contributed for free. :-)

Friday, December 13, 2013

Light seeking truck project

This project is a demonstration of how to create a light seeking system that is relatively low cost to make and execute. This involves an Arduino microcontroller as the heart of the whole project.  The target system is a truck that is a broken down RC, bought from a second hand store on an "as is" basis as referred to previously in the older posts. 

The building blocks:

Below is the video of the first building block of code and electronics.  It involves two light dependent resistors (LDR), a servo motor and a light source to test the responses.  As light is focused on any one of the LDR's, the servo moves accordingly.  The design thought of is that the servo movement should be relative to the difference in intensities read by the LDR's.  The bigger the delta, the greater the angular rotation.  This system will be the basis of the steering system for the truck.

 


From the above, the design was copied into the truck body itself using a prototype breadboard as seen below.  The servo motor is already installed in the steering mechanism replacing the original DC steering motor installed.  We would be interested to control the steering in incremental fashion and not only in fixed angles, left or right.  Aside from the LDR's, a 4-channel IR sensor is also being put in place to be used for another project later on (the line follower project).




This is the first prototype of the hardware and software together in the truck body.  The original electronics of the truck were removed (PCB at the tip of the screw driver) and will be disposed of.  The software was tested using an Arduino Leonardo (mini format) compatible board.  This was chosen because of the thin layout fitting the thin breadboard.  The program will be ported later on to the Arduino Uno to be installed into the truck body.



Below is the truck with the LDR's already in place.  Two placed in the front and two at the back.  All placed on the corners of the truck body.  The Arduino board is also installed as can be seen under the deck of the truck.  The power to the drive motor will be provided by the L293D H-driver IC.  All the IR sensors are placed under the front bumper for the later project.


Almost all set.  Now, it's time to close the truck, upload the software and test run the system.  Below is the first steering test.  Using a laser pointer to trigger the LDR's, the front wheels steer toward the light input.  This is our first taste of success.



For the full functional test, power must now be from batteries because we have been using the USB port to power the system yet.  The final step was to connect the Arduino to battery power as well as connect the H-driver to the battery as well.  The drive motor will be powered from the battery without going through the Arduino. 


Running the prototype:

Below is the first ever test run of the light seeking truck.  Obviously, the sensors and steering need to be optimized further but the demonstration unit is already a success story. 



How to add intelligence to our homes?

Smart homes were science fiction stuff back decades ago.  With the advances in technology these days, the demand for smarter homes become more and more.  With a little bare engineering, we will try to model a house with lighting that can be controlled via a USB port, creating a "smart home" appeal.  Because the technology is available using microcontrollers, we will be able to deploy the system in a very cost efficient scenario.  The goal again is not to re-invent but rather to create something with bare engineering and still have fun along the way.


We will start with the model house built by the kids above.  It has a garage, a kitchen, a bedroom, toilet and a little living space.  The project will be to light this model house using LED's.  The LED's will be controlled via software in a PC. 

How to make it possible:
1.  Model house - need decorations...
2.  LED's controlled by Arduino Uno
3.  PC with application software written in VB
4.  The PC will communicate with the Arduino via USB to trigger light switching
5.  Target completion - within Dec 2013  :-)

Monday, December 9, 2013

Microcontrollers are for kids too

Microcontrollers are little electronic boards that can be programmed to a variety of functions. These are abounding everywhere around us today. Almost everything electronic we have now are driven by some form of logic and controls. From radios, phones, cameras, cars, alarm systems, aircraft, etc, etc. But kids can have their share of the fun too. So I bought a non-functional RC toy truck from a second hand store in order to transform it into something that functions again. This costs me almost nothing as this was sold in an "as is" basis. As this is a "kid friendly" project, my idea is that the kids will be able to relate to microcontrollers without the "burdens" of development work. In fact, they will end up playing, and hopefully have much fun along the way.


So what are the projects in store for us?
1. Line tracking truck
2. Light sensing truck
3. Open space seeking truck

So kids and young at heart, track this truck project along as they will have updates soon!