Microcontroller Projects

see translations

Here are some projects I have been working on since November/December 2001.  I have been doing them for my own personal interest as well as to teach myself about embedded systems.  They are generally in chronological order, although I started the Solar Tracker before testing the R/C Airplane project since I was waiting for some parts to ship:

At the bottom of the page is a small glossary I made for terms that not everyone may be familiar with, but which I thought it would be disruptive to place their definition inline with the surrounding text.

Just before the glossary is my opinion about PICs and Stamp IIs, mostly about where/when I think it best to use each and why.  I started to write this in the R/C Airplane section but then realized it was out of context, but still might be informative to some, so I moved it to the bottom.

Solar Power System Analyzer

Purpose: This project is intended to analyze the performance of a solar power system.  By measuring and recording the power flowing from the solar panels to the batteries and out to the inverter, you can determine many useful things about your power system.

Technical Overview: Please refer to the following figure (Figure 1) as I describe the system.

Figure 1

Between the solar panels and batteries there is a shunt. There is also another shunt between the batteries and inverter.  By measuring the voltage across the shunts, I determine the amps flowing into and out of the batteries.  I also measure the current battery voltage.

To take these measurements, I have a microcontroller connected to an analog-to-digital converter chip (ADC) which is then connected to the batteries and the two shunts.  Each time I take a measurement, I store the values in memory.  Whenever my computer starts up, it downloads the data the microcontroller has gathered, and stores it permanently on the hard disk.

Analysis Details: By sampling these three pieces of information every so often all day long, every day, you build up a "picture" of your system's performance.  A simple analysis of this data tell you many things, such as:

These results can then be interpreted to tell you your systems strengths and weaknesses, and where additional money would be best spent.  For example, if you're going to put more money into your system, are you going to just blindly add more batteries, more panels, or perhaps a better inverter?  If instead you know the answers to the above listed items, then looking at them as a whole might clearly show you to be in one or more of the following scenarios:

  1. much more power goes into the batteries than I take back out of them
  2. only a little more power goes into the batteries than I take back out of them
  3. I have plenty of power
  4. I run out of or low on power at night
  5. I run out of or low on power sometimes even during the day
  6. my peak usage in amps is close to what my inverter is rated for

By determining which of these is true for you, you can determine where to best spend your money to improve your system for your usage.  For example, if #1 is true(and typically #4 will be true if #1 is true) then you know it's time to replace your batteries since they're not holding their charge well (aka they're old).  If #2 is true, and so are #4 and/or #5 then you know your batteries are OK but that you are lacking enough solar panels to replenish the amount of energy you are trying to use.  If #5 is true, then you should think about getting an inverter that can handle more power since using an inverter near its limits will likely cause it to wear out faster and eventually die- sell it now while it's still worth some money.  :-)

A Few Technical Details: 

Major Parts: These are the major parts used, I didn't list things like the wires needed to connect everything up, breadboards, etc.

Usage:  The Stamp uses serial communications to read the ADC values, store and retrieve data on the local RAM chip, and upload data to the PC.  A program on the PC connects over a long serial cable to the Stamp, instructs it to upload its data, then instructs it to clear its RAM chip and start gathering new data again.  This allows the PC to timestamp the data from the Stamp since it knows when the Stamp started sampling (cause it told the Stamp when to start), when the Stamp finished, and how many data items it gathered in that time.  This allows the program on the PC to compile a spreadsheet of timestamps with the corresponding voltages from the batteries and shunts.  With some conversion calculations it is able to also have figures for the power going in and out of the batteries at that time (volts * amps).

Development Status: Incomplete.  I had problems with the op-amp linearity.  Basically the system would collect data, but the data wasn't very accurate because the op-amp linearity was not good.  What this means is that when the system said 5 amps was flowing, it was accurate, but when it said 10 or 0 then in actuality it may have been 9 or 1.  As far as I can tell, the problem lies in the differential amplifiers I made to read the shunts.  I was using 1% accuracy resistors, but apparently (I read about this later) you need .01% or better resistors to have a good differential amplifier.  Who knew?  :-)  Anyway, I could fix this but I was mostly interested in the project for the sake of learning about microcontrollers and I'm not interested in the building of high-quality differential amplifiers, so I put this project aside for later.  Everything else seems to be working though, the software is working as expected- it's just waiting for me to feed it good data.

 

R/C Airplane In Flight Information System

Purpose: I thought it would be interesting to be able to see some information about my model airplane while it was in the air.  Specifically, I was curious about engine temperature since I suspected an engine in one of my planes was overheating and losing power, but I couldn't verify it since it cools quickly upon landing.  While I'm at it, adding other sensors such as RPM would improve the usefulness of the device.

Technical Overview: The idea is to mount a set of sensors onboard the airplane, read them into a microcontroller, process the sensor information into useful data, transmit the processed data to a microcontroller on the ground, and display the information on a small LCD screen.  This flow of information is diagramed here, in Figure 2.

Figure 2

The set of sensors that I am currently using are (in order shown on LCD screen):

The receiver has the ability to sound warning alarms on various problematic conditions:

Technical Details: In this section I will detail the information from start to finish of the information flow shown in Figure 2.

NOTE: I have not yet flown the aircraft because I am waiting for a part needed to make the transmitter's range good enough.  Unfortunately, I ordered the parts a couple months ago and finally when they still hadn't arrived, I sent an email only to be informed that they had no record of my order.  So I made another order by phone (instead of their e-commerce site) and hopefully the necessary part will arrive shortly.

I finally got the part I needed for the transmitter to work well, however the range still needs improvement.  The data gets refreshed only during fly-bys.

For the 5 sensors I'm currently using, here's basically how they work, including how the microcontroller reads them:

For the warning alarms, they are simply some if-then-else type statements in the receiving microcontroller's code which then call a couple subroutines for sending different sounding alarms through a small speaker.  I finally got to make the maiden flight, however the airspeed thing wasn't working at the time (haven't looked into why yet) and I found out that the engine temperature runs over 110 degrees centigrade which is the limit of the thermistor.  So these warnings will need to wait until I fix the airspeed thing and get a new thermistor capable of working with the maximum engine temperatures.

I have described most of the parts involved already, but I haven't mentioned that I'm using Basic Stamp II microcontrollers in the air and on the ground.  When/if I get around to it, I'll port the code over to PIC microcontrollers so that this device could be made more cheaply (much more given the cost of a PIC versus a Stamp II).  The ADC is an 8 channel 12-bit ADC from Maxim.  The transmitter is a TWS-434 from Rentron.  Everything else is either mentioned above or is a resistor, capacitor, or wire jumper!

Development Status: I finally got to make the maiden test flight and here's the status:

I had a bit of a hard landing when the engine quit during a low and slow fly-by, so I have to fix the wing before I can run anymore tests.  Here are the things I still want to work on:

By the way, if you are interested in flying RC airplanes or helicopters or U-control, and if you live in San Diego county (especially on the north end), I am a member of Palomar RC Flyers which is a flying club with a couple nice fields in the north end of the county.  Feel free to contact them if you're interested, or me if you just have a couple questions.  I joined because there are instructors there who teach you to fly for free- just cause they like to!  It's fun, try it.

Solar Tracker

Purpose: To learn about the PIC microcontroller while trying to develop a commercially viable solar tracker.  Tracking the sun increases the yield from solar panels anywhere from 25%-40% per day versus fixed panels, depending on who you believe :-)  Probably it varies based on the type of panel, how sensitive it is to the angle of incidence of the sun's rays.  Anyway, panels are expensive, so I figured if you could make a cheap enough tracker that people might buy it instead of buying more solar panels.  Also, a lot of the people currently owning solar power systems are probably the do-it-yourself type and might be able to install a tracker themselves if you sold them the control board cheap enough and it was simple to use.  So there were my goals: learn about PIC, make tracker simple to use and cheap.

Technical Overview: The panels are mounted on the same kind of mount that the old 10-12 foot satellite dishes were on, with a motor for changing the orientation.  Additionally, you need a rack to put the panels on, and then you just fasten the rack to the movable mount.

The basic steps for tracking the sun are as follows:

  1. take a measurement of panel output at current position, call this ADCcurrent
  2. move the panels a bit
  3. take a new measurement of panel output, call this ADCnew
  4. compare ADCnew with ADCcurrent
  5. depending on which measurement is greater, move east or west

It's a bit more complicated than that, with some steps thrown in for knowing when to stop moving and go to sleep for a while- but showing all those steps would make it too complicated and obscure the basic idea.  Sometime after the sun goes down and before it comes up, I move the panels back to the east in one big swoop which makes the morning startup more efficient than tracking back to the east in the morning.

Technical Details: The output of the panels gets measured by an ADC which is internal to the PIC (I used a 16F876 model PIC chip which contains 5 internal ADC channels so I didn't need an external ADC chip).  The panel output is run through a 15-turn potentiometer and the input to the ADC is the center tap on the potentiometer.  This makes an easily adjustable voltage divider to scale the panel output into the range which the ADC can work with.  Once you have done this scaling (which is super easy), then the tracker is ready to go.

To move the tracker, I have two SPDT relays hooked up so the "single-pole" pins are connected to either side of the tracker motor.  The two "throw-pins" on each relay are hooked up to V+ and V-, allowing me to run the motor in forward, reverse, and stop modes.  See Figure 3 below.  The default state is V- hooked to both sides of the motor, causing the motor to draw no current and therefore not move.  To move the motor forward, simply activate Relay A and now the motor has V+ on the top and V- on the bottom.  For reverse, activate Relay B and now the motor has V- on top and V+ on the bottom.  Simple, easy, and only requires two output pins from the PIC to activate the two transistors which power the relays.

Figure 3

Development Status: The prototype is currently in use and working well.  I figure I'll let it run for a month or two to make sure there are no bugs, then maybe try to put together and sell a kit for people to use.  Who knows, we'll see.  The parts required are cheap, the circuit is pretty simple, it's easy to calibrate- so I'm pretty happy with the results of this project.

Opinion (PICs and Stamp IIs)

Here are my opinions about PICs and Stamp IIs, note that my exposure to the subject is limited to time since Nov 2001, so take this as you will. It seems to me that the Basic Stamp II is the best microcontroller for most (but not all) prototypes, but that since the PIC is FAR cheaper ($5-7 versus $50), anything you want to manufacture must be done with a PIC.  I say that the Stamp II is best for most but not all prototypes because the Stamp II requires only your computer to program and debug it while it is in the target circuit, also because it is natively programmed in Basic which makes it very quick to get a prototype quality program running.  The exception is when even a prototype requires that processor speed must be maximized, and code optimized, in which case the PIC can be made to run faster and on a mix of C and assembly code which is optimized for your circuit- or if you need to use floating point numbers which the Stamp II does not support, then you must use a PIC or go to the trouble of interfacing the Stamp II with a floating point chip.  Also, in order to even program your PIC you must buy or build a programmer for it, and for anything but assembly code you need to buy a compiler, and for debugging the PIC in-circuit you must buy or build an in-circuit debugger- some of these things can cost a couple hundred bucks, kind of a barrier if you're just a hobbyist making a gizmo for fun.  I chose to build the programmer and create an in-circuit debugger module in software using my computer's serial port (not as good as the paid-for debuggers I'm sure, but it was my idea and fast to build and cheap, so I like it).  Again, I've only been at the microcontroller thing since November so take my opinion at that value.  :-)

Glossary

ADC- acronym for analog-to-digital converter.  This type of device takes a voltage and converts it to a digital value on its internal scale.  For example, suppose the ADC is setup to measure a voltage from 0-5 volts DC and it uses an 8-bit scale- then the digital value of 0 would be 0 volts and 255 would represent 5 volts.  This digital representation can be extracted from the ADC typically by a parallel or serial connection.

flex sensor- The flex sensor is a resistor whose resistance changes based on the amount that the sensor is bent over.  The one I used had a nominal resistance of 10K ohms, meaning that unflexed it was a 10K resistor.

microcontroller- a microcontroller is a chip similar to the CPU in your computer, however it is intended to be part of a circuit to do something other than run a computer.  You setup this chip to read some information in on a few of its pins, run a program that you have written, and then use some other pins as outputs.  Microchip is a company which manufactures microcontrollers called PICs, you can read more about microcontrollers and PICs specifically at their site.

pitot tube- a tube with a pressure sensor at one end, open on the other.  The open end is placed facing into the air  going past an airplane.  Combined with another pressure sensor, the difference between the two can be used to gauge the airspeed of the plane.  Temperature and perhaps humidity (not sure about humidity) enter into the equation somehow.

shunt- a shunt is simply a resistor with a very low known resistance, typically able to handle a high amount of amperage.  By measuring the voltage across a shunt you can determine the current flowing flowing through and since the resistance is very low the power loss is negligible.

SPDT relay- a relay in which pin C gets switched between being connected with pin A or B.  If you connect A and B to V+ and V- respectively, then the relay allows you to put V+ and V- on pin C.

thermistor- a thermistor is a device whose resistance varies with temperature.  This resistance is known for a set of temperatures, and typically a given thermistor will come with a table detailing the resistance values for a set of temperatures.  Resistance/temperature pairs can also be calculated by a formula if you know a parameter or two about the thermistor (I'm sorry, I can't recall the name of the formula).

translations