#161 Measuring weight using an ESP32, a strain gauge, and a HX711

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
retty youtubers here is the guy with a Swiss accent with a new episode around sensors and microcontrollers feeding our beloved animals is a rewarding job we do not want to forget it so let's build a connected scale which alarms us when the fruit bin is empty of course we will be able to use the same principle to measure the weight of any other good like the honey in remote beehives or even our own weight to visualize it somewhere in the cloud so today we will measure quite small weights with an Arduino like microcontroller we will need some tricks to do that then we will build a bowl for our cut which is capable to detect if no food is available anymore and we will send the Twitter alarm to our smartphone for measuring weight we need three things a sensor a converter to make its signals digitally readable and a microcontroller to control all the actions the usual way to measure weight is with strain gauges strain gauges are relatively simple devices thin PCBs or carriers with copper traces these PCBs are sensitive to all kinds of forces and change their resistance accordingly if we stick such a strain gauge on a metal bar and apply a force to one end the resistance of the copper traces increases or decreases depending on the direction of the force that's all in principle you can imagine that the distances these gauges are extended are minimal if the forces are small this is why we have to use some tricks but we are thinkers and engineers and we love tricks to make things work so the first trick is not to only place one strain gauge on the bar we place two or by the four of them on both sides of the bar trick number two is weaken the rod that it bends easier this can be done by drilling precise holes through the bar right under the gauges so with the defined force we get a bigger movement and trick number three uses these two or four signals from the sensors and combine them in an interesting manner it is called the Wheatstone bridge because Sir Charles Winston popularized this concept already in the 19th century its main advantage is its ability to measure resistors extremely accurate and it cancels temperature effects this is exactly what we need here so we combine our two or four gauges into such a bridge fortunately we can buy such devices with everything mounted and connected for a few dollars these bars are made for a particular weight for example four to five or even 40 kilograms and they are announced to be very precise the colors of the wires seemed somehow standardised red black green and white if your sensor has different wire colors you easily find which one is which if you search for the wires with the higher resistance between them these are then the opposite wires now we should be able to see very small changes in voltage if we bend the metal bar but these are really small voltages as we see here if I bend the bar quite a lot we only measure around two millivolt now we have a sensor to measure forces not weight Sir Isaac Newton also an Englishman and also a long time ago discovered a way to convert weight in forces and vice versa this is what we will use now strain gauges usually have threaded holes on each side I found one of them - a base plate and make sure it can move a little down for this prototype I use an old PCB which I found in my laughs then I mount a bowl on the top of the opposite side like that the sensor is spent a little if I put cat food into the bowl and we should be able to measure a voltage created by this bending force and now the star of this video enters the scene she is called dishka and is always hungry fortunately she has long hair so nobody sees her big belly but even if she is hawkish we have to measure her food in grams per day not in kilograms so our bowl has to be very sensitive and this is why we need trick number for a very sensitive and accurate analog to digital converter also called ADC and of course this ADC should not cost more than the cut itself because these days everybody is interested in measuring weight such ADCs are produced in extremely high series this makes it possible that we can buy a 24-bit ADC with a built-in amplifier for a dollar if we buy a few of them it's name is HX 711 cool we connect the top and the bottom wires in my case black and red to the E Plus and E minus pins and the other tool to a plus and a minus the B plus and B minus pins are not used here you could connect a second strain gauge now we only have to decide on the microprocessor and search for a library if we want to use an Arduino Uno we find a few libraries which work fine we only have to connect five volt ground clock and theta to the respective pins load the example sketch and are ready to go we already see some values and if I press the ball we see the values moving as always with scales we first have to zero the device and then we have to calibrate it using a known weight but wait we want it also to get a tweet if bowl is empty so we need a connected device and because the newest kid on the block is an ESP 32 I will use one of these new ports with an OLED display so let's check if the library works also with this new processor the only thing we have to do is to adapt the data and the clock pins to the pins of the ESP 32 I use pin 25 and 26 the HX 711 also runs on 3.3 volt so no problem the sketch runs like a charm but wait from time to time we see outliers not good what is the problem as always with intermittent problems finding the root cause is not easy but because we know that it worked with the Arduino Uno we can suspect that it could have to do with a higher speed of the ESP 32 speed is not always good if we look at the timing of the two signals we see that the shorter signal is a little more than 100 nanoseconds and if we look at the data sheet we see that this is too fast for the chip its minimum time has to be more than 200 nanoseconds usually we can add a few delays here and there to fix this issue not so here because the library uses the shift in command which reads 8 bits in a row without intervention possibility and here we have three shift in commands to read all 24 bits in a row so the easiest way to solve this problem is to slow down the ESP chip itself the ESP 32 is a very fast chip and we can afford to slow it down for this application slowing down the ESP 32 is quite easy just include a library and add this command at the beginning of the sketch then our ESP 32 runs with only 80 megahertz and the signal is now three times longer much better for the HX 711 now the outliers disappeared unfortunately the serial speed as well as the Wi-Fi communication is not influenced thank you expressive the whole prototype is based on the example file of the H X 711 library you find the links in the description next I make sure the OLED shows the values this is very comfortable even if the compiler warns us the library works with the ESP 32 now we have a nice setup to test the accuracy of our bowl the calibration commands are included in the sketch please uncomment it the first time you use it first this routine adjusts the sender to 0 and then waits for a defined wait to be added to the bowl at the end we take this number and divide it by the weight itself the resulting number has to be keyed in here because dishka is not interested in grams I use cat food for calibration I counted 50 pieces and enter 50 as a calibration value now the scale is ready to count the pieces and we can comment these lines the empty bowl really shows zero pieces and if I add one piece it shows one if I add a second I chose two and so on this is very astonishing for me first because the food pieces were really small and light and second because I did not do anything against electric interference in contrary I use much too long wires anyway the device is ready to show it to the country as with all models she had to starve a little before her appearance not to fit into the slim clothes but to be hungry enough to eat from this new bowl the next step is now to connect our ESP 32 to the Wi-Fi network and to add the pops up and qtt library which works also with the ESP 32 and because I already have a raspberry zero running mosquito and node-red I easily can connect my new cut pole with the system if you do not know how to set up a recipe for this purpose you can watch video number 126 because my bench light is also connected to my mqtt broker I could now switch my work light off for a moment if dishka emptied her bowl but we said we wanted to eat to achieve this we add an mqtt receiver note to note red and make sure it receives only the actual number of remaining pieces in the bowl then we add a switch note to make sure the tweet is only sent if less than 4 bytes are in the bowl a trigger which make sure the tweet is not sent too often and a Twitter note to connect to Twitter done now I get alarmed if port ishka is hungry and we can continue with her favorite activity catching a big stroke you see the curtain is already destroyed because we have to do this very often summarized we were able to build a connected pole for our cut dishka she never will be hungry again we learned that we can use thin PCPs with copper traces glued on a metal bar to precisely measure forces and weight that we have to use 2 or even 4 such sensors in a witson bridge to make sure we get the required sensitivity and also compensate for temperature drift that we can buy such ready-made sensors for a few dollars we can buy an accurate H X 711 module and connect it to either an Arduino or an ESP microprocessor because the timing was too fast for the HX 711 chip we had to slow down our ESP 32 fortunately serial and Wi-Fi still worked after that next we added MQTT to connect discus ball to my small home automation server fortunately the pops-up library also works with the ESP 32 and finally we added a new flow - no red to enable sending a tweet if the ball gets emptied now the cat is happy and we just have to print a 3d case I hope you are also happy and this video was useful or at least interesting for you if true then like bye
Info
Channel: Andreas Spiess
Views: 104,090
Rating: undefined out of 5
Keywords: cat, gauge, esp32, esp32 projects, esp8266 datasheet, arduino projects for beginners, boxing, esp8266, esp32 arduino, HX711, arduino, weight, cats, electronics, esp8266 projects, Strain Gauge, lorawan, strain, arduino tutorial, esp32 oled, esp32 datasheet, arduino project, eevblog, Strain gauges
Id: iywsJB-T-mU
Channel Id: undefined
Length: 13min 55sec (835 seconds)
Published: Sun Oct 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.