Project showcase
DRS Oil Container

DRS Oil Container © GPL3+

An oil container that can automatically order new oil via Amazon DRS when the oil level in the container is low.

  • 831 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

Ide web
Arduino IDE
Simpleicon sns
Amazon Web Services AWS SNS
Icon
Amazon Web Services Amazon Dash Replenishment Service

About this project

Motivation

Have you ever craved to eat something but need to postponed cooking it just because you run out of oil? Now, this won't happen again with the DRS Oil Container, an oil container that can automatically order new bottle of oil when you're running low of it.

The DRS Oil Container is equipped with ultrasonic sensor acting as level sensor and connected to the Genuino MKR1000. The Genuino will initiate a purchase with the help Amazon DRS API when the sensor reading is below the threshold value.

Hardware setup

This project only involves the use of Genuino MKR1000 and HC-SR04 sensor. The HC-SR04 is connected to the Genuino MKR1000 as shown in the schematics. The Trigger and Echo pin of the HC-SR04 can be connected to any digital pins of your choice. The sensor is then placed under the container's cap.

Software setup

This project utilize AmazonDRS Library. The library is available on GitHub together with tutorial to setup DRS with push button. Before you start coding, there few setups need to be done in order to enable the Genuino MKR1000 to initiate a purchase via the DRS API.

1. Create Amazon Developer account

2. Create SNS Topic

3. Create a login with amazon (LWA) security profile

  • Please take note of your Client ID and Client Secret as these need to be used in AmazonTokens.h file

4. Create a Dash Replenishment Device

  • ASINs are Amazon's version of unique product identification
  • Please take note of the devices Model ID and the respective Slot ID

5. Authorize the device created earlier to make purchases and get authorization code grant

  • After you finish editing the AmazonTokens.h file and add your refresh_token, your Genuino is now ready to initiate a purchase

Demo

In this demo, water is used instead of olive oil. The Genuino initiate a purchase when the level is below 5 cm.

Conclusion

The project is not limited to replenishment of oil only but can be extended to any type of liquid container.

Code

CodeArduino
Code for the DRS Oil Container
/*******************************************************************
This code implement the Amazon Amazon Dash Replenishment API to 
automatically buy something from amazon when the sensor reading is 
below the threshold value. This code utilize the WiFi101 library,
AmazonDRS library, Ultrasonic Library and ArduinoJson library. It is the modified version of the amazonDashButton found in the AmazonDRS library 
example.

Credit to Brian Carbonette, J.Rodrigo and Benoit Blanchon for writing the 
AmazonDRS library, Ultrasonic Library and Arduino json library respectively.

AmazonDRS library
https://github.com/andium/AmazonDRS

Arduino json library
https://github.com/bblanchon/ArduinoJson

Arduino ultrasonic library
https://github.com/JRodrigoTech/Ultrasonic-HC-SR04

WiFi101 library
https://github.com/arduino-libraries/WiFi101

 *******************************************************************/

#include "AmazonDRS.h"
#include "Ultrasonic.h"

AmazonDRS DRS = AmazonDRS();

//WiFi creds ----------------------------------------------------------------------------------
char ssid[] = "****"; //  your network SSID (name)
char pass[] = "****";    // your network password (use for WPA, or use as key for WEP)
//------------------------------------------------------------------------------------------------------

#define slotNumber 1 //This will vary for multi slot devices 

const int TrigPin = 4;     //DIO number of the trigger pin
const int EchoPin = 5;     //DIO number of the echo pin
const in Bottle_height = 25; //Insert containers height (based on sensor position)
static long sensorTime = 0;    //millis of last sensor reading
static long waitingTime = 0;    //millis of last purchase
static String slotStatus = ""; //boolean which depicts if slot is available for replenishment
static String slotId = "";     //unique slot id ex: 0a5038b7-7609-4b81-b87e-3e291f386324 

Ultrasonic ultrasonic(TrigPin, EchoPin);

void setup() {
  Serial.begin(115200);

  //pinMode(EchoPin, INPUT);
  //pinMode(TrigPin, OUTPUT);
  
  while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
   }

  //Start up DRS
  DRS.begin(ssid,pass);
  
  //initialize slots
  DRS.retrieveSubscriptionInfo();  //check slot statuses

  slotStatus = DRS.getSlotStatus(slotNumber);
  slotId = DRS.getSlotId(slotNumber);
}

void loop() {

  //Check for level reading
  //if the slot status is true proceed to request replenishment for the associated slot
  
  if (levelCheck() && ((millis() - waitingTime) > 10000))    //wait 10 secs
    {
      
       //Check if slot is available, if so replenish
                
        if(slotStatus == "true")   //if the product in slot are available 
        {
            waitingTime = millis();
            //we have a match! replenish the products associated with that slot!            
            DRS.requestReplenishmentForSlot(slotId);
            Serial.println("Buy new");
        }
        else
        {
          Serial.print("Sorry, slot ");
          Serial.print(slotId);
          Serial.println(" is not available at this time");
        }
        
    }

}

bool levelCheck(void)
{
  delay(1000);
  int sensor = ultrasonic.Ranging(CM);
  int level = Bottle_height-sensor;
  Serial.print("Level(cm): ");
  Serial.println(level);
  
  if(level < 5 && level > 0 && ((millis() - sensorTime) > 30000))  //wait 30 sec
  {
    sensorTime = millis();
    Serial.println(" Level Low!");
    return true;
  }
  else 
  {
    return false;
  }
}

Schematics

Hardware Connection
Schematics of connecting the level sensor to the Genuino MKR1000
Capture oddcofvmaw

Comments

Similar projects you might like

DRS For Water Filtration System

Project tutorial by vincent wong

  • 1,689 views
  • 1 comment
  • 6 respects

Amazon DRS Promise: Never Miss Coffee Break Again!

Project tutorial by coffee-drinkers

  • 779 views
  • 0 comments
  • 3 respects

DRS Enabled Smart Pantry

Project in progress by Md. Khairul Alam

  • 7,410 views
  • 6 comments
  • 20 respects

Liquid Laundry Detergent DRS Sensor (LaundryBot)

Project tutorial by ArtSuzhou

  • 1,602 views
  • 0 comments
  • 4 respects

Amazon Dash Button for Arduino!

Project tutorial by Brian Carbonette

  • 9,829 views
  • 3 comments
  • 24 respects
Add projectSign up / Login