 Okay, so I'm using Google Slides. Seriously, this is the first time I'm using this. If I have any problem, I'm sure a lot of you here can give me tech support for it. Okay, hi. Thanks Google for hosting this event. Now I can say I made a presentation at Google. So my name is Leon. For those of you who never met me before, I'm kind of a maker. I do electronics, I do software, and I do designing as well. Okay, so today I'm going to talk to you about a project that I did called the IOT Smart Shelf. Okay, so what the IOT Smart Shelf does is basically it's a shelf that when I put my stock inside, it actually can sense how much stock I have and be able to update it on the internet. So how does this work? So this is, for those who don't know what I sell is actually a transfer media paper which comes in boxes like this. Okay, so one day I had this idea of, and what we were doing before that, we were always counting by hand. Okay, so what's the idea? The idea is very simple. The box is a fixed height. So I built a shelf with a known height. And I used an ultrasonic sensor. I put it on top. So based on how many boxes there are, the sensor is able to detect the height based on, because it knows the height of the shelf. So you know how many boxes there are inside. It's a very simple idea. So I think I'll be able to understand how it works. So the idea is actually very simple, but to make the actual shelf was actually quite challenging. And today what I'd like to share with you all is the journey that I actually went through to make the shelf. And all the different challenges I had along the way. So the first thing that I did was... Yeah, so I had to make a prototype first. The idea came about, but I don't know whether it really worked. So the first thing I did was I made a prototype made out of cardboard. That's the easiest thing to do. And what I learned from the prototype is that I cannot do too many boxes. Because these boxes, they're not really the same. They can be like maybe one or two mm different on each different box. So I found that when I hit 20 boxes and 19 boxes, depending on how it is, sometimes the 19 boxes and 20 boxes are almost the same height. So because I did the prototype, I knew that the max I could do was 10 boxes for the shelf. And that was the first thing that... So never ever jump in and make the entire shelf and you do 20 and realize that it doesn't work. So it's important that you do a prototype first and proof of concept. Then the next thing that really I had to do was space constraint. The most important thing. Where else am I going to put the shelf? So don't build a shelf and then I don't realize that it's too big. I can't put it anywhere. And so I used Adobe Illustrator to design the shelf. So I came up with quite a number of different versions of how I do it. And then I came up with kind of a modular concept of how to do this shelf. Which means that I just built one shelf and I put it one on top of the other. And the good thing about doing it this way is that I'm able to figure out how much wood I need. Because this paper is actually quite heavy. Each one of these boxes is about 1 kg. So one of these would be 40 kg. Not including the weight of the wood. So I had to use wood and not cardboard. It could not work with cardboard. So for those who have never seen the ultrasonic sensor. I have one here. How many of you have ever played ultrasonic sensors before? It's actually one of the most lousiest design stuff around. The biggest problem I had with this project was that how do I make this sensor stay on top of the wood? This was actually the biggest challenge I had. If you look around the internet, everybody used the ultrasonic sensor for one thing. That is collision avoidance. So you can find a lot of cases on Timiverse and 3D printed stuff that will make it go this way. You don't have anything that will make it go this way. So in the end what I did was I later cut a piece of acrylic so that I could put this and mount it into the acrylic like this. And then from this acrylic I can actually then screw it onto the wood. Because the holes here are so small you can't actually screw this on the wood itself. And the screws are actually very difficult to find. I cannot believe it. The smaller the screw, the worse it is. Actually it's very easy to find big screws but very difficult to find small screws. So I had to, I only could find a screw later at Linden Tower. So I had to do a bit of woodworking. So you cut a hole in the piece of wood and mount the sensors like this. From here, cutting a hole in a piece of wood is actually a very difficult thing. Cutting a hole in a piece of wood that looks like a square is a very difficult thing. Cutting a hole is very easy. So after cutting the hole, mounting everything like this. So this was actually the easier part. So the next biggest challenge which I think you guys will appreciate more because you guys are more hectares, right? This is more of a maker kind of a problem. So each ultrasonic sensor has 4 pins. And 4 pins I had 14 shelves. So 14 times 4 I had 56 wires to deal with. So that was a lot of wires. Okay, so some of them like you saw the first one where I had 4 shelves, 4 boxes together. There were 4 sensors and so alone then I had 16 wires really that was coming out. So how did I solve this problem? The good thing is that 2 of these is PCC and ground. So out of the 14 actually, 2 of them are in common. Out of the 16, 2 of them are in common but I'm still left with 8 wires because there's a signal and echo. So no matter how I get 8 wires left for 1 shelf. Okay, so how did I solve this problem? So I had to go and make sure that it worked first. And basically that was the problem that you get with 56 wires to try and make sure that your 14 ultrasonic sensors will work. And that was quite a nightmare. So obviously we can't actually deal with this at the back of the shelf. That was the biggest problem I had. And so the solution was to make our custom circuit board. DIY circuit board. Everyone knows about. Okay, for those who don't know I'm the DIY circuit board man. So with this what I used is that I used an Ethernet cable. Ethernet cable had exactly 8 wires. So this would make it into one single wire. And then 2 more here for VCC and ground. One Ethernet cable and then 16 wires from the ultrasonic sensor will go in. So in the end I only need to bring 2 wires down into the Arduino, the main controller. And then on the Arduino we will have the second DIY circuit board which brings in 4 Ethernet cables and rock everything into the mega. So from just now that this bus here I'm able to make it into that. Because I can make custom circuit boards. So all of you should make custom circuit boards. That's your next question. So yeah, actually I really want to bring this board because I solved so many problems because I could make DIY circuit boards. Something like this is a very big example. Alright. So then next came the problem of the software. So the software there was a bit of when I was doing the prototype there was one thing that I noticed about ultrasonic sensors. This thing is cheap right, it's like $2. So you can't expect them to be super duper reliable. And the problem that they would give suddenly wrong readings. So my prototype when I was doing the prototype it was sensing correctly then all of a sudden it will give you a wrong value then it will be correct again. That was when I realized that they can sometimes give you a spike and just a wrong value out of nowhere. So out of 10 values sometimes they give you 9 correct and 1 is wrong. So if you are unlucky you take that wrong value, you get a wrong reading or number of boxes. So the logic of my software was that first you calibrate each sensor to the height of the shelf because the shelf is made to a certain height. But the sensor will read a different height, it's never correct. So you take the height that the sensor reads minus or what is the theoretical height of the shelf and that gives you an offset. So every single sensor has a different offset and this has to be stored in the e-form. So when the Arduino boots up it will read in all these different offset values. And you cannot depend on one reading. So what I did in the end was that every time I read the ultrasonic sensor I read 5 values. I take the maximum and the minimum value and this maximum minus minimum is less than a certain threshold. I know that they are all about the same reading and this reading is accurate. If I have a sudden spike that means the maximum minus minimum will give you a very big difference. And that tells you that this 5 readings is one of them is wrong. Let's redo the reading again. And the other thing was that I realized that I should not actually measure the top of the box. At first I measured the top of the box which is here. Later on what I did was that I measured the center of the box. So I know the height of the box. So I take top of the box minus height of box divided by 2. And then I have a threshold which we think that if it's slightly more or slightly less that it's correct. Because if you take the top right you don't actually compensate for both directions. But you take the center you can compensate for both directions. So this was the logic that I did in the end. And this works actually very well with the in the end. So far I have not really got a wrong reading yet. Sir, how do you read the center of the box to be able to understand that it will be reflected by the top of the case? Not like you can. How do you get some place to... No, you take the height of the box. You read the top value and then you minus off the height of the box divided by 2. It's just a theoretical... It's theoretically it's supposed to read the center. You're not really actually reading the center. You could also take the top and put 2 threshold on the top and bottom. But I found that having it this way was easier to understand for me. So what you're saying is you can also use the top and then you have the threshold top and bottom. It will also work. What's the accuracy of the center of the case? By right they say less than 1 mm. I'm not wrong. By left, no. I found that anything lesser than this height can be a bit difficult to really maintain a good. If your box is very thick, it's very easy to get it on. But if your box is... this is probably the minimum that you can go with. Half of this is very difficult to get a correct reading every time. So of course you have all these sensor readings coming in. You need to put it somewhere. So that's when I came up with the IoT concept. So another custom circuit board here. Putting the VHP8266 on it. So this will send it up into the cloud. And from there I am able to know how much stock I have real time. So this custom circuit board basically just... This gives you the power to all the ultrasonic sensors. And then one regulator to bring it down to 3.3 volts for the ESP8266. And then a couple of LEDs for your debugging purpose. So I know what the shelf is actually doing. So in the end this is actually how it works. So the IoT shelf and the ESP8266 reads everything. Goes up into digital ocean. I use the PHP script to actually pull in the values. It updates the MySQL database. And then I have another web app that actually pulls it from the MySQL database. And I am able to see how much stock I have. So this is the finished product. It's actually quite big. It's about this high. So we have 6 shelves at the bottom and 8 shelves at the top. Total of 14. This is the back. This is actually how I mount it on. And this is the inside of it. Here we have 6 boxes of paper. No, that's why you maximum you put 10. You should not hit it. Not so easy. Because if you carry 10 of this, it's already your most tank age. So typically you are carried and straight away you put it on. The shelf when you push it in. There was... Does the exact number matter? Would it not be enough to know and give the shelf to all of the world? Oh no, the number matters. Because we sell our boxes, if let's say a person wants one box, we need to be sure that there is one box there to be sold. So these people are quite expensive. So everyone counts. Yeah, but if you've got an accurate calculation of what the volume of the shelf goes by... Sorry? If you've got an accurate read on... This is the volume of the shelf. Look if you can get the calculation of that shelf. Yeah. Sorry. You're not going to get that long. If you're reading, we can go up and put it through. Sorry, I don't quite get your... It doesn't seem like you've ever been in a situation where you thought you had stopped it. Where I stopped and I did not have. When you thought you had stopped, you didn't have. You might be off by like one box. Yeah, you won't be off by more than one box usually, but it can be a big factor for us if we are off by one box. Because it's like the ordered five boxes, we check there's five boxes, but in the end if there was four, then we'll be in trouble. How are you making the precinct? These other 10 are coming for what you thought you'd be able to run out of. Well, that is a very long answer. Next question. So you have to check the previous view. Yeah, I actually gave a talk on that before. Or you can find me later again. You can go to my blog. If you go to... Yeah, so over somewhere at the bottom. Over here we can have the... I do have a guide on it. I will just show you. The last one is that this is actually where everything goes. So, all the different stock, if you look over here, it will tell you on the shelf how many in the warehouse, how many. You were saying that the boxes are a little bit different, I guess it's really just a big hack of them. They're all completely the same. Do they weigh the same? They're all the same weight? They're not the same weight. Because some of them have 50 sheets, some of them are 100 sheets. But the same product has got a known weight, right? No, no. Because each one of these... The same package? Oh, the same package, yes. Well, it should, right? Yeah. I know the number one question everyone asked me is why don't I use a weight sensor? I found that it's actually more difficult to mount a weight sensor. Let's see if they would have the... 50 boxes. So far, no. Thankfully, yeah. Given that why you're reading was such a big endeavor of this. The way this works is that you apply the positive or zero to the trigger and then you get back positive or zero on the echo pin, right? Couldn't you fan out all the trigger pins instead of connecting to the trigger pin of each sensor directly? You're saying trigger all of them at the same time as it? Yes. You still have 56 wires. You still have to have one pin in there. You still have the same number of wires. For me, what I'm going to improve in the next version is that instead of using an Arduino mega, which was a shortcut way for me, that I would use multiplexers in the next version to reduce the number of pins that I need from the microcontroller. But in terms of that, you still need each ultrasonic still needs to have one wire go in for trigger. Right. So you don't need to connect them to microcontroller. Is that correct? You still... I mean... Okay. I think we can discuss the integracies later. You can catch up with Leon at the end of the session. Yeah. This is just my contact info.