Drinking Reminder Water Bottle With AllThingsTalk

About: Howdy, we are application engineers in Seeed. Sharing projects with maker community is awesome. Hope you like it XD Seeed is the IoT hardware enabler providing services that empower IoT developers to swiftl...

Do you often forget to drink water when you are busy? Welcome to try our drink reminder water bottle.

Step 1: Things Used in This Project

Hardware components

Software apps and online services

  • Arduino IDE
  • AllThingsTalk Maker

Step 2: Hardware Connection

Grove - RTC and Grove - OLED Display must communicate with Wio Link via I2C bus, but it only have an I2C port in Wio, so you need to use a Grove - I2C Hub or make a Grove cable by yourself. Then connect Grove - Ultrasonic Ranger to port Digital0 in Wio Link, if you have a Lithium Battery, you can connect it to Wio too.

Step 3: Software Programming

Here is the idea, we use Ultrasonic Ranger to detect the changes in water level in the bottle, and use this to calculate how much water did we drink. And use RTC to get the current time, if we don't drink for a long time, raise an alert to remind us that we should drink. The OLED will display how much water did we drink and how many times we reached the goal real-time.

These libraries can be helpful in this project but them should be installed manually, so please download and import them to your Arduino IDE:

For controlling OLED, we create a class named Display, then we can call showDateTime() method, showProgress() method,showContinuously() method and showAlert() method to display date & time, drinking progress & goal, how many days reached the goal continuously and drinking alert in OLED.

In the methods mentioned above, we use the basic OLED display methods like:

oled.setTextXY(x, y); 
oled.putString(your_string);

Before using them, you need to initialize the OLED, which means calling init() method in setup() produce:

void Display::init() 
{
 oled.init(SH1107G);
 oled.clearDisplay();
 oled.setNormalDisplay();
 oled.setVerticalMode(); 
}

For collecting drinking data, we created a class named DrinkingData. We can use setGoal() method and setAlertInterval() method to set the goal of daily drinking and how often raise alert if we don't drink water.

In addition, we can call getAlert() method, getGoal() method,getProgress() method and getContinuously() method to get if there is an alert for now, daily drinking goal, drinking progress today and how many days reached the goal up to today.

updateProgress() method and updateContinuously() method should be called in loop() produce, they will update your drinking progress and update how many days you reached the goal.

Step 4: Cloud Configuration

Think further, if you want to send your drinking progress to a cloud, for example, AllThingsTalk.

In AllThingsTalk Playground, you can create a device easily, and get its Device ID and Device Token, your should replace it in ATT.cpp.

And then we create 2 functions, named initATT() andsendProgress() in Arduino IDE.

In initATT() function, we subscribe your device to MQTT server, aka "api.allthingstalk.io". And in sendProgress() function, we build a new message, and send it to ATT.

void initATT(void) 
{
 Serial.println("Subscribe MQTT");
 
 while (!device.subscribe(pubSub))
 {
    Serial.println("retrying");
 }
}
 
void sendProgress(uint16_t progress) 
{
 payload.reset();
 payload.map(ASSETS_COUNT);
 
 payload.addNumber(progress, "Progress");
 
 payload.send();
 device.process();
}

If you don't want to use a cloud, please comment initATT() andsendProgress() calling code in setup() or loop() produce, or the program will be stuck at them.

Finally, fill your Wi-Fi SSID and Password in cup.ino, and power up Wio Link, you will see the drinking progress uploaded to AllThingsTalk.

Share

    Recommendations

    • DIY Summer Camp Contest

      DIY Summer Camp Contest
    • Backyard Contest

      Backyard Contest
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    Discussions