# TankDroid - Bluetooth Android-Arduino Controller



## renesis

Finally am far enough to show you guys what I've been working on.

Inspired by AH's iAqua, robsworld's Robo-Tank, and bits and pieces from other older projects. (All on TPT)

I started off reading the iAqua mega thread on TPT, and soon realized they were hitting space limits on the MEGA. I decided to go with a DUE and had begun my build with a 3.2" LCD. Later, Rob's mega-thread had started, and one quote stuck out.



robsworld78 said:


> I wanted to build one for myself but was looking at one of my phones which has the 3.2" screen and figured that's to small so decided I would resize it to fit a 5" or 7" screen


Which got me thinking... why not just control it with my phone?

In comes the bluetooth, and weeks spent learning to write an app (Android if you haven't guessed), add a couple months of trial and error - and TankDroid was born.

It more or less covers the same things as iAqua, and a little less than Robo-Tank. No remote connect (for now ).

It is not complete (maybe far from it still), and I'd like to continue evolving it - but at this point, I am confident that it works. Still coming across the occasional bug in coding or in the app - but so far working very well. I do need to re-write the app to optimize it, as I used MIT App Inventor 2 which is not the best way to write apps (Takes a few seconds for the initial opening of the app). I also need to clean up the code before I post it, and would like to have it run while I'm on vacation without errors before I'd feel confident posting it.

Features:

- Bluetooth Control
- 5 LED Channel Control @ 12-bit PWM (right now set to WW/CW/R/G/B, but will add adjustability if there's enough interest for anyone else to build one of these)
- Sunrise/Low Sun/High Sun/ Sunset/Moon Lighting
- Custom Lighting
- 8 Relay Channel Control
- Heater Limit Controls + Alarm
- 3 Temperature Probes + Calibration
- 1 pH Probe + Calibration
- Feed Settings to turn off filters etc.
- Auto Feeder
- 2 Auto Dosing pumps (may expand on this later)
- Programmable schedules for power, lights, dosing, and auto-feeding

Hardware:
- Arduino DUE
- HC-05 Bluetooth Module (reprogrammed to 115200)
- DS3231 RTC (found to be less affected by noise, and to stay in sync better than the DS1307, also runs on 3.3V)
- DFRobot pH board + probe
- Optocoupled 8 Channel Relay Board
- Optocoupled 2 Dosing Channels
- Relay for Auto feeder

The hardware is a mess for now, after having to try various configurations and swapping pieces. I will be moving everything to a custom board in the coming weeks, and likely create a new box as I put a couple too many holes in this one. Also, having the dosing pumps inside the box makes me a little nervous.










App:

First screen, upon clicking the button, list of your bluetooth devices pops up.









Then, select TANKDROID. I am going to try to change this, so it automatically finds the right device to pair without input.









Home Screen
Set to update every 3 seconds. Couple bugs still (MIN temps, fertilizer vials). Ignore pH value, probe was not connected when I took this capture. Clicking the Temp or pH icons resets the respective MIN/MAX.

Feeding icon shows last fed time or time left in feeding cycle when active.
Light icon shows the current mode, and time left to next fade, or time left in active fade when in a fade.

Dose remaining show up, accidently inverted the dose remaining in the app - so the vials actually fill up as the real ones empty .










Custom Lighting Screen, sliders or can type in a value. Checkmarks sends the value, the left icon resumes normal lighting mode.










Power Controls - Click on the icon to toggle power.









Settings Screen:









Light Values (click and type in), checkmark sends and saves the values, and the X requests current values (used to confirm changes, or revert changes) - this goes for most the screens.









Temp Limits for heater safety:









Temperature Calibration, this screen will show the current temps as well to help in calibration - placeholders there for now.









pH Settings - same as above, placeholder for current ph for now, also just realized i mixed up the high and low (whoops!). I'll add a checkbox option to allow for CO2 control based on pH value later.









Feed settings:









RTC Sync button sends android time to the arduino. Very easy to sync, but this RTC is very good, hasn't lost a second in 8 days. The ds1307 I had lost about 4-5 seconds a day.









Fertilizer settings, refill and run buttons:









Schedules screen:









Power:









Fades:









Dosing:


















Feeding









That's it for the screens for now.

To Do:

- Fix MIN temp readings
- Fertilizer Icons on home screen
- Temp & pH readings on calibration screens
- Redo Box & Clean up circuit board
- Clean up coding & app
- Add WIFI

To Do if there's interest from others to build one:

- Allow adjustability in LED channel colours
- More LED channels?
- Add more dosing pump capability
- ???

No LCD means TONS of room to add things, whole sketch is at 10% of the DUE's capacity.

Also, didn't get any shots of it, but the app scales up nicely to my 7" tablet as well.

I may go with a PI server to allow for wifi control - the PI could connect to the controller via bluetooth and offer some separation between the DUE and the outside world. Still playing with this in my mind, and won't likely get anywhere for a month or so.

Suggestions? Comments?


----------



## mlongpre

This looks awesome! Very well done!

I'm interested in this with wifi so I could check things online. Also maybe two more dosing pumps. Same with led drivers. Possible to build in support for more but not use them if you don't need them? Pwm dimming of each channel?

All in all very elegant and simple. I like where this is going!


----------



## LooseheadLen

*Nice work*

+1
V. nice design. I agree with the previous poster - more LED channels if the capacity is there. Makes it easier to scale up or potentially control/monitor multiple tanks. Fwiw, I would (like to) use this on my next tank (100g fw).


----------



## renesis

mlongpre said:


> This looks awesome! Very well done!
> 
> I'm interested in this with wifi so I could check things online. Also maybe two more dosing pumps. Same with led drivers. Possible to build in support for more but not use them if you don't need them? Pwm dimming of each channel?
> 
> All in all very elegant and simple. I like where this is going!


Thanks!

Yes, each LED channel has 12-bit (4096 brightness levels) PWM dimming. I also use PWM on the dosing pumps to give them a 'slow start/stop' to keep the DC motors in good shape as they break down faster from hard starts.

Because of that, with the current hardware at least, I'm limited to 10 PWM channels total. (Currently 7 in use with 5 LED and 2 pumps)

I could probably figure out another way of giving the pumps a slow start or possibly have an add-on board for additional PWM channels.

WIFI will definitely make things tricky, and I'd like to keep the connection secure- so I will probably take my time on this one to make it rock solid. I was thinking of a separate module (maybe a PI) to connect to the controller via BT, and host a small page similar to the app that could be accessed externally. Again, security will be key here.



LooseheadLen said:


> +1
> V. nice design. I agree with the previous poster - more LED channels if the capacity is there. Makes it easier to scale up or potentially control/monitor multiple tanks. Fwiw, I would (like to) use this on my next tank (100g fw).


Thanks!
For multiple tanks, it may be easy enough to have 2 controllers and then have them with different BT addresses selectable from the splash screen. I haven't given it much thought as I haven't caught MTS (yet??)


----------



## Marz

Very nice. The interface is impressive for a first timer!


----------



## renesis

Thanks Marz!

I've been looking at the design, and if I incorporate another chip (PCA9685), I can go up to 16 LED channels, and still retain the soft-start dosing.

Are 4 dosing pumps and 16 LED channels enough for you guys? Any other features desired? I may as well incorporate everything hardware wise now into the circuit board, can always do the coding later.


----------



## HighWater

Awesome Renisis! 
How about water level monitor? 
Auto Top Off on/off
Water Dump Level 1/4 tank - 1/2 tank - 3/4 tank (hard piped for water changes)


----------



## mlongpre

4 dosing and 16 led would be awesome. If water level monitoring and top off are possible, even better! Webcam support maybe? To view your tank while you're away.


----------



## renesis

Water level, and top-off should be straight forward enough.

Level could be used with one of these:

https://www.adafruit.com/products/464

or something like this:

https://www.adafruit.com/product/164

Both are analog, and it would be simple enough to code in- and leave an open connector for the users choice.

Top-off are just float switches, and to then control one of the auxillary relays for a pump- again easy enough to add in.

Won't be able to work on this for the next 10 days or so, but will update again once I have a design in mind. Controller will be fully in charge while I'm away- hopefully I won't come back to an algae farm or dead fishies.

Webcam would be nice, but that might be a bit beyond my reach... we'll see


----------



## LooseheadLen

renesis said:


> Water level, and top-off should be straight forward enough.
> 
> Webcam would be nice, but that might be a bit beyond my reach... we'll see


If you're willing to cross to the dark side, a Beaglebone Black or RaspberryPi might integrate webcam easier?


----------



## renesis

Hey all, back from vacation!

Quick update- Unfortunately, the RTC seems to have fried while I was away. It only gives out the time and date as all 0's, and will not accept any time being written to it. So, next step will be to figure out if it was a bad chip, or something I did in the wiring. Luckily that time condition put it into midnight- and essentially kept the lights off. 

Fish and plants were all okay though!

I'll have to figure this one out before I start adding any more features to the board.

Len, I initially started with the Raspberry PI, but didn't feel experienced enough in linux to pull it off just yet. But I may use a PI for the webserver portion- and in that case, webcam could be integrated.


----------



## renesis

I finally had some time to open everything up to figure out what went wrong (was able to run the tank manually off my phone in the meantime to turn on/off lights, dose/ co2 etc..)

Well... took a look at the RTC and immediately found my error - total rookie mistake!

I had put 2 2.2k pull up resistors for SDA and SCL - except... the one for SDA, I put it into the hole next to strip that connects to the clock. So, SDA was not pulled up - and it worked for a little while until the pin on the DUE died.

Since I was using SDA1/SCL1, I moved everything over to SDA0/SDA0 - removed the resistor (as there are internal ones for SDA0/SCL0), and it looks like I'm up and running again.

I've started working on a custom board now as well to replace my wire jungle.


----------



## mlongpre

Looking forward to seeing more!


----------



## disman_ca

Renesis are you will to share your code? I've wanted to delve into this type of build and even arduino uno to try an learn but it is beyond my dedication to learning the wiring and coding.


----------



## mlongpre

Yeah I've been interested in these projects for a little while now too. I'm just scared off by the coding really. Tried to learn some coding a couple years back and it didn't go too well. The rest I can do no prob. Great with electronics and soldering just not the part that will make everything work together. Bah!

Really looking forward to seeing this thing finished and being a potential customer.


----------



## renesis

Hey everyone,

I will definitely post the source code once its a little more refined. I haven't put in much markup text yet, so its quite difficult to understand what its doing if someone needed to modify it.

Haven't been able to work on the hardware much this week, but its been running fine after the RTC channel swap. Hopefully will have some more updates soon.


----------



## slobodan

Renesis,
How is this project going.. I'm planning to do exactly what you are doing here..
Are you planning to release this as community effort project so some of us can contribute to this?


----------



## renesis

slobodan said:


> Renesis,
> How is this project going.. I'm planning to do exactly what you are doing here..
> Are you planning to release this as community effort project so some of us can contribute to this?


Hey,

Unfortunately this project has gone on the backburner this summer as I've had a couple other projects that took priority. Hoping to get back on this in the Fall though!

The controller has mostly been taking care of my tank. I say mostly, because it does seem to lock up randomly every 3-5 days where I have to manually reset it. I haven't had a chance to track down what's causing it as of yet, but I do think its hardware related.

I do plan on releasing it all, but wanted to get the firmware at least somewhat stable first, and create a proper shield for the Due. The code is still quite a mess, and I haven't gone through to clean it up yet, but can definitely post it if there's interest.


----------



## slobodan

Hi,
I'm definitely interested to help you with this.
I have most of the parts and PCA9685 chips which are currently running my LED lights of Arduino Uno.
I'm building new setup with Arduino Due and was looking at iAqua but then thought why not use LCD screen which I already have, my phone..  
If you would like I can definitely help you clean up your code and anything else that is needed to get this completed.
I can try and setup GitHub as well.
Let me know what you think?


----------



## renesis

slobodan said:


> Hi,
> I'm definitely interested to help you with this.
> I have most of the parts and PCA9685 chips which are currently running my LED lights of Arduino Uno.
> I'm building new setup with Arduino Due and was looking at iAqua but then thought why not use LCD screen which I already have, my phone..
> If you would like I can definitely help you clean up your code and anything else that is needed to get this completed.
> I can try and setup GitHub as well.
> Let me know what you think?


Sounds good! I could use some help if I want any hope in releasing this thing in the next year.

I've uploaded the arduino code here: https://github.com/renesis/Tankdroid

Edit: If you pm me your github user or email, I can add you as a collaborator.

It's separated into 'tabs' to make things easier, still needs a lot of help though.

I think the next step is designing a shield for the DUE to incorporate the PCA9685, (at least) 4 optocoupled fets for dosing pumps, and ULN2803 for the relay board control, Bluetooth, RTC, and of course the eeprom chip as well.

I did start on the shield, but admittedly haven't gotten far.

Edit: If you pm me your github username, I can add you as a collaborator.


----------



## slobodan

thanks renesis..
Let's see if we can get people interested and finish this..
I think this has great potential...
I'll look through the code and see what I can figure out..


----------



## stephane france indre

renesis said:


> Finally am far enough to show you guys what I've been working on.
> 
> Inspired by AH's iAqua, robsworld's Robo-Tank, and bits and pieces from other older projects. (All on TPT)
> 
> I started off reading the iAqua mega thread on TPT, and soon realized they were hitting space limits on the MEGA. I decided to go with a DUE and had begun my build with a 3.2" LCD. Later, Rob's mega-thread had started, and one quote stuck out.
> 
> 
> 
> Which got me thinking... why not just control it with my phone?
> 
> In comes the bluetooth, and weeks spent learning to write an app (Android if you haven't guessed), add a couple months of trial and error - and TankDroid was born.
> 
> It more or less covers the same things as iAqua, and a little less than Robo-Tank. No remote connect (for now ).
> 
> It is not complete (maybe far from it still), and I'd like to continue evolving it - but at this point, I am confident that it works. Still coming across the occasional bug in coding or in the app - but so far working very well. I do need to re-write the app to optimize it, as I used MIT App Inventor 2 which is not the best way to write apps (Takes a few seconds for the initial opening of the app). I also need to clean up the code before I post it, and would like to have it run while I'm on vacation without errors before I'd feel confident posting it.
> 
> Features:
> 
> 
> Bluetooth Control
> 5 LED Channel Control @ 12-bit PWM (right now set to WW/CW/R/G/B, but will add adjustability if there's enough interest for anyone else to build one of these)
> Sunrise/Low Sun/High Sun/ Sunset/Moon Lighting
> Custom Lighting
> 8 Relay Channel Control
> Heater Limit Controls + Alarm
> 3 Temperature Probes + Calibration
> 1 pH Probe + Calibration
> Feed Settings to turn off filters etc.
> Auto Feeder
> 2 Auto Dosing pumps (may expand on this later)
> Programmable schedules for power, lights, dosing, and auto-feeding
> 
> Hardware:
> 
> Arduino DUE
> HC-05 Bluetooth Module (reprogrammed to 115200)
> DS3231 RTC (found to be less affected by noise, and to stay in sync better than the DS1307, also runs on 3.3V)
> DFRobot pH board + probe
> Optocoupled 8 Channel Relay Board
> Optocoupled 2 Dosing Channels
> Relay for Auto feeder
> 
> The hardware is a mess for now, after having to try various configurations and swapping pieces. I will be moving everything to a custom board in the coming weeks, and likely create a new box as I put a couple too many holes in this one. Also, having the dosing pumps inside the box makes me a little nervous.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> App:
> 
> First screen, upon clicking the button, list of your bluetooth devices pops up.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Then, select TANKDROID. I am going to try to change this, so it automatically finds the right device to pair without input.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Home Screen
> Set to update every 3 seconds. Couple bugs still (MIN temps, fertilizer vials). Ignore pH value, probe was not connected when I took this capture. Clicking the Temp or pH icons resets the respective MIN/MAX.
> 
> Feeding icon shows last fed time or time left in feeding cycle when active.
> Light icon shows the current mode, and time left to next fade, or time left in active fade when in a fade.
> 
> Dose remaining show up, accidently inverted the dose remaining in the app - so the vials actually fill up as the real ones empty .
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Custom Lighting Screen, sliders or can type in a value. Checkmarks sends the value, the left icon resumes normal lighting mode.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Power Controls - Click on the icon to toggle power.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Settings Screen:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Light Values (click and type in), checkmark sends and saves the values, and the X requests current values (used to confirm changes, or revert changes) - this goes for most the screens.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Temp Limits for heater safety:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Temperature Calibration, this screen will show the current temps as well to help in calibration - placeholders there for now.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> pH Settings - same as above, placeholder for current ph for now, also just realized i mixed up the high and low (whoops!). I'll add a checkbox option to allow for CO2 control based on pH value later.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Feed settings:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> RTC Sync button sends android time to the arduino. Very easy to sync, but this RTC is very good, hasn't lost a second in 8 days. The ds1307 I had lost about 4-5 seconds a day.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Fertilizer settings, refill and run buttons:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Schedules screen:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Power:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Fades:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Dosing:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Feeding
> 
> 
> 
> 
> 
> 
> 
> 
> 
> That's it for the screens for now.
> 
> To Do:
> 
> 
> Fix MIN temp readings
> Fertilizer Icons on home screen
> Temp & pH readings on calibration screens
> Redo Box & Clean up circuit board
> Clean up coding & app
> Add WIFI
> 
> To Do if there's interest from others to build one:
> 
> 
> Allow adjustability in LED channel colours
> More LED channels?
> Add more dosing pump capability
> ???
> 
> No LCD means TONS of room to add things, whole sketch is at 10% of the DUE's capacity.
> 
> Also, didn't get any shots of it, but the app scales up nicely to my 7" tablet as well.
> 
> I may go with a PI server to allow for wifi control - the PI could connect to the controller via bluetooth and offer some separation between the DUE and the outside world. Still playing with this in my mind, and won't likely get anywhere for a month or so.
> 
> Suggestions? Comments?


*****
Hello
good work
is it still in use,
I can't find the android app
it is on google store
thank you


----------

