IOT Fish Tank

Created by Brandon Ekins

brandonekins.com/

https://github.com/BrandonEkins/fishtank

Project Outline:

The goal of this project is to simplify the different tasks associated with taking care of fish. While my wife thought it was a great idea to buy some beta fish a couple of years ago their numbers have dropped from 2 to 1 because of our inability to give them proper care. This project should extend the life of our remaining Beta as we can now feed him remotely and be notified of when he needs to be cleaned.

Project Requirements:

Utilize at least 3 physical devices (one sensor and two actuators, or two sensors and one actuator)

  • Raspberry Pi (Actuator)
  • Wemos d1 mini x 2 (1 actuator & 1 sensor) ### Utilize at least 2 wireless communication protocols (Wi-Fi, BLE, RFID, LoRa, etc)
  • Wi-Fi(MQTT)
  • Discord Bot

Utilize restful API

  • basic information from tank sensor running from my Raspberry Pi

Utilize event hub or cloud IoT service

  • MQTT on Raspberry pi

Utilize a non-web page interface (voice, IFTTT, chat)

  • Discord Bot

Project Diagram

diagram

Part list

  1. Raspberry Pi
  2. Tank sensor
    1. Photo Resistor
    1. Wemos D1 Mini
    1. Thermometer
  3. Auto Feeder
    1. 3D printed hopper
    1. 1/2 in drill bit
    1. Drill bit adapter
    1. 1/64 geared 5v stepper motor
  4. Physical Interface
    1. Wemos D1 Mini
    1. Button
    1. OLED Display

3D printed part files

Located in the parts folder on GitHub

Sources

http://tinkercad.com https://learn.adafruit.com/adafruits-raspberry-pi-lesson-10-stepper-motors

The Paho MQTT Python Client-Beginners Guide
https://www.instructables.com/id/ESP8266-with-Multiple-Analog-Sensors/

Procedure

Because of the different nature of this project I am not going to go step by step into how I did each step but instead talk about the steps, the roadblocks I faced and then how I overcame them

  1. The Hopper: First, I was excited to jump into the 3d modeling and printing as it was my presentation as well. Thankfully I have a talented father who could help edit my designs and let me know what ideas needed better flushing out. I eventually ended up with the idea of using a drill bit as an auger in a hopper because that way if I got the dimensions wrong, I could just drill it out. For some reason I really wanted to power everything from one power cable, so I searched out the most powerful motor that could be powered off the 5v pin and I ended up finding a 1/64 geared stepper motor and h bridge set on amazon. Once I obtained the motor and the drill, I needed to model an adapter from the triangle end of the drill bit to a rectangular motor head. This took me 2 prints and I still ended up filing it a ton until it fit. The hopper came out nice on the first attempt but the stem for the drill bit wasn’t quite long enough, so I ended up incorporating some wooden blocks to make up the difference.
  2. The Raspberry Pi: The next step was getting the Raspberry Pi to control the food dispenser. Using Adafruit’s guide I got it working quickly. I then wrote a dirty PHP website that when I loaded it would call the python script to run the motor.
  3. Sensors: For the temp and dirtiness sensors I decided to use a D1 mini. Unfortunately, they only have 1 analog pin, so I ended up following this guide to wire up my own multiplexer. I first wired it up in tinkercad to make sure I wouldn’t burn out any diodes.
  4. Physical interface: Originally the goal of this device was to use an OLED display to display the information from the sensor and to have a button that when pressed once would update the information and if twice it would feed the fish. Unfortunately, the screen went a little haywire and it became a lower priority so that is something I would like to play with later. The button however worked seamlessly.
  5. MQTT: To connect all the devices, I created a MQTT server on the raspberry pi. Each sensor had its own channel as well as the button. There was also a command channel that the sensor was subscribed to and when a command came for either light or temp, they would then publish their information on their individual channel. The button would just send a message saying when it was pressed. The raspberry pi has a python script running as a systemd service that listens on all the channels and then both stores the needed information and handles running the motor based on the button push. One of the issues I mentioned during my presentation was the difficulty in keeping them connected. To make sure they heard their requests I wrote a script that continually publishes the message until it can confirm that the command was run.
  6. API: For the API I simply wrote a flask server that took the information stored from the sensors and then served it to 3 different endpoints: light, temp & food.
  7. Website: For the website I built a webpage with chart.js that would pull the data from the API endpoints and then display the last 10 datapoints on graphs. This was one of the least polished parts of the project and I wish I had known about the adafruit.io interface earlier.
  8. Discord Bot: For the discord bot I had it pull the information much in the same way that the API did and then you can request it based on the command you type in.
  9. Scheduling: My goal has always been to schedule out the feedings so we dont have to think about it anymore. To do this I created a cron job that ran the motor script and the sensor scripts on a specific time schedule.

Conclusion

This is the largest scale project that I worked on during this class as you can see based on all the source code detailed below. If I were to do a second iteration of the project, I would actually remove all of the different boards and run everything off of a wemos d1 mini that is connect to adafruit.io control panel. This would improve reliability and reduce the cost & size of the overall project. I would also look at creating a smaller hopper that could clip on the side of the fish tank. Overall I probably spent about 20 hours on this project and about 2 on the writeup.

Posted in IOT

Leave a Reply

Your email address will not be published. Required fields are marked *