Project aims to control lights and CO2 admission to a planted aquarium. User has 2 lights time interval to set and one CO2 time interval. In the defined time intervals relays that control lights and CO2 are turned on or off. Additional sensors were added to read data about the aquarium and room.
So far so good. The interesting part of the project is still to come: the time intervals, relay controls and sensors data are driven and stored by a PC running Linux and NodeJS server. The server stores sensor data in a database and exposes a web interface for users to setup time intervals and see historical sensor data in chart format. Communication between NodeJS server and Arduino is done using serial port. Web application requires authentication in order to gain access to controls and sensor data.
Details on how to install and run NodeJS server can be found on GIThub.
PS: This is my second project using Arduino, so any advice would help me a lot.
Arduino Aquarium ControllerRelay:
Arduino controls 2 relays that are set on/off based on 3 time intervals:
- 2 time interval for aquarium lights (you can setup 2 periods during the day when aquarium lights are on)
- one time interval for CO2 (solenoid that controls the addition of CO2 in the aquarium)
Time intervals can be set via web interface and are stored in EPROM in order to be able to restore them after a power failure. Read / write data to EPRON are kept to a minimum. Make sure on initial Arduino setup you write write only once the default values on EPRON. You do this by removing comments here:
// should run only once at initial setup
// writeSettingsFromMemory();
Sensors:
The setup has 2 sensors:
- An ambient temperature and humidity sensor
- A waterproof temperature sensors that is submerged into the aquarium
Sensor data is updated every 20 mins. (time interval value can be easily adjusted) and the updated data is displayed on the LCD and sent to server via serial port. Server is storing the data in a database (mongo DB) in order to be used as statistical data in web interface.
Time control:
Project uses Time and TimeAlarms Arduino libraries to manage time and schedule events that control relays. Schedulers are also used to periodically read sensor data and send data to server. RTC module is used to keep track of time in case of a power failure. Time library syncs with RTC module based on a schedule.
Server & Web InterfaceThe server for this setup is is using NodeJS, Express and MongoDB and is capable of communicating with Arduino through serial port. The server also exposes some APIs endpoints that are used to communicate with the web interface.
The web-interface is a single page Angular 5 app. The application is responsive and can adapt to any screen size. App communicates with the server using APIs. The following features are supported by the web-app .. so far:
- login & user management: access to aquarium data and control via web interface or API are secured with login
- Aquarium Controls: control the 2 relays directly from web interface (manual mode on light and CO2). Displays the total amount of time when lights and CO2 are on.
- Aquarium scheduled time intervals when lights and / or CO2 are on / off can be set directly from web interface
- Statistics: sensor data displayed using charts. Charts can displayed data from current day, last week or last month.
Hardware needed
Old PC or laptop. In this setup i used and oldish MSI mini PC Celeron 1.8Ghz, 2GB DDRAM3, 256GB HDD.
On this PC I've installed a light Linux distribution with minimal UI: Lubuntu
Starting the server
Prerequisites:
- NodeJS v8+ installe on server
- MongoDB installed server
- Angular CLI
Start server in development mode using following command
$ npm run dev
This is usually used when developing the server and web-interface.
Start server in production mode using following command
$ npm run prod
More details here.
Further steps would be:
- setup up a web-server that servers the generated Angular web-app (static files : html / css / js / images / fonts). I recommend using NGINX for this.
- make sure web-server and NodeJS API start automatically on startup in order to recover after power failure
I would be happy to share more details on this. Just let me know.
Web-Interface Print-Screens
Comments