Details of how to use this device with the platform IFTTT now included. This provides a quick and simple way of setting up mobile notifications.
Hi, thanks for taking the time to come and have a look at my instructable. It has been super fun undertaking this project, in making it I have learnt so much and, I hope in reading this you might learn something too.
Through my girlfriend I was introduced to the food sharing app OLIO, an amazing initiative whose goal is to reduce food waste through peer-to-peer food sharing. Check it out and spread the word. With food waste on my mind and the IoT Builders competition here on instructables, I decided I would try and create something that could help reduce food waste.
What I have come up with is essentially a WiFi enabled weighing scale. The device is configured to IBM's Watson IoT Service and from there the data stream is sent through a Node-RED flow to visualise the data.
How can it be used?
This device is not limited to combatting food waste, it can monitor just about anything. A few examples of what you could keep track of:
- the amount of milk in the fridge
- any food in the kitchen, never buy something you don't need again!
- the weight of a plant, so you know when to water it
- medication, so you can know when an elderly loved one needs to order more
- keys by the door of a student flat, so you know when your friends are home
The possibilities really are endless, if it can be weighed and its weight changes, this device could be very useful.
Step 1: How Does It Work?
I am an architecture student, not a computer scientist and as such this project has been a steep learning curve. I'm sure there are a great many ways of creating this project, perhaps more simple ways too. I have tried to keep the project as simple as possible. This project handles data in this way:
- Node MCU ESP8266 receives data from the load cell via the HX711 board
- NodeMCU connects to the internet via WiFi and sends data to Watson IoT Service
- Node-RED receives data from Watson IoT Service and visualises the data
- Data can be accessed from anywhere at the url https://iot-scale.mybluemix.net/ui
What are all these things?
- NodeMCU ESP8266
The easiest way to describe the NodeMCU ESP8266 is that it is an incredibly cheap "Arduino-like" development board which has WiFi built in. I paid just £3.91 for mine on eBay. Best of all you can program it in the Arduino IDE.
- Load Cell
This is simply a bar of aluminium with two holes drilled at the centre - when supported at one end and with a load applied at the other an analogue reading is produced.
- HX711 Board
This is an amplifier which converts the analogue reading produced by the load cell into a digital one readable by the NodeMCU ESP8266. I bought the HX711 and Load Cell together for £3.42 also on eBay.
Node-RED takes a lot of the work out of IoT. It requires a much lesser understanding of programming and languages since it is visually based. It is exceptionally easy to link your project to Twitter and send tweets or link your email account and send an email from it.
- IBM Watson IoT Service
An online cloud service that can securely host you IoT project. Basically in this project the sensor data is sent to IBM's Watson IoT Service where it is received stored and sent on to other places on the internet.
Step 2: What You Will Need - Materials
This project requires very little in the way of materials. They are as follows:
- NodeMCU ESP8266 link
- HX711 Board and 5kg Load Cell link
- Slide switch equivalent link
- Dupont cables link
- HTC Cell phone battery link
- 100mm x 100mm x 27mm of Oak (you can use equivalent hardwood)
- Sprung 4 point contact (I salvaged mine from an old printhead)
- 2 pieces of translucent acrylic 100mm x 100mm x 7mm
- 2 x M4 countersunk machine screws 18mm long
- 2 x M5 countersunk machine screws 18mm long
- 2 x M4 pan-head bolts 15mm long
- 6 x M5 washers
- 2 x M5 nuts
My brother had an old HTC cell phone lying around that didn't work anymore hence the battery being used in this project. I am still able to charge the battery using the old phone. If you were to buy the above battery make sure you have some way of recharging it.
I was lucky enough to be able to find the acrylic and oak in the waste bins at my university workshop. I also had a scrap printer lying around from which I salvaged wires, a switch and a spring contact. I also already had most of the nuts, bolts and washers. Altogether I spent around £10.
Step 3: What You Will Need - Tools
I am really lucky to have access to very well equipped workshops at university and before I left for the Christmas break I used a CNC router and Laser cutter. However, you could still achieve this project without those specialist tools. Tools I used were as follows:
- CNC router
- Laser cutter
- Bench-top disc sander
- Cordless drill
- Drill bits, various sizes
- Needle files
- Sand paper, various grades
- Wire cutters
- 2 part epoxy, Araldite or equivalent
- Super glue
This list is not exhaustive but the main tools I used are listed here.
Step 4: The Chassis
- CNC Router
As mentioned earlier I used a CNC router at uni. This is how I made the main enclosure of the device. I have attached the tool-path should anyone want to replicate the piece. I used a 4mm straight router bit.
(At this stage I hadn't completely designed the whole device, it would have been great to have routed out the battery bay and slots in the base. Instead I did this at a later stage with a jigsaw for the battery bay and a drill and needle files for the slots.)
With the CNC router I only marked the perimeter with a 4mm deep cut rater than cutting the entire depth the whole way around. This was because the CNC router is quite slow. I cut the waste off with the bandsaw.
- Disc Sander
To round off the corners I used a disc sander
Step 5: The Internal Workings
The diagrams above should provide sufficient information on what to wire where.
A few things to note:
- The load cell should be mounted from the end with the M5 holes. Mine had a sticker showing which way up it should be mounted. I placed 3 M5 washers between the oak chassis and the load cell to give extra space under the suspended end.
- Make sure nothing ends up under the suspended end of the load cell.
- Watch the height of the dupont cable connectors. Bend the pins of the NodeMCU ESP8266 if necessary, you don't want them to touch the underside of the weighing pad.
- I mounted the NodeMCU ESP8266 upside down, this meant I could attach cables more easily. It also means you can reset the module using a pin through a small drilled hole in the oak chassis.
- Using some very small screws you can secure the NodeMCU ESP8266 and the HX711 to the oak chassis through the pre-drilled holes on both the boards.
Step 6: The Base
Since the battery is rechargeable it was necessary to make it easily accessible. The base is made up of a rounded square piece of acrylic with two pan-head machine screws which protrude the thickness of the base of the oak chassis. These two screws slot in to two key hole slots cut into the base of the oak chassis and slide across to secure the base.
To make the key hole I drilled a 5mmØ and a 3mmØ hole a centimetre to one side. I then used a round needle file to connect the two. You can see the base being removed in an earlier video in the instructable.
Step 7: The Top
The weighing surface (top) is pretty much the same as the base. It is also made from 7mm thick acrylic. Two holes are drilled and countersunk to line up with the load cell mounting holes. These countersunk holes then receive two M4 countersunk machine screws which are 18mm long. It is important they are countersunk to ensure a flat weighing surface.
I placed two M5 nuts over the load cell holes to allow a gap between the underside of the weighing surface and the load cell bar. Place the acrylic on top and tighten.
Step 8: Hardware Is Done
Great, we have finished our hardware. Now time to get the software up and running.
Step 9: Software
Download the two .ZIP files. Add the pubsubclient library in the Arduino IDE by going to Sketch>Include Library> Add .ZIP library...
You will also need to add the NodeMCU ESP8266 board to your Arduino IDE. I found this instructable to be very informative and useful in getting started with the Arduino IDE and NodeMCU ESP8266 link.
Open the Arduino sketch and edit the following:
#define WLAN_SSID "your_network_name" //Put your SSID here
#define WLAN_PASS "your_network_password" //Put you wifi password here
You will also need to edit the following 4 lines however you won't know your relevant details until the next part of this step (configuring your IBM Bluemix device):
#define ORG "your_organisation_ID"
#define DEVICE_TYPE "your_device_type"
#define DEVICE_ID "your_device_ID"
#define TOKEN "your_token"
The first thing you need to do is go and sign up for a free trial of IBM Bluemix link. I figured a screen-shot series (above) would be the best way to describe how to configure the online portion of the software. Follow that and once you know your organisation_ID, device_type, device_ID and token go back and edit the Arduino sketch.
Another thing you will need to do is to add the Node-RED dashboard so that you can use the "gauge" node. Instructions are included in the screen shot series.
You will find that the number you get is wrong, i.e when nothing is on the scale it doesn't read 0. Find the line of code in the Arduino sketch:
valCalibrated = (val - 4137240) / 234.20;
Start by substituting this line with just "valCalibrated = val" take a note of the value arriving at the Node-RED debug window. Let's assume that value is 2500 for example. Re upload the sketch with this line:
valCalibrated = val - 2500;
Now you need to work out your scale factor. Place a 100g weight on the scale. Note the number arriving at the Node-RED debug window. Let's assume it is 1500. Since this is the value for 100g our scale factor is 100 times smaller i.e. 15
valCalibrated = (val - 2500) / 15;
A video which really helped me understand calibrating a load cell can be found at the following link
Upload the sketch for a final time. Now go to yourappname.mybluemix.net/ui you should find a nice looking gauge with a live feed of data coming from your IoT Scale. Well done!
Step 10: Use It
Put something on the scale and keep track of it from anywhere you have an internet connection. Any problems at all please leave a comment or message me. Hope you have enjoyed this instructable.
Step 11: Appendix
My original intention was to make the weighing scale pad from concrete, not acrylic as shown. I love the combination of concrete and oak. However, the maximum thickness I wanted to cast it at was too thin and the strength was compromised. I thought it looked pretty and it took me a lot of time to make so I thought it deserved a picture.
At the beginning of the project I was hoping to host the Node-RED flow myself on an Ubuntu server I made from an old laptop. This instructable helped me a lot in doing that link. I then managed to run Node-RED from it after following this tutorial link.
This all worked great on the local network however I couldn't get it to work consistently remotely since I don't have a static IP address. In the end it worked out much better doing it through IBM's platform.
Step 12: Update 2018
In November 2017 I was approached by a fellow instructables member. He runs a home distillery and was looking for a device to keep track of the receptacle collecting the alcohol. He told me my device was the only thing he could find that met his requirement, so he commissioned me to build him two.
Because I was now selling the scale, I decided to make a few small changes that would ensure the device was a bit more durable and easier to use. Firstly there was no need for the devices to be battery powered and as such they now just run off a 5v usb mains socket. This is supplied via a micro usb port (the black protrusion). The biggest change is the way the data is handled.
Using the platform 'If This Then That' commonly abbreviated to IFTTT, makes the process much simpler. I made a Webhooks applet that when triggered sends a notification via the IFTTT app to the user's mobile device. This 2 minute youtube tutorial is all you need to know to make this work.
I have provided the code used to make this new way of handling the data. There are four bits of information you need to change to get it to work for you. 1. Your Internet SSID 2. Your Network Password 3. Your IFTTT key 4. Your IFTTT Webhooks event name. You will also want to change/add conditions for sending a notification. The example I have included will send a notification every 10 seconds if the weight is greater than 400g.
One more thing to consider is the calibration of the scale. Details of how to do this is included in previous steps of this instructable.
Again if you have any questions, please leave me a comment below. Thanks!