Mohammad Haizad
Published © GPL3+

DRS Oil Container

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

IntermediateShowcase (no instructions)20 hours1,843
DRS Oil Container

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Jumper wires (generic)
Jumper wires (generic)

Software apps and online services

Arduino IDE
Arduino IDE
Amazon Web Services AWS SNS
Amazon Dash Replenishment Service
Amazon Web Services Amazon Dash Replenishment Service


Read more


Hardware Connection

Schematics of connecting the level sensor to the Genuino MKR1000



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 

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

AmazonDRS library

Arduino json library

Arduino ultrasonic library

WiFi101 library


#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() {

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

  //Start up DRS
  //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!            
            Serial.println("Buy new");
          Serial.print("Sorry, slot ");
          Serial.println(" is not available at this time");


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


Mohammad Haizad

Mohammad Haizad

2 projects • 3 followers
Graduate student in Electrical & Electronic Engineering


Add projectSign up / Login