Aquarium Monitoring with AWS-Seeed-Soracom

If our pollution adversely affects the environment, then, it's our responsibility to protect the environment, humans, plants, and animals.
Guillermo Perez Guillen
Published © MIT
Aquarium Monitoring with AWS-Seeed-Soracom
Difficulty: Advanced | Type: tutorial | Duration: 72 hours | Views: 871

Things used in this project

Hardware components

SORACOM Air Global IoT SIM SORACOM Air Global IoT SIM × 1
Wio LTE US Version - 4G, Cat.1, GNSS, JavaScript(Espruino) Compatible Wio LTE US Version - 4G, Cat.1, GNSS, JavaScript(Espruino) Compatible × 1
Grove - Ultrasonic Ranger Grove - Ultrasonic Ranger × 1
Grove - 3-Axis Digital Accelerometer ±16g Ultra-low Power (BMA400) Grove - 3-Axis Digital Accelerometer ±16g Ultra-low Power (BMA400) × 1
Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680) Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680) × 1
Antenna, Cellular / LTE Antenna, Cellular / LTE × 2
USB-A to Micro-USB Cable USB-A to Micro-USB Cable × 1
3.7V Lipo battery × 1

Software apps and online services

SORACOM Beam - Data Transfer Support SORACOM Beam - Data Transfer Support × 1
Arduino IDE Arduino IDE × 1
Jupyter Notebook Jupyter Notebook × 1
Python 2.7 × 1

Hand tools and fabrication machines

Aquarium × 1
Aquarium Air Pump × 1


1. Introduction

An aquarium is a vivarium of any size having at least one transparent side in which aquatic plants or animals are kept and displayed. Fishkeepers use aquaria to keep fish, invertebrates, amphibians, aquatic reptiles such as turtles, and aquatic plants. The term "aquarium", coined by English naturalist Philip Henry Gosse, combines the Latin root aqua, meaning water, with the suffix -arium, meaning "a place for relating to". The aquarium was launched in early Victorian England by Gosse, who created and stocked the first public aquarium at the London Zoo in 1853, and published the first manual, The Aquarium: An Unveiling of the Wonders of the Deep Sea in 1854. An aquarium is a water-filled tank in which fish swim about. Small aquariums are kept in the home by hobbyists. There are larger public aquariums in many cities. This kind of aquarium is a building with fish and other aquatic animals in large tanks. A large aquarium may have otters, turtles, dolphins, and other sea animals.

This project I will carry out in a turtle aquarium of 75x45x35 cm.

  • The DHT11 sensor, will measures the temperature and humidity of the environment of our aquarium.
  • The SRF04 sensor, will measures the distance from our sensor to the water in our aquarium, and so we can have an idea of the level water.
  • The ADXL345 sensor, will detects the vibrations of our air pump, or when our turtles are in motion.
  • 2. Cost

    With cellular connectivity, there is a cost associated with the data usage. This submission considered on cost effectiveness and also ability to scale production to 1000s of devices. We are going to associate with the exporter or wholesaler of the commercial aquarium service in our country. In this way we will ensure that our product reaches the consumer. Ornamental fish market linkage exists between buyers and sellers as well as domestic and international market. Wholesaler usually sells the fishes to local retailers and in turn, retailers directly sales to local customers, hobbyists etc. In this direction, in order to develop market for aquarium business service, there is need to studying consumer preference and existing marketing strategies, adopted by aquarists.

    3. Hardware

    Seeed Studio + SORACOM Starter KitWhat is Seeed? Seeed is the IoT hardware enabler, offering numerous hardware platforms and sensor modules, as well as customization and manufacturing services based on Shenzhen's extensive and flexible supply chain. Seeed is based in Shenzhen, China with branch offices in the US and Japan.Seeed Studio + SORACOM Starter KitWe are going to use the Wio LTE Cat 1 board, and the configuration of our project is the following:

    As we can see in the figure, we have to connect the humidity sensor DHT11 on the D20 pin, the ultrasound sensor on the D38 pin, and the ADXL345 accelerometer on the 12C pin. And don't forget, connect the battery, LTE antenna to Wio LTE and plug your SIM card to it.

    How does it work?
  • When we uploading data from an IoT device using Beam, the data is transmitted from the Wio LTE board to the end point of Beam on a 3G/4G/LTE closed network, communication is encrypted by Beam on the Internet past Beam, and the data can be safely delivered to the Amazon Web Services (AWS).
  • Before you go ahead, I suggest you read this important information about the Wio LTE board:

    4. Software

    Examples used:

  • Examples - Wio LTE for Arduino - mqtt - mqtt-client
  • Examples - Wio LTE for Arduino - grove - grove-accelerometer
  • Examples - Wio LTE for Arduino - grove - ultrasonic-ranger
  • Examples - Wio LTE for Arduino - grove - temperature-and-humidity-sensor
  • In the following figure we see how the device manager has detected the virtual port of our Wio LTE board.

    When our board is configured in DFT mode, then it is no longer detected.

    The used libraries and their download links are shown in the first lines of our code:

    #include <WioLTEforArduino.h> // DHT 11 & SRF04 & ADXL345 sensors "DHT.h" // DHT 11 sensor <Ultrasonic.h> // SRF04 sensor <ADXL345.h> // ADXL345 sensor <WioLTEClient.h> // MQTT#include <PubSubClient.h> // MQTT <stdio.h> // MQTT

    The important configuration to connect to the Soracom server is shown below:

    #define APN "" // MQTT#define USERNAME "sora" // MQTT#define PASSWORD "sora" // MQTT#define MQTT_SERVER_HOST "" // MQTT#define MQTT_SERVER_PORT (1883) // MQTT#define ID "WioLTE" // MQTT#define OUT_TOPIC "outTopic" // MQTT#define IN_TOPIC "inTopic" // MQTT

    The calculations of our sensors (DHT11, ADXL345 and SRF04) are shown in the following lines:

    // VARIABLES float h = dht.readHumidity(); // DHT 11 sensor float t = dht.readTemperature(); // DHT 11 sensor long distance; // SRF04 sensor int x; // ADXL345 sensor int y; // ADXL345 sensor int z; // ADXL345 sensor char envDataBuf[100]; //local data buffer // MQTT // SRF04 SENSOR VALUES distance = UltrasonicRanger.MeasureInCentimeters(); // SRF04 sensor SerialUSB.print("Distance: "); // SRF04 sensor SerialUSB.print(distance); // SRF04 sensor SerialUSB.println("[cm]"); // SRF04 sensor // ADXL345 SENSOR VALUES Accel.readXYZ(&x, &y, &z); // ADXL345 sensor SerialUSB.print("Acceleration [x,y,z]: "); // SRF04 sensor SerialUSB.print(x); // ADXL345 sensor SerialUSB.print(' '); // ADXL345 sensor SerialUSB.print(y); // ADXL345 sensor SerialUSB.print(' '); // ADXL345 sensor SerialUSB.println(z); // ADXL345 sensor

    The data to be saved on the AWS server and in JSON format are shown below:

    sprintf(envDataBuf, "{\"uptime\":%lu,\"temperature\":%f,\"humidity\":%f,\"distance\":%lu,\"accelx\":%lu,\"accely\":%lu}", millis() / 1000, t, h, distance, x, y); // MQTT SerialUSB.print("Publish:"); // MQTT SerialUSB.print(envDataBuf); // MQTT SerialUSB.println(""); // MQTT MqttClient.publish(OUT_TOPIC, envDataBuf); //send data to beam // MQTTYou can get download code on attachments: mqtt_aquarium.ino

    5. Soracom

    What is Soracom? Soracom is a MVNO (mobile virtual network operator), which means it doesn't operate its own network infrastructure, but instead has a partnership with NTT Docomo, one of Japan's largest telecoms, for its 3G and LTE. The Soracom User Console is in:'t forget plug your SIM card to the Wio LTE boardThe steps necessary to provision the board are installation of the Wio board drivers, Arduino board manager, Arduino example libraries, and the Wio LTE DFU and enable button sequences necessary to proceed.

    As part of my work, I show you my activated SIM.

    Next, the SORACOM Beam is enabled.

    And finally, Soracom Beam fill out. The Host name, we can get in the next chapter.

    Also, Soracom register credential we can get in the next chapter.

    You can learn more if you follow the instructions in the following video:

    6. AWS

    In Soracom Beam fill out, the Host name is getting from: AWS Iot - SettingsTo get the security credentials, we do the following: AWS IoT - Secure - Polices - Create

    We type:

  • Name:
  • Action: iot:*
  • Resource ARN: *
  • Effect: Allow
  • After we created the policy:

    We continue with: AWS IoT - Secure - Certificates - Create

    We select. One-click certificate creation

    After we download the credentials, we "Activate" the credentials.We "Attach a Policy", and select my IoT policy and click in "Done". Finally, we search our certificate and select "Active".

    7. IoT Analytics

    The main goal of this chapter is to graph the captured data. In AWS IoT Analytics we give a name to the "Resources prefix", and click on "Quick Create"

    We´re going to create a rule, so we give a name to our action and fill out the "Rule query statement" as follow: SELECT *FROM ‘outTopic’Click on "Add Action" and select "Send a message to IoT Analytics" and finally click on "Configure action"In "Configure action" click on: Send a message to IoT AnalyticsSelect your channel name and click on "Create Role" and give a nameClick on Create role.Now, we go to: AWS IoT - TestIn my case on "Subscription topic", I typed: outTopic and I can get the data values.When we have finished the test, the data hasn´t yet been loaded into "Content". So, we go to: IoT Analytics - Data setClick on Actions - Run now.On "Content" we can see the same dataYou can get this data on attachments: outTopic.json

    8. Sage Maker

    Type: Amazon SageMaker and we select Create notebook instanceWe fill out the Notebook instance settings as follow:

    We need to created a role with permissions to share resources between IoT analytics and Sagemaker.

    When you finished, click on Create notebook instance and once created, we hope it enters service.Finally, we Save, Run and Refresh

    The graphic and averages are calculated with:

    fig, ax = plt.subplots()df.temperature.plot(legend=True)df.humidity.plot(legend=True)df.distance.plot(legend=True)df.acceleration.plot(legend=True)'Average Humidity: ', df.humidity.mean())print('Number of samples: ', len(df))print('Average temperature: ', df.temperature.mean())print('Number of samples: ', len(df))print('Average distance: ', df.distance.mean())print('Number of samples: ', len(df))print('Average acceleration: ', df.acceleration.mean())print('Number of samples: ', len(df))You can get download code on attachments:

    9. Test

    In the following video, we can appreciate all the tests carried out with this system, from the Seeed hardware, later with the Soracom console and finally with Amazon Web Services.

    10. Conclusions

    We are going to associate with the wholesaler of the commercial aquarium service to ensure that our product reaches the consumer, and to reduce the operating costs, we must schedule the time in which we will monitor our aquarium. For example, two or three times a day and for one hour is enough. In my case, I used this method, and I didn´t spend all the credit assigned to me for the project.
  • Limitations of my project, in relationship with Seeeed´s catalog are: 1) I would liked to do tests with more sensors as Multichannel Gas Sensor, Grove Air Quality Sensor and Grove Water Sensor. 2) Propose the manufacture of a sensor that measures the water quality, since it doesn´t exists in it´s catalog.