Hydroponic – 4 Months Later

It has been 4 of months since the Arduino-based hydroponic control system has been in operation and I’ve since harvested arugula and lettuce. I’ve added a couple of columns to to grow cherry tomatoes. For the most part it has been a good experience.

I’ve finally added EC and pH measurement from Atlas Scientific  and programmed it using I2C rather than serial. I also added voltage isolation between the probe and the rest of circuitry to reduce changes of noise interference.  Data collected is via modbus over xbee to my SCADA host as before. The updated wiring includes the two extra sensors as shown below.

The spike in measurement resulted from adding more nutrient and pH down to the nutrient tank. More about that later.

New Development Environment

Most noteworthy, I migrated to using PlatformIO as the dev environment given that it supports multiple boards, has a command line interface, integrates nicely with the Atom editor and github.

Issues

1. Inconsistent distribution of flow. The drip lines where sitting at the top and some plants would not get enough water. Fix: added 2″ caps (orange in pic) ensuring proper alignment of drip line.
2. Water leaking to the floor. I could have done a better job in making the holes to host the net pots. When harvested, I would have to keep an empty net pot to avoid dripping of water. Fix: Replaced with 2″ Wye. It holds a 2″ net pot nicely. I could not find white wyes that did not cost and arm and a leg. I opted for the black drainage type.  The photo shows a trial test.
3. 3″ net pots to hold cherry tomatoes is throwaway. The holes where made into 4″ pipe and it caused all kinds of issues. Fix: Replace with TODO wyes.
4. Drain pump. The one I bought is too slow and noisy. Fix: I use a wet vac to drain the water. It is a lot faster and helps with cleaning the tank.
5. Level Sensor: The sensor got destroyed with the splashing of the nutrient mixture over time. Also, the readings on average were correct but I did not like the range in level during operation.  Fix: Removed and looking for different sensor.
6. Topping off nutrients is ok a the start but after a while, I just want to system to take care of it all. One has to add it over a period of time rather than in one shot. Otherwise, spikes in pH/EC occur. Fix: purchased nutrient containers  and some peristaltic pumps. With some TODO driver circuitry and code, managing nutrients should be mostly automated.

Exploration

The following plot represents nutrient temperature and growing chamber temperature. The nutrient temperature is on the low end of the range and I’m going to test to see if keeping the temperature around 21C (70F) impacts the growing cycle.

Next Steps

The fun stuff begins and it is machine vision. One to assess how well photosynthesis is occurring and the other is to measure growth.

Scope

After experimenting with LED plant lighting, I finally got to the point of building an Arduino based hydroponic controller and ready to start planting things. As usual, functional requirements frames the project and consist of the following:

•  Lighting control by On Hour/Minutes and Off Hour Minutes
• Circulation pump and Fan control via on time/off time
• Hand-Off-Auto for lighting and circulation pump
• Measure Mixture Temperature
• Measure Chamber temperature and humidity
• Drain pump
• Circulation Pump
• H2O Inlet valve
• pH and Electrical Conductivity
• LCD display of key parameters
• xbee connectivity since I have several of those lying around
• Nice to Have – CO2

P&ID

A simple P&ID of the system the building of the system from which the tag list was created along with the corresponding modbus addresses.

Device Communications

The system consists of a mash-up of several technologies which communicate over different protocols. I like I2C and 1Wire as it simplifies the wiring.

Control Panel

The control panel components came from Digi-Key  as they provide competitive pricing and quick delivery. Note I chose Phoenix terminal blocks for the cheap price and quality.  Enclosures ended up too expensive leading to the din rails, terminal blocks, etc. mounted on wood. It does the job and came out ok.

A simple food container houses the LCD/RTC and switch enclosure and the future EC/pH sensor electronics as this is where the I2C devices reside. Labeling is not the nicest but it is good enough for now. The xbee device is left hanging there for now as well.

Piping

Inspiration for the setup came from this site and a chat with the folks at Quick Grow. I was told that 2.5″ piping would be sufficient to grow lettuce and thus ended up using that size for the first phase. I left a space for future expansion for 3″ pipe for cherry tomatoes.

Note this was built in an un-sused shower space in the basement and the folks at Quick Grow stated that the white will reflect the light so no need for reflective material. I also purchased the LED lighting from them for both the growing chamber and seeding area to support the local business.

General Parts List

A partial parts list used for the project.

The Schedule 40 piping and connectors as well as the sharkbite products came from good old Home Depot.

Stripping wire and terminating them became quite easy with these tools

Software

There is a lot of libraries available to connect the various sensors. I also wrote my own to handle discrete inputs and outputs, timer outputs, Hand-Off-Auto, etc. This made things easier to maintain and can be found at https://github.com/chrapchp/IOLib and the main code at https://github.com/chrapchp/PlantLEDLighting/tree/hydroponics

Changes in switch values are detected and invoke a callback function. For example, the HOA class invokes a callback function passing the new switch state detected.

Median Filters

Noisy Liquid and CO2 levels was observed over time through the SCADA system. I exported the data in question and explored ways to deal with the extreme fluctuations. Note I did put an oscilloscope and the CO2 signal was clean. After some Excel plotting, I ended up with wanting a median filter with with a window size of 5. Fortunately, a library was written for it which saved me some time. The content of the signal on the left is the before filtering there is about 3000 samples in that image.

CO2

Nutrient Tank Level

Data Acquisition

The flow and CO2 use interrupts. Polling rates of the switch are set up at 500ms unless overridden. e.g.

Flow rates are calculated every 1second based on the pulses from the interrupt handler. The 1-wire and DHT-22 reading is performed every 5 seconds.

The ultrasonic level sensor was “calibrated” to read 100% at 100 L as well as the hi level switch.

Wiring

• Ultrasonic sensor – no special circuitry required to connect to the Arduino. Example here
• DHT-22 sensor – added a 10k resistor between vcc and signal. Example here
• 1Wire Temperature sensor -added 4.7k resistor between vcc and data
• Input and level switches – enabled internal pull-up resistor in Arduino.
• CO2 – no special circuitry required. Data sheet here
• Flow sensor – no special circuitry required. How-to here
• Added 1000uF electrolytic capacitor between 5v and DC ground handle potential inrush currents
• Added 100nF ceramic capacitor between 5V and DC ground to filter out high frequencies

Next Steps

Installing a camera to take time-lapsed photos of the plants in the growing chamber as well moving to a smaller fan rather than the larger 12″ one in place is on the radar. Creating  mobile friend UI on the SCADA system is also in the queue.

Arduino based Plant LED Lighting – Iteration 1

After years of procrastination, the itch to get into hydroponics needed attention. Before jumping headfirst into the unknown, a quick experiment to see how the plants responded to neopixel LED strips was in order. As such, I’ve put the MEAN stack exploration on hold.

Objective

Can the neopixel LED strips provide enough lighting to grow herbs and other leafy vegetables?

Putting it Together

The software is straight forward with the xbee operating using AT mode rather than API mode.  For now, I used modbus to communicate to Mango and for giggles VT-Scada. More on that in a future post as the IIoT speak I hear from certain vendors — not the two mentioned–make me cringe knowing what they have under the hood.

Software Feature List

• set time from host via modbus  or terminal console
• set lights on time via modbus or terminal console (default 18 hrs on)
• set lights off time via modbus or terminal console (default 6 hrs off)
• set duty cycle via modbus or terminal console
• set duty cycle period via via modbus or terminal console
• get temperature via via modbus or terminal console
• get soil moisture via via modbus or terminal console
• force the lights on or off via modbus or terminal console

Modbus was used as I already had a SCADA host running. It could have been xbee API or bluetooth. Having done both, this is relatively easy to refactor the code later.

The code can be found at https://github.com/chrapchp/PlantLEDLighting. Not the prettiest code yet it it does the job for this experiment.

Periodically changing the red/blue ratio aka duty cycle between 70-95% red with the remaining in blue light tainted the experiment. Regardless, it is logged in the SCADA/HMI host for further analysis.  Interestingly, the research around  LED-based plant lighting is growing along with plenty of do-it-yourselfers experimenting.

Lessons Learned

On the Mega front, the Chinese knock-off ended up with causing more trouble that they’re worth. Problems included the following:

•  voltage regulator fried
• TX1 via the header pin did not work
• finding a driver took extra goggling

Needless to say,  I ended up purchasing the real one.

Wiring xbees on breadboards gets old fast. The current setup consists of switches to commission/reset and  a potentiometer to vary the input voltage for testing a device. Nevertheless, I  purchased the wireless connectivity kit  (S2C) and the pro version of the xbee  to facilitate the configuration and program some custom functionality in the xbee in the future. Highly recommended if xbee development is on the radar. BTW, digikey Canadian or US site offer great service and fast delivery. I’ve ordered from them several times.

Observations

Herbs

The basil and oregano took a couple of weeks to germinate followed with a slow growth rate.  In contrast to what others are doing, the growth rate falls far short with expectation.

Leafy Vegetables

The kale and arugula germinated in 3 days and grew relatively fast. The weak stems could be attributed to the LED’s . I’ve planted some outside as well and will compare the stem sizes with the indoor ones.

Minor Changes

The addition of a fan to create a light  breeze led to stronger stems. After a couple of weeks of circulation, the arugula and kale stems seemed stronger. The basil grew and looked healthy yet remained small. When compared to their outdoor counterparts, the healthier looking indoor basil prevailed.

Next Steps

There seems to be some confusion out there between lumens and pars. I read about people only measuring lumens for plants and scratch my head.  Consequently,  I like ChilLED‘s pitch in positioning their lighting products as well an intro-101 from Lush Lighting.

Incidentally, a buzz exists stating the effects of UV could lead  to ‘certain’ plants to produce more THC. Note, I am not interested growing those plants and just want to grow edibles all year round.  At any rate,  I think the root cause revolves around the low LED pars and power rather than the effects of different soil, nutrients, and seeds.

In short, I’m considering using ChilLED for sourcing my lighting needs provided that  controlling the output of the various channels without using their controller remains feasible.  Note  growmay5 provides some interesting vlogs on this as well as other topics around LED plant lighting.

Altogether, I’m satisfied with experiment and how quickly I could mash up a solution. Hydroponics is the next step with better LED lighting and queued for later this year as a project.

Kale

Temporary setup

Slapped together hardware

Bike LEDVest

I’ve been tossing this project in my head for a few years. I signed up when the Myo Armband came out on kickstarter and figured I could make use of it one day.   When I purchased the the Apple Watch, then that got the wheels in motion to build an LEDVest.

Some of the goals I wanted to achieve included the following:

• Learn the iOS development (Swift language)
• Drill down on Bluetooth LE development
• Persist information on iCloud and retrieve from different devices
• Create something useful and provides context based information to others while riding my bicycle at night
• Explore iOS HealthKit and MapKit

Prototype

My wife did all the sewing. The LED’s are so bright that the iPhone camera does not do it justice inside. Many people commented from motorists, pedestrians, and cycles on how cool this vest was.

It took a lot of effort but it was a nice diversion from the day job. Learning a new programming language, organizing the code so that the appropriate level of abstractions exist to easily add new features, creating an application level protocol to control the LEDVest, and designing and building simple hardware bumped up the fun factor.

Using my Apple Watch, I can speak text to display and I send it to the LEDVest to display. If I am annoyed at a stop light, I tend to keep it safe. e.g. “Smog sucks”.  So far the software periodically displays the temperature from the hardware, along with the WTI price and Canadian currency via the yahoo finance API. If I loose connectivity to the iPhone, the arduino portion fails-safe and displays the stop symbol and posts the temperature every 30 seconds.

I’ll talk about the implementation details later.

Making it work.

I got everything to function with a rather messy board setup as shown below.

The output from the Arduino shows the delta T between messages received from the end-devices.  It is pretty close to the calculated ones. I will change the duration to be 15 minutes later on but for debugging purposes 10s intervals for pin sleep is tolerable.

Host Software

Rather than re-invent the wheel, I thought there should be software out there that provides SCADA/HMI functionality for free. It is a commoditized activity by now.  After combing the web, I stumbled and settled on Mango, an open-source M2M solution. Mango is Java based that integrates with MySQL and runs under Apache. All good stuff so far.  The web site describes the features and how to install the software.  I liked the data historian, alarms, and the various types data points including calling external web based sources. I set one to get the external temperature at the airport and using regex to scrape of the temperature form the HTML. All within Mango.

I found it relatively easy to get going. One thing I had to do was write a Modbus function 6 (write a single register) for the Arduino in C as I want to send commands to the arduino. i.e. set the time for example.

The diagram below shows some of the points I configured to handle the home energy monitoring. I used ISA motivated nomenclature to name the tags. I may revert to a human readable tags as I won’t have hundreds of points and becomes cryptic after a while.

Data logging for each data point is configurable as shown in the screen shot below. The example is for the temperature in the basement. All of this info is in the MySQL database from which one can chose to slice and dice the data later on using external tools.

As for graphical objects, one can create custom objects e.g. dials, meters, etc. and assign tags to them. When this is all done I will add an iPhone friendly UI to this so I can interact with the home energy system on the road. One thing that Mango does is allow me to work on my solution rather than re-inventing the wheel.  I know have the facility to hook up multiple ardduinos and focus on the fun stuff which is the embedded side of things.

Prototyping – Part II

There is not much to this. A protoshield, the arduino, and a breadboard. Note the current transformer (donut). I have two of those to use in the panel.

The first test was to plugging in a 60 W lamp to see what the measurement came too. I expected around 0.5 Amps and 60 watts. I was not disappointed.  I proceeded to plug in a toaster and put the ammeter in the circuit to see if my RMS current matched its RMS measurement. The photo below shows a .4% error. Not bad. Note the drop in the line voltage.

In Canada, the nominal line voltage is 120Vrms. I do measure the voltage as part of my power calculations and when I saw the 113 V I checked with the multi-meter and it read the same.  Assuming a 120 V reference would lead to errors in the power calculations. I should not be running a toaster outside my 20Amp line in the kitchen. I created a suicide cord that threads through the current transformer and is basically an extension cord. It plugs into a 15Amp line with other loads. 120 down to 113 is just over a 5% difference from the nominal line voltage. I am trying to rationalize why such a large dip. Anyway, the power measurement works.

Crest Factor

The crest factor is the the ratio between peak and RMS signals. I do compute that and it gives me an idea on the shape of the waveform. A sinewave should have a crest factor of $\sqrt{2}$. The 60 W lightbulb had a crest factor of 1.40 for the voltage 1.40 for the current. Close enough.

I plugged in a variable speed drill and ran it a low RPM. As expected, the power factor went down to .27 with most of the power becoming reactive at 104 vars. The real power was just a mere 29.5 watts. The crest factor for the voltage was 1.39 and for the current, 3.96. That is expected as the duty cycle is changed to control the speed. For us home owners, we get charged for the real power consumed.  In industrial environments, the power company would penalize you for running with such an awful power factor.

I can’t wait to plug all this in the main panel see what the overall power consumption profile is. I expect the power factor to be closer to one.

Next Steps

Computing C02 emissions is trivial as well as projecting cost of power usage.  I would like to have that wired next to the power panel and displayed on the LCD sooner than later.  On the other hand, I need figure out the zigbee side of things as well as how to best do the data logging.  I can easily purchase another arduino later and focus on getting this prototype soldered on something more permanent.