Intro: Internet Enabled Solar Tracker
This is a Solar Tracker. A full size, cloud connected, smartphone accessible Solar Tracker built mainly from 2x4s and plywood, employing wooden peg gears, recycled curtain poles, nuts, bolts and threaded rod. The solar tracker uses a home built electronic controller incorporating WiFi, stepper motor drives, accelerometer and magnetometer. The tracker was designed to drive a full size 90W panel in azimuth and elevation. The gears driving the tracker are wooden peg gears commonly used in the 16th century. The gears were designed using modern 3D CAD (Solidworks). Connecting the wooden peg gears to the cloud just seemed like the right thing to do. This is not a waterproof design – you will need to consider modifications to waterproof your derivative design.
The project includes mechanical mechanisms, web application, free/green solar energy, firmware, basic electronics, a microcontroller, accelerometer/ magnetometer, the Internet of Things, WiFi, 3D Modeling, CNC machining, re-use and basic woodworking. The Internet Of Things was enabled by the innovative Electric Imp - http://www.electricimp.com
The need for solar tracking is well documented in the available internet literature and scientific journals so there is no need for me to repeat it here. There are many arguments for and against, but efficiency gains of up to 30% versus static installation make solar tracking attractive. You just need to make sure that your motive power needs are much less than the potential efficiency gain. The additional cost of a tracking solution is added to the overall cost of a solar system which increases the time to a positive ROI. But tracking does not need to be expensive – at least not for the home hobbyist with a small number of solar panels. The tracking accuracy requirements are not that high either. Using a micro-controller to control the tracking made it easy to control the tracking power losses by having the system operate in a low power mode for as long as possible, with only an occasional high power spurt to turn the motors a small amount. There are other ways to do solar tracking (optical sensors connected to simple circuits for example - "light followers"), but microcontrollers create opportunities for feature creep and you will learned a whole lot too. And learning is key.
Here's a short video to show the completed project in action:
Let's get started shall we?
Step 1: Overview
The major system components identified in the block diagram:
- 90 Watt solar Panel
- Two axis motion platform constructed from 2x4’s complete with wooden peg gears and re-used curtain rod/pole.
- Custom electronics – Electric Imp connected to stepper drivers, IO Expander and 6 Axis MEMS accelerometer/magnetometer
- Rechargeable battery – retired unit from my motorcycle as it is no longer capable of turning the engine over.
- Solar Charge Controller – cheap unit from ebay to make sure the battery doesn’t overcharge.
- Smartphone or web browser – monitoring status and remote control. This is a non-essential part of the system done purely for a learning experience to see what it takes to connect a phone to a remote device. (gotta remember to hide the URL so that I don’t have too many people trying to control the panel!)
The tracker circuit includes a tilt compensated compass - the math was coded from an application note. The chip has 3 axis magnetic output and 3 axis accelerometer output. The magnetic output tells the system the azimuth angle and the accelerometer tells the system the the inclination with respect to gravity. The GPS location is hardcoded in the firmware (future will have this set by smartphone via the web). The firmware determines, based on the time of day and geographic co-ordinates, what the sun angle is with a Sun Angle algorithm ported to the Electric Imp Squirrel language from C++ (discussed in later steps). Firmware drives the azimuth and elevation motors to the Sun Angles based on feedback from the mag/accel.
This whole thing could be done a lot more simply, but I was intrigued by the Internet Of Things made possible by the Electric Imp. Rather than just reading web articles to get at best a superficial understanding, I found a way to try out the technology with an overkill solution to a common problem. Most solutions on the market today are "light followers". They control motors in response to the intensity of light to maximize incident sunlight on the panel. These work well, are low cost and are really all you need. But if you go that route, you will miss a learning opportunity on the electronics/firmware/web/IoT development side of things. This is some of what you'll learn::
1. ASP.NET programming model for web based applications. This is the server side code that the smartphone connects to, to see the status of the system, or to drive inputs to the controller for manual control of azimuth and elevation for debugging purposes.
2. AJAX which allows a web page to update without server page reload. Allows a web page to dynamically query server data directly and update the regions of the page without page reload. This is how the monitoring data is updated.
3. SQL Server work on the back end. The data from the Electric Imp is logged in a SQL Server database.
4. JQUERY Mobile - great open source library that simplifies working with the Web page Document Object Model. Just scratching the surface of it for this application but it has taken the web by storm. It is a great way to develop Smartphone HTML5 "apps".
5. HTML5 capabilities and the relation to potential hardware independent phone apps. Bumped into a number of apps that will take the Web app and turn it into a traditional phone store application. Some are free until you reach 10000 downloads... yeah right!
6. The Internet Of Things model and what companies like Electric Imp and COSM are doing to make this a reality even for low budget hackers like me.
7. Appreciation of cloud based services and the power of having services provided by the cloud. The electric imp is fully cloud based.... your firmware lives in the cloud and is downloaded when your device connects to the internet.
8. Algorithms for tilt compensating a compass. Ultimately I implemented an app note but it required a fair amount of research.
9. Algorithms for sun angle prediction. Ported an Open Source implementation to the Electric Imp. Had no idea that sun angle prediction was such a complex problem. I don't fully understand the algorithm but tip my hat to anyone who does! IJW!
There is plenty more to learn with this project but I had to cap the list somewhere!
I think the easiest way to tackle the documentation is to walk you through the building of the tracking base, then the electronics/firmware and finally the web app. The electronics and motion platform are independent components of the system. The tracker electronic module was designed to be a reusable component. The tracker base was designed to demonstrate peg gears and levers in another shameless attempt at stimulating my kids’ minds with engineering.
Step 2: Stuff You'll Need for the Base
Supplies you will need to make the base
- Bearings 3/8"– you will need seven 3/8 ID by 7/8 OD roller bearings. Sealed bearings are better at keeping moisture and dust out. Ultimate bearing for all-weather operation is a plastic sleeve bearing or roller bearing. I used cheap steel bearings that may not stand up to extended outdoor use without water proofing but I already had them in my box of stuff from an old CNC machine build so I used what I had. I used 7 of them. VXB, Electronic Goldmine and Use-Enco.com are good sources for low cost bearings. Electronic Goldmine has 3/8” ID bearings for under $1 each. VXB has plastic and ceramic bearings as well.
- Bearings 3/4" - You will need two ¾” ID by 1 ¼” OD bearing for stabilizing the azimuth pole (curtain pole OD must be 3/4" for this project)
- 2x4 Pine Studs – Two of them will be plenty. Construction lumber is a sustainable and renewable resource.
- ¾” Plywood – I used birch from a furniture project I completed a long time ago. You will need enough to cut out two x 10” gears, two x 2.5” gears and some collar clamps. A 2ft by 2ft sheet will be plenty
- Pocket Hole screws – 2 ½ screws for joining 2x4s and 1 ¼” for joining thinner wood
- Piece of plastic – Acetyl/Acetyl/Nylon at least ¾” thick. A 2”x2”x1” piece will work nicely. This will be used to make the nut that controls the elevation.
- Strips of 1.5” by 0.75” wood – plywood or anything else you have handy. Sustainable hardwood such as Poplar is good. This is used to stabilize the lead screw (fancy name for precision threaded rod) that will carry the elevation panel load.
- More strips of the same to make the support frame for the solar panel itself.
- Elmer Max wood glue
Tools that will help
- Measuring tape
- Miter Saw. You can cut everything by hand but this will take a long time.
- Angle grinder for cutting threaded rod and curtain pole to length. A hacksaw will work as well - anything that cuts steel will be fine
- Electric Drill for making pocket holes - high speed drill works better for this than a battery powered drill which tends to rotate at lower RPM
- Battery Powered drill/Electric screwdriver to fasten the pockets screws - makes the job go a lot faster than doing this with a manual driver
- 3/8" Tap drill and 3/8-13 tap for the elevation Acetyl nut that you will need to make
- 10 x 3/8" nuts and washers for assembly
- Drill press if you have one - helps to keep holes perpendicular.
- 1-1/2" hole saw or larger. Anything up to 3" will work fine. This will be used to make the collar clamps that keep the pole clamped to the gear
- Hammer - for various alignment tasks and for securing the pegs into the holes on the gears
- Hacksaw or similar thin bladed saw to slit the collar clamps
Step 3: Making Gears
The gear ratio for the system is 4:1 which results in large gears. The ratio for gears is determined by the relative diameters or tooth counts such that the following equation is satisfied
D1/TC1 = D2/TC2
Where D = Diameter and TC = Tooth Count
The diameters we are referring to here are the diameters to the center of the peg circle on each gear as shown in the pictures.
The tooth count determines the spacing between the pegs – aka the pitch of the gear. This is limited by the diameter of the pegs and the amount of backlash between gears that you can tolerate. I decided on a final tooth count of 48 for the large gear and 12 for the small gear. The minimum spacing between teeth determines the tooth limit.
Minimum spacing = 2* peg diameter. This is the chord length. Practically you need to allow for more than this because you only want the driving peg to be in contact with one receiving peg. The driving peg needs to be free to slide down between pegs.
Arc Length Spacing = ( PI * Gear Circle Diameter / TC ) > 2* Peg Diameter
Spacing = 0.641” 2*Peg Diameter = 0.5”
NOTE: For this circle I am making the approximation that the Arc Length ~ Chord Length
The peg circle diameter of the small gear is 2.45” and the peg circle diameter of the large one is 9.8”. The pegs are 0.25” hardwood dowel pins 1.25” long. You can find the pegs at Lowes or Home Depot. You can make the gears using a jig-saw/scroll saw/router and a drill but I chose to use CNC. It’s a lot quicker and makes the gears very accurately. The gears where modeled using Solidworks, then drawings were created and exported as DXF. The DXF file was imported into CamBam which generated the g-code. I have described this overall process in this instructable https://www.instructables.com/id/Tetris-Puzzle/step3/Data-manipulation/ so won’t repeat it here. The Solidworks files are attached to this step. The CamBam files are attached as well - remove the .pdf from the filename - these are not PDF files but a work around for the INstructables importer :-)
The gears are the most complicated part of the build and need to be reasonably precise to have consistent tooth engagement. A total of 4 gears – two of each type – are needed. The larger gear has two different hub sizes. One is 0.375” and the other is 0.75”
I adjusted the CNC program in Cam Bam to cut each type to the correct overall size.
Here's a video of the larger gear being cut on the CNC.
Once the gears are cut using your preferred method, the pegs get hammered into place. I used a 0.75” thick piece of scrap to gauge the height of the pin to make sure all pins get hammered in to the same depth. On the second set of gears I set the hole depth to 0.5” in the plywood to simplify height-setting the pegs.
I made a quick mockup with two pieces of 2x4 and some 3/8” bolts and 3/8” rod to test the engagement. The gears will bind if not properly aligned and the engagement depth of the small gear relative to the large gear in the vertical axis needs to be controlled in order to have smooth rotation. Overall this test worked out well so it was on to figuring out the rest of the structure.
Step 4: Base - Bearing Pockets
The base is made from 2x4 construction lumber. Cut 3 pieces 20” long and 3 pieces 5” long. Two of the 5” pieces will become motor mounting plates which will support the motors and the drive shafts of the small gears. First step is to drill a small pilot hole 3 ½” up from one end. Use a 1/16” drill bit. The pilot hole needs to be made carefully as it will define the axis for the drive shaft of the small gear. You want this to be close to perpendicular to the surface as possible.
Next, use the 5/8” Forstner or spade bit to mill a pocket into the one face to create a bearing pocket. The bearing is about ½” thick so the pocket should be about the same depth. A little more or less won’t hurt. Now repeat the process on the opposite side of the wood for the other bearing. You will end up with aligned bearings one on each side of the wood. Now you can enlarge the pilot hole so that the shaft can pass though. The shaft in our case will be threaded rod 0.375” so a 1/2” hole will provide good clearance. In addition I used a step drill-bit to chamfer the edge of the hole to make sure that the inner bearing race would not rub on the wood and generate extra friction.
In total there are two blocks that need to be made and each block has two bearings to guide the drive shaft for the small gear. To mount the blocks to the horizontal support plates, we use Kreg pocket holes. One pocket hole on either side of the shaft clearance hole will be enough. Set the Kreg Jig for 1.5” thick wood. after making the holes, screw the motor support plates to one of the 20” horizontal pieces so that the face is 13.5” away from one end. You need to allow for the 10” gear as well as the 1.5” thickness of the small gear as well as nuts and washers that will secure the small gear to its drive shaft later.
Then place the large gear with the 3/8” hole so that the edge of the gear is about 0.25” away from the edge of the 20” piece (see pictures) and use the gear as a drill guide to make a 3/8” shallow starter hole through the 20” piece. All we need to do at this stage is mark where a bearing pocket is needed.
You will be making bearing pockets on all 3 horizontal plates. It is very important that these bearing pockets line up with each other. The bearings need to be concentric to each other. The easiest way to ensure this is to stack the three plates together and drill a thin guide hole through all the plates before you start. It is unlikely that you will have a 1/16” drill bit long enough to go through 4.5” (the drill bit would wander anyway due to the drilling stress) so you will most likely need to drill through one and just start into the next. Then remove the first plate and use the mark to start through the second plate until you are through the second plate and starting into the 3rd. Then remove the second plate and drill the pilot hole for the third all the way through. I made my holes using measurements, but this has the potential for error. Drilling a pilot hole will simplify things and ensure alignment through elimination of measurement error.
Then transfer the wood to a drill press and create a pocket for a 3/8” ID bearing using the 5/8” forstner bit. You can use a hand drill but be careful to keep the drill as close to perpendicular as you can. This bearing will be used as a thrust and roller bearing for the elevation axis. In general it is not recommended to use a roller bearing for thrust applications but the load is so light that this is a non-issue for this design and saves having to use more expensive combination bearings or additional thrust bearings.
The next horizontal plate will need a larger bearing pocket on the one side to support the curtain rod, and the 0.375” ID bearing pocket on the opposite side to support the threaded rod which passes through the middle of the curtain rod. This plate will carry the larger 0.75” bearing which has a 1.5” OD. I didn’t have a drill bit large enough for this so programmed the CNC to cut the pocket. A 1.5” spade bit will work just fine for this application. The opposite side pocket can be cut with the 5/8” Forstner or spade bit.
Step 5: Base - Collar Clamps
The curtain rod is secured to the gear using a wooden collar clamp cut out of the 0.75” plywood. The fabrication of the clamp starts by cutting a 2” disk from the plywood with a 2” hole saw. If you have a larger hole saw, (say 3”) use that. The smaller clamp tends to split. Once you have cut the disk out, clamp it to your work surface and use a 0.75” spade or Forstner bit to cut a through hole. The curtain rod will pass through this hole and then be clamped to the gear. Using a hacksaw, cut a slit into the clamp. Then drill a hole for the clamping screw. I used a Kreg screw so the pilot hole was made with a 1/16” bit.
After drilling the pilot hole, I used the Kreg drill bit to counter bore the hole so that there is a flat surface for the shoulder of the clamping screw. To prevent the wood from splitting when the clamping screw is screwed in, use a single Kreg screw to hold the plywood together first, before fastening the clamping screw. Once the clamp is tight, use 3 additional 1 ¼” Kreg screws to secure the clamp to the gear as shown. The large bearing is a tight fit onto the curtain rod – use a hammer to get it on far enough so that it is held perpendicular.
Step 6: 2x4 Nema 23 Stepper Mounts
The azimuth and elevation are driven using stepper motors. To mount the stepper motors, mounting blocks were fabricated using off-cuts from the 2x4 construction studs. You will need two blocks. The blocks are 3.5” square.
First step is to cut the blocks to size. Measure 3.5” in from an end and make your cut. The width of a 2x4 is 3.5” so you should end up with a 3.5” square block. Mark the center of the block by drawing in the diagonals on the surface. The largest precision bit I had was a 35mm Forstner, so I made the large holes with that. Then I cut a small lip with the 1.5” spade but to the final size of the boss on the stepper motor. You could cut the hole completely with the spade bit but I don’t like the way they chew out wood. The holes are not very precise and clean with a spade bit.
Then cross drill smaller holes in from each this side to turn the block into Swiss cheese. I used the 5/8” forstner bit for this. These holes will allow access to the motor couplings during assembly. The motor is clamped to the mouting block using the long 2 ½” Kreg screws. To make the holes for the mounting screws, place the motor in position and use the mounting holes as a drill guide. I used a 1/16” drill for the pilot holes and then enlarged them to 1/8” later to allow for a little free play during installation.
For drive shafts, a 4 1/8” length of 3/8” threaded rod is used. This is cut from the end of the 6ft rod. You need 2 of these. The shaft couplings are from a previous CNC machine build. They were drilled out to fit the 3/8” rod on one side. The other side matched the 6mm motor shaft diameter perfectly. The couplings I used are very nice, high tech flexible beam couplings, but really not necessary for a project like this. I just used what I had. You could use flexible hose and hose clamps as an alternative for this coupling.
Step 7: Base Assembly
After reviewing the photographs for this project I realized that I had not taken enough pictures of the assembly process. Hopefully it will still be clear from the pictures I do have. The assembly starts by screwing together the motor vertical supports and the bottom and upper horizontal 2x4 using 2 ½” Kreg screws.
Then the larger gears are installed. The threaded rod connects to the lower gear using a nut and washer above and below the gear to clamp the gear to the threaded shaft. The gear that has been clamped to the curtain rod slides over the threaded rod and the large bearing rests in the pocket made for it on the upper horizontal plate.
The small gears are connected to the threaded rod using a 3/8-13 not and washer on either side of the gear to clamp the gear to the shaft. I used Locktite to make sure that it doesn’t come loose. The small gear needs to be help in place and then the shaft run through it. It is not possible to get the small gear in place is you assemble it to the shaft first and then try and slide ot through the shaft support bearings. A third nut positions the shaft by determining how far out to hold the gear. This nut is also locktited in place. On the back side, the coupling is fastened to the threaded rod and keeps the bearings in place. A small amount of axial play is ok – don’t make the clamping force on the bearings too high – the system should spin freely.
Next, the motors are screwed in place using 2 ½” Kreg screws. That concludes the assembly with the parts we have made up to this point.
Step 8: The Top Plate and Goal Posts
This project was an example of figuring things out in the fly. I had a rough idea of what I wanted to do but as always left the details to the construction phase. I tend to think about and understand problems better when I start working on them. After much cogitating, I decided to add a top plate for overall support of the panel. This plate has a single pocket for a 0.75” ID bearing and is the final support for the azimuth axis. The vertical supports are 5” long and held in place using pocket hole joinery. I cut the pocket using the CNC. The critical thing here is to make sure that the hole is accurately aligned with the hole in the second horizontal plate so that the curtain pole will move freely. If there is misalignment, the movement will start binding.
The goal posts consist of a 36” long horizontal member and 2 x 12” long vertical supports. The middle of the horizontal member gets a ¾” hole. The two vertical uprights get ¾” holes near there ends. TO make sure of a low friction movement, a thrust washer was placed between the goal posts and the top support plate.
The goal posts are assembled using pocket hole joinery. Remember to set the Kreg jig for 1 ½” wood thickness and use 2 ½” pocket screws.
Step 9: Elevation Axis
The threaded rod will carry a portion of the panel weight depending on the elevation angle. To support the exposed threaded rod, a structure was created from 0.75 x 1.5” poplar. Pieces were cut to length using the mitre saw and assembled using pocket screws. A bearing pocket was drilled using the 5/8” forstener bit for both the top and bottom pieces to ensure smooth rotation.
Originally I had only planned on a single support at the top, but the weight of the panel deflected the threaded rod enough to cause contact with the curtain pole. A second bearing block was made for lower support. Note that the pocket holes are different for the 2 bearing blocks. The upper block has the pocket holes on the bearing pocket side and the lower block has the pocket holes on the opposite side to the bearing pocket. Otherwise the bit for driving the pocket screws won’t be able to fit in the space between the uprights so you won’t be able to fasten the screws with the standard pocket screw driver bit.
The elevation motion is caused by a nut riding up and down the exposed threaded rod. A custom Acetyl nut was made for this. I used Acetyl as it is a common plastic for this type of application. The wear on the threaded rod will be less than if a steel nut was used. Acetyl is easy to machine and cut with hand tools and I had a bunch left over after making nuts for my CNC machine.
The chop saw was used to cut a 1” wide by 2” long piece of Acetyl. Then a 3/8-13 hole was tapped into the Acetyl as shown in the pictures. A ¼” hole was made at the end of the nut for attachment to the elevation bar.
An eye bolt was screwed into the panel. Attaching the Acetyl nut to the eye bolt completed the elevation axis. I cut about 45 degree chamfers at the ends – no real functional need.
Step 10: Panel Mounting Frame
The panel mounting frame was made out of ¾” thick poplar that I had left over from a cabinet project. The vertical pieces are 1.5” wide and the horizontal cross piece is 3.5” wide.
The pieces are held together using pocket hole joinery. Make sure to set the Kreg jig to ¾” and use 1 ¼” fine thread Kreg screws. I added waterproof wood glue to the joints for extra stability. The horizontal support tube for the entire panel is an offcut of the curtain pole. The pole needs to be about 40” long to make it through the support uprights. The pole is held to the frame using ¾” electrical conduit clamps.
The panel is attached to the wooden frame using ¼-20 stainless hardware. The panel is then installed by holding it in place and sliding the curtain pole through the one vertical upright, through the conduit clamps and out the other side. The threaded rod also needs to be trimmed prior to this using a dremel/hacksaw/angle grinder. You can gauge the height by sliding the pole through the uprights without the panel and cut the rod about ½” shorter. You can cut it in place – no need to disassemble.
Step 11: Electronics and Motor Wiring
The controller for the system is driven by an Electric Imp. This is an amazing device that makes connecting projects to the Cloud really easy (well easy in hindsight – like everything else there is a bit of a learning curve!). You can find all the information you need to know about the Imp at www.electricimp.com
The Imp is wired to a number of breakout boards and modules. There are 2 stepper modules and electronic compass from Pololu, an IO Expander and Electric Imp carrier board from Sparkfun. I used a standard Vero board from Radioshack to make the circuit.
- A4988 Stepper Controller http://www.pololu.com/catalog/product/1182
- A4988 stepper motor driver carrier with voltage regulators http://www.pololu.com/catalog/product/1183
- LSM303DLM Breakout board https://www.sparkfun.com/products/10888
- Electric Imp https://www.sparkfun.com/products/11395
- Electric Imp carrier board https://www.sparkfun.com/products/11400
- SX1509 16 Channel I/O Expander https://www.sparkfun.com/products/11502
- 2 x Nema 23 stepper ( I used PK268 but anything with enough torque will work. I don't know how much torque is needed. These motors are most likely overkill but fits with the overall theme!)
You will need some hookup wire, a soldering Iron and solder for this. Alternately, you can lay out a PCB or use a breadboard.
The stepper motors are supplied with 12V from the battery. The electric imp carrier board has a built in voltage regulator that will take 12V directly which is convenient since the same battery can power the motors and the circuitry without additional components. Additionally, the one stepper driver has a built in regulator that will take 12V in and provide a regulated 5V and 3.3V out. I used this feature to make sure that the current drive capability of the Imp carrier board regulator was not exceeded.
To make the controller board, wire up as shown in the schematic. There is nothing tricky here. Due to the length of this instructable, I’m not going to cover stepper motor or general electronics theory. There are many sources on the web that will help get you started.
Step 12: The Firmware and Principles of Operation
One of the difficulties I had to overcome was driving a consistent pulse train for the stepper motors through the IOExpander using the Imp. Running a tight loop resulted in a very stable and smooth pulse train but if the number of steps the motor needs to move through is large taking more than a handful of seconds, the imp is not able to process the internet stack during this time and will at some point crash – they do warn about this on their web site so this is not a jab at Electric Imp – just a fact that you need to be aware of if you try to change things to get a smoother pulse train for the stepper motors. I had to use the Imp sleep functions which are not time accurate but still allow the generation of a pulse train that will move the motor the correct number of steps – just with a lot of jitter in the timing which does make the motors noisier. This is a small limitation of the Imp.
The system operates by calculating the azimuth and zenith angle of the sun based on the time of day. The algorithm for this was ported from a C++ implementation that is available here: http://www.psa.es/sdg/sunpos.htm
The algorithm is a simplification of available sun tracking algorithms, but even so appears to be pretty complex for the layman such as myself. I was able to test my ported algorithm output against other web calculators with good results so my confidence in the use of this algorithm are high. Insert more URLs
Once the sun position calculation is complete, the system checks to see what the current elevation and azimuth of the solar panel is, calculates the offset between the required sun angles and the panel position, and uses these offsets as inputs to the motor objects to drive this error to zero. This piece of measurement magic is accomplished using an LSM303 breakout board. This device consists of a 3-axis accelerometer and magnetometer in the same package. The implementation is a tilt compensated compass. This allows the use of a single chip to provide heading and tilt information of the panel. Since the PCB is attached to the panel to measure inclination of the panel, the magnetic heading needs to be compensated for tilt. The algorithm is an implementation of an ST Application note that you can find here: http://www.st.com/web/en/resource/technical/document/application_note/CD00269797.pdf
The algorithm works well for tilt angle 45 and lower so the circuit board was mounted at a roughly 45 degree angle to the panel so that when the panel is at the elevation extremes of 90 and 0, the tilt measured by the accelerometer is in the +/- 45 degree range.
If we consider that the power available from the solar panel will vary as a function of the cosine of the angle of incidence of the sun’s rays, we can tolerate a reasonable offset between the ideal azimuth and ideal zenith of the panel and the actual angles of the panel. For example at 5 degrees off azimuth from ideal, the available power is 99.6% of maximum. Given that the tilt compensated compass is only accurate to about 2 degrees, this is important to show that it should be easily possible to have high efficiency gains even with inaccurate sensing.
This also means that we can also significantly reduce the power needed for the tracking circuit by keeping the microprocessor and motor drive circuits in sleep mode for long periods of time. Given that the sun angle changes in azimuth at a rate of 15 degrees per hour, we can maintain a 5 degree worst case error at the end of our error adjustment time period (2 degrees due to magnetic compass inherent inaccuracy assuming additive, plus 3 degrees due to sun movement) by waking up every 12 minutes and adjusting the error offsets to zero.
The code is attached for your use.
Step 13: Configuring the Electric Imp for HTTP Communication
In order for you to connect to the Imp through HTTP, you need to configure an HTTP IN node. From the Add Node button on the Planner, click Add to add an HTTP In node. This is the node that will receive messages from the smartphone. The smartphone in this application connects to a webserver. That webserver then sends messages via HTTP Post to the URL specified in the planner. Each node will have a specific URL.
The Imp also logs the solar data to a SQL Server database. The Smartphone periodically queries the database to receive updates on status. This query is also done via a aspx page on the Web Server because the database is only accesible to pages served by the server for security purposes. To add a node for HTTP Request, click the Add button next to HTTP Request. Add the URL that will receive the data from your Imp firmware through it's output port.
The Firmware connects to these HTTP In and HTTP Request nodes through input and output ports defined in the firmware. For the Solar Tracker, we use
imp.configure("CompassAccelSolar", [HtmlCommands], [compassPort,headingPort,rollPort,pitchPort,sunAzimuthPort,sunZenithPort]);
HtmlCommands - This is the Input port that receives commands via HTTP
compassPort - this is the output port used to log data to sql server.
The remainder of the output ports are for logging to COSM/Xitely which I haven't hooked up yet... maybe next design iteration.
Reading the code presented in the previous step will help with understanding. This topic on it's own is worthy of a Instructable! Electric Imp is also about to change the way that HTTP communication with your target device is done in future with the use of Agents, so this interface as described here will then become legacy. Just FYI.
Step 14: Web App and Smartphone Interface
The ability to control and monitor the status of the solar panel was a key design goal. To be clear, you do not need this functionality for the tracker to work. It is additional functionality that allows you to monitor the status of the tracker remotely.
To use the code, you will need a Web Server set up running IIS Version 7 or later. You can run the WebServer on your own PC or use an external hosting service like http://1and1.com (I use 1and1). If you use your own web server hosted at home, you will need to register with a Dynamic DNS service so that your PC is locatable from the Imp server.
The interface to the panel is created by Index.html. This web page uses JQuery Mobile http://jquerymobile.com/ to create the look and feel of a native iPhone app. The only limitation with JQuery Mobile is that you can’t access smartphone specific hardware such as the accelerometer and GPS. There are 3rd party platforms that will allow you to bridge this gap such as Phonegap http://phonegap.com/
The nice thing about Phonegap is that you can have your code compiled for iOS and Android platforms. If you avoid dependencies on phone hardware such as I have done for this app, you don’t need thse 3rd party platforms and your code will run on ANY Smartphone, Tablet or PC with a suitably up to date browser. Brower must support HTML5.
The Solar Tracker application doesn’t need phone hardware, so JQuery Mobile is the only dependency.
How it works
The Index.html file has two main internal “pages”
- Status monitoring page – periodically queries the current hardware values from the SQL database so that you can see the system status.
- Motion control page – allows you to drive the panel motors to a specific elevation and azimuth. You could for example send the panel to a storm-safe position.
- Settings page - this was not implemented but in future will contain specific parameters that can be stored in the Imp like Lat and Lon.
The status monitoring page periodically (once every 2 seconds for development – will be slowed down later) queries the Web Server for data which is displayed in a grid-like fashion. This data is provided from the SQL Server (also hosted by 1and1.com). The interface is through web page TrackerStatus.aspx which queries the data from the SQL Server database and returns the response to the AJAX query made by Index.html running on the Smartphone. Index.html then updates the display of with the latest values.
To control the motion of the panel manually, the Motion control page makes an AJAX call to the Services.Aspx page. This page interprets the call and passes a JSON object to the Electric Imp “HTTP In” node hosted by the Electric Imp Server. The “HTTP In” node connects to the firmware through an Input Port called HTMLCommands. The Squirrel code supporting this port extracts the target angle information and uses Tracker objects in the firmware to drive the motors to the required manual position.
The firmware is able to update the SQL Server database by sending data to the HTTP Request Node. This node is configured to pass the data to DatabaseUpdater.aspx which writes the information into the database. All the status information is written to SQL using DatabaseUpdater.aspx.
You can copy the supplied files to your web site target directory. To summarize:
- Index.html – file loaded by the smartphone browser. Provides the UI for the tracking system and the UI for manual control of the tracking angles if needed
- Services.apsx – ASP.Net file that receives manual tracking angles from Index.html. Provides these angles to the Imp HTTP In node, which routes them to the firmware via HTTP. This file may seem redundant but it avoids problems with Cross Origin Resource Sharing. Browsers are in general not happy making AJAX calls to a domain other than the domain that served up the page they are currently using. For example, MyWebServ.com served up the index.html file. Index.html is using AJAX to make a request to electricimp.com…. browser freaks out. Call sometimes gets made but an error is returned. Making all the calls into the same web server avoids this. I’m sure there are other ways but I don’t know them!
- TrackerStatus.aspx – ASP.Net file that interrogates the database on request for the latest status data from the Imp. Data is requested by index.html AJAX call. TrackerStatus.aspx queries the database, packages the result as a JSON string and returns the response to index.html
- DatabaseUpdater.aspx – Peridodically the firmware writes to it’s output port (CompassPort). The Imp planner is configured with an HTTP Request node that connects to CompassPort. When a data packet is received, the HTTP Request node will make a request to the target page with which it was configured. This page is DatabaseUpdater.aspx which writes the current status values into the database via a SQL UPDATE query.
You will need to configure your database connection string as well as your electric imp URL specifics. The attached file WebFiles.PDF contains all the source code for the web services. Rename the file to .pdf file to .zip and unzip.
Step 15: Conclusion
There are more tweaks and ideas that flooded in during the development of the system that I need to work on. Initially the base was built as a test platform for the electronics. A more robust base for harsh environment outdoor use is currently occupying some of my free thinking time. Laying out a PCB, waterproofing an enclosure and incorporating the solar charge controller into a single unit are also in the future plans.
Here's a video of the controller in action with manual control from an iPhone.
This was a blast to build and stretched my brain. I hope this Instructable motivates you to build one of your own!