Introduction: IOT123 - SOLAR TRACKER - CONTROLLER
This is an extension of the Instructable
IOT123 - SOLAR TRACKER - TILT/PAN, PANEL FRAME, LDR MOUNTS RIG. Here we concentrate on the controller of the servos, and sensors of the sun's position. It is important to point out that this design assumes 2 MCUs will be employed: one (3.3V 8mHz Arduino Pro Mini) for the solar tracker, and one independent MCU for your sensors/actors.
This is Version 0.3.
Rather than publish all the projects after complete satisfaction, I will practice continuous integration and deliver something more often, modifying what I have delivered as I need. I will write another instructable for the battery charger, _when_ the optimization of the controller software/hardware is complete. I will point out where the optimizations are needed as we step through this.
Part of the reason for this approach is client feedback. If you guys see a need or have a better approach, please comment, but keep in mind I cannot deliver everything and possibly not to a time-frame that suits you. As these explanations seem less relevant they will be deleted from this article.
What this includes:
- Use the LDRs from the original Instructable to sense the suns approximate location.
- Move the servos to face the sun.
- Options for the sensitivity of the movements.
- Options for the step size when moving to the sun.
- Options for the angular constraints used on the servos.
- Options for the delays of the movements.
I2C interface for setting/getting values between MCUs.
- Deep sleep between movements.
What this does not include (and will be addressed as time permits):
- Only using power during daylight hours.
- Remembering the dawn position and going there at dusk shutdown.
- Removing the regulator from the MCU.
- Disabling the LED(s) on the MCU.
- Rerouting the power through VCC rather than RAW.
- Providing workarounds for flashing without regulated power from the USB to Serial TTL converter.
- Battery voltage monitor.
Dec 20, 2017 V0.1 CODE
- Initial version tracks light source, always on, no charging
Jan 7, 2018 V0.2 CODE
- HARDWARE CHANGES
- Add I2C pins
- Add switch to servo GNDs
- Printed Label on controller box fascia
- SOFTWARE CHANGES
Read configuration from EEPROM
I2C bus support as a slave to another MCU (3.3V)
Set configuration via I2C
Set Enabled via I2C
Get configuration via I2C
Get runtime properties via I2C (currently Enabled, and Current Light Intensity)
Remove serial logging (it affected I2C values)
Jan 19, 2018 V0.3 CODE
- Label updated. Switch is now used to choose either CONFIG or TRACK mode
- I2C only used for configuration
- Controller waits 5 seconds before initializing tracking, allows for moving hands
- To use I2C configuration, SPDT must be on CONFIG as unit boots
- In between tracking movement, unit is in deep sleep mode for configuration value SLEEP MINUTES (default 20 minutes).
Step 1: Materials and Tools
There is now a full Bill of Materials and Sources list.
- 3D printed parts.
- Arduino Pro Mini 3.3V 8mHz
- 1 of 4x6cm Double Side Prototype PCB Universal Printed Circuit Board (to be cut in half)
- 1 off 40P male header (to be cut to size).
- 1 off 40P female header (to be cut to size).
- 4 off 10K 1/4W restistors.
- Hookup wire.
- Solder and Iron.
- 20 off 4G x 6mm stainless pan head self tapping screws.
- 4 off 4G x 6mm stainless countersunk self tapping screws.
1 off 3.7V LiPo battery and holder (terminating in 2P dupont connectors).
1 off 2P male right angle header
1 off SPDT switch 3 pin 2.54mm pitch
Strong Cyanoacrylate glue
Dupont connectors female 1P header (1 off blue, 1 off green).
Step 2: Assembling the Circuit
The circuit currently does not have the Voltage Divider Circuit (volt meter).
- Cut the 4x6cm Double Side Prototype PCB Universal Printed Circuit Board in half across the long axis.
- Cut the 40P male header into pieces:
- 2 off 12P
- 3 off 3P
- 6 off 2P.
- 2 off 12P
- 1 off 6P
On the topside of the Arduino fix the 2P right angle female header int #29 and #30 then solder.
Step 3: Flashing the MCU
The Arduino Pro Mini is conveniently flashed using a FTDI232 USB to TTL converter using the 6P female header. See the photo above for the alignment of the 2 boards.
The lowpower library (attached and https://github.com/rocketscream/Low-Power) needs to be installed.
Once the Arduino Pro Mini + PCB is installed in the casing it can still be flashed as the header pins are exposed. Just disconnect the Controller Unit from the Panel Frame exposing the header.
Step 4: Assembling the Circuit Casing
- Ensure the Ardiuno Pro Mini is inserted into the headers on the PCB.
- Insert SOLAR TRACKER controller box base into SOLAR TRACKER controller box walls and affix with 2 off 4G x 6mm stainless countersunk self tapping screws.
- Insert Ardiuno Pro Mini + PCB with 6P Header slotting into the void in SOLAR TRACKER controller box base.
- Insert SOLAR TRACKER controller box lid into SOLAR TRACKER controller box walls and affix with 2 off 4G x 6mm stainless countersunk self tapping screws.
- Affix assembly above to the base of the Panel Frame with 4 off 4G x 6mm stainless countersunk self tapping screws.
Step 5: Connecting the Rig Leads to the Controller
The pertinent connections ready from the previous Instructable, are 4 off 2P LDR connections and 2 off 3P connections from the servos. What is temporary until the recharging is ready is the battery. Use a 3.7V LiPo that terminates in a 2P DuPont connection for now.
- Insert the LDR connections (no polarity) from top:
- Top Right
- Top Left
- Bottom Right
- Bottom Left
Step 6: Testing the Controller
As stated before, the software has not been optimized for Solar Charging workflow. It can be tested and tweaked using natural (sun) and unnatural light sources though.
To test the tracking in a controlled environment it may be convenient to set the SLEEP MINUTES to a lower value (see next step).
Step 7: Configuring Via I2C Using Console Input
This explains configuring the controller via a second MCU, entering settings into a console window.
- Upload the following script onto a D1M WIFI BLOCK (or Wemos D1 Mini).
- Disconnect USB from PC
-ve (Controller) => GND (D1M)
+ve (Controller) => 3V3 (D1M)
SCL (Controller) => D1 (D1M)
SDA (Controller) => D2 (D1M)
Turn the SPDT switch to CONFIG
Connect USB to PC
From the Arduino IDE start a console window with the correct COM Port
Make sure "Newline" and "9600 baud" are selected
The commands get entered into the Send Textbox followed by the Enter key
The commands are in the format Character byte byte
If the second byte (third segment) is not included 0 (zero) is sent by the script
Be careful using serial input; review what you have entered prior to hitting the "Enter" key. If you are locked out (for example changing the I2C address to a value you have forgotten) you will need to flash the controller firmware again.
The supported variations in the command first character are:
- E (Enable servo tracking) useful for stopping movement during configuration. This is input using: E 0
- D (Disable servo tracking) useful to start automatic tracking if not rebooting the device. This is input using: D 0
- G (Get configuration value) reads values from EEPROM and IN-MEMORY: This is input using: G (index is valid byte values 0 - 13 and 15)
- S (Set EEPROM value) sets values to EEPROM which are available after reboots. This is input using: S (index is valid byte values 0 - 13, value is valid byte values and vary per property)
The code is the point of truth for the indexes but the following is used for a guide for valid values/comments:
- I2C ADDRESS 0 - controller slave address, the master needs this to communicate with the controller (default 10)
- MINIMUM VERTICAL ANGLE 1 - angle vertical servo lower limit (default 10, range 0 - 180)
- MAXIMUM VERTICAL ANGLE 2 - angle vertical servo upper limit (default 170, range 0 - 180)
- SENSITIVITY VERTICAL LDR 3 - Vertical LDR reading margin (default 20, range 0 - 1024)
- VERTICAL ANGLE STEP 4 - angle vertical servo steps on each adjustment (default 5, range 1 - 20)
- MINIMUM HORIZONTAL ANGLE 5 - angle horizontal servo lower limit (default 10, range 0 - 180)
- MAXIMUM HORIZONTAL ANGLE 6 - angle horizontal servo upper limit (default 170, range 0 - 180)
- SENSITIVITY HORIZONTAL LDR 7 - Horizontal LDR reading margin (default 20, range 0 - 1024)
- HORIZONTAL ANGLE STEP 8 - angle horizontal servo steps on each adjustment (default 5, range 1 - 20)
- SLEEP MINUTES 9 - the approximate sleep period between tracking (default 20, range 1 - 255)
- VERTICAL DAWN ANGLE 10 - FUTURE USE - the vertical angle to return to when the sun goes down
- HORIZONTAL DAWN ANGLE 11 - FUTURE USE - the horizontal angle to return to when the sun goes down
- DAWN INTENSITY 12 - FUTURE USE - the minimum average of all the LDRs that triggers a start of daily sun tracking
- DUSK INTENSITY 13 - FUTURE USE - the minimum average of all the LDRs that triggers a end of daily sun tracking
- END OF EEPROM VALUES MARKER 14 - VALUE NOT USED
- CURRENT INTENSITY 15 - the current average percentage of the light intensity
- END OF IN-MEMORY VALUES MARKER 16 - VALUE NOT USED.
Step 8: Next Steps
Check back periodically to check for changes in software/hardware.
Modify the software/hardware to your requirements.
Comment on any requests/optimizations.