First of all, my name is Joe Carlson. You probably don't care about me at all. That's fine. But I'm a software engineer and developer advocate and I work for a company called MongoDB. You may have heard of it before. It's a pretty cool database product if I do say so myself. If you are wanting to hang out with me ever again in the future, please do so. Best place to do that is on Twitter. But if you're on TikTok too, you should for sure check that out and make funny videos about programming over there. If you want to follow any of the links, source code, recording of this video, slides, code samples, all that, you can find that on the link there. JoeCarlson.dev slash IOTkitty slash BF04B or if you scan that QR code in the upper right-hand corner of the video, that will also take you there. Lastly, and this is very important, but anything I say in this talk reflects my own views and not the views of my employer. All right? Cool. I love my job. I don't want to get fired.
Okay, so what the heck is IoT? Well, I'm sure you already know, but it's basically anything that connects up to the internet. It's just a thing with a chip on it that has Wi-Fi or Ethernet or whatever, right? It just can connect up to the internet. But I want to talk about my particular interest in IoT. I think that us as engineers, we are particularly well-suited for exploring tech and the internet as a medium of art.
I think the internet is the defining thing that has shaped who we are as a generation, how we behave, and I think that there's so much room to explore that area. And I love doing that through art and tech. In particular, even more niche, I'm obsessed with stupid shit. I love putting chips in things that they should not, they do not belong in. I think it's fun exploring that fine line between just genius and complete stupidity.
In fact, I love it so much, I ran a hack-a-thon called the Stupid Shit and Terrible Ideas Hack-a-thon, which we just made stupid stuff. Like someone made a camera that only takes photos when you shake it, or a six-foot wooden fidget cube, or laptop made out of cardboard. Fun stuff, right? I love stupid shit.
4. Data Considerations for IoT Projects
When building IoT projects, it's important to consider data considerations and choose databases that can ingest data quickly. IoT projects are write-driven applications, so the ability to write data concurrently and massively is crucial. Flexible schemas are well-suited for IoT projects, allowing for easy updates and adjustments. MongoDB is a great choice for IoT projects, as it handles time series data well and allows for schema validation on a database level. If you're considering MongoDB for your IoT project, it's worth exploring its capabilities.
So I do work for MongoDB and I do need to talk a little bit about data considerations if you're building IoT projects. So I want to talk broadly about what to look for when you're building out or you're looking at databases to save IoT data.
Okay, so first of all, you want to make sure you're looking at databases that are able to ingest data quickly, right? IoT projects are unique in that they are write-driven applications. Most applications that are web-focused are read-heavy, right? Like I write one tweet to a database and it could be potentially read by, you know, millions of people. None of mine are. But if I was that famous, like maybe it could be. But you want to make sure you're looking at databases with different needs, right? And being able to ingest or write data concurrently and massively is extremely important for an IoT database.
We mentioned earlier that a lot of IoT projects are event-driven, right? We're waiting for some asynchronous event to happen out in the field and we want to make sure we have a database that matches that event-driven nature of our IoT projects. Flexible schemas are uniquely well-suited for IoT projects. For example, on my project I built a... I added a new sensor and I was able to update my time series data to include that new sensor data. Time series data is unique in that it gets stale really quickly, and you're typically using it to visualize on some sort of dashboard. Maybe we're using it for historical uses as well. As we're adding and upgrading over time, we can start adding and adjusting our schema flexibly at scale.
I do want to note here, it's a common misconception that MongoDB is a schemeless database. You can actually validate schemas on a database level with MongoDB. You don't need an ORM like Mongoose. And you want to make sure you have a database that handles time series data well. You can make a time series data with most RDBMSs, cool, not a problem. But it does get messy really quickly. I'm going to show you my IoT time series data I used for my project and why I think it's superior to other models. So, I may be biased here since I work for MongoDB, but MongoDB is a great choice because it does all these things and more. So, all I have to note is that if you're looking at using a MongoDB or IoT project in the future, you should definitely be considering MongoDB. All right, sales pitch is over, let's get back to the good stuff. IoT key litter box, let's jump in. This is actually what I ended up building. It's a little mid-century box I bought. I know it's extra. You don't need to get something fancy like this. You could get a $20 plastic thing on Amazon or whatever, as long as it's got an enclosure and can use cold litter, that's all you need.
5. Robot Kitty Litter Box and Asynchronous Events
This robot kitty litter box exists, and it works by using load sensors underneath the box to detect a cat-sized object entering. Once a cat is detected, its weight is measured and recorded in a MongoDB database. After the cat is done, a new base weight is initialized, and the process waits for a new event. The project involves waiting for asynchronous events to occur. The first step in any IoT project is to make an LED to ensure the circuits are set up correctly.
I thought this was a dumb idea, but I recently found out this robot kitty litter box exists. Wired gave it an 8 out of 10 and, more importantly, they're selling it for $500. I'm not trying to monetize this, but if you wanted to, this might be your chance.
How does this thing work? I have load sensors underneath the box. They're basically like an internet-connected bathroom scale. Let's get to the other part first. We have an enclosure on the box and there's a switch on it to determine when it's open or closed. When we open that box, we're going to something I call maintenance mode. We're either removing waste or adding litter to the box. The point is the base weight of that box changes every time it goes into maintenance mode. Once I've cleaned it up, done my work on it, close it back up again, it leaves maintenance mode, waits for it to chill out a little, then we reinitialize the base weight of that box.
After the base weight of that box has been determined, what we do is we wait for a cat-sized object to enter the box. Now I don't know if that's an opossum, a raccoon, or a large rat. It doesn't really matter. We're just waiting for something that's around 5 to 15 pounds to enter that box. Once a cat has been detected by the load cells, we wait a little bit for the cat to settle. Then we take a measurement of that cat's weight, so I can passively measure the cat's weight over time, and we record a bathroom event having occurred. So it does its business, and we fire that event off into a MongoDB database in the cloud.
Alright, cool, so the cat's done its business. What we do is wait for things to cool off a little bit, I wait like 5 minutes, and we reinitialize a new base weight of the box, and we wait for a new event. Either that's a maintenance event, or a new cat entering the box event. Alright, so there are all these asynchronous events that we're just waiting for to constantly occur. And that's it, it's pretty simple. Let's jump into some code, though, huh? Let's speed a little code, guys. If you want to follow along with any of the source code, again, all that code is available at that link, or if you scan that QR code with your phone.
Okay, so the first step for any IoT project, if this is your first IoT project, the first step you need to do is make an LED. LED, blank. It basically just makes sure that your circuits are set up, your board's fine, you're able to communicate it and make it do what you want. And just like programming, we iterate on that and build. So you can see actually I have the load cells staged up next door or next to it over there.
6. Controlling LED with Johnny-5
To make the LED go on and off, we use Johnny-5 with the Raspberry Pi package. We initialize a new Johnny-5 board for Raspberry Pi, wait for it to be ready, and then initialize an LED on the 13th GPIO pin. It only takes a few lines of code to get our hello world working.
And I'm just making that LED go on and off. That's it. Okay, so how do we do that? With Johnny-5, it's pretty easy. Johnny-5 works with a lot of different boards. So we need to import the Raspberry Pi package. And we reinitialize a brand-new Johnny-5 board and tell it, hey, your input-output you're going to be dealing with today is in fact a Raspberry Pi board. All right. And then we wait for that board to be ready to start listening. And then we just initialize a brand-new LED on the 13th GPIO pin. I don't know what that is. I got to Google it every single time I hook it up. And then it just has a built-in function that says blank. But that's it. What is that? That's like, I don't know, less than 10 lines of code to get our hello world working for our Johnny-5. So pretty simple.
7. Making an LED into a Toilet
To make an LED into a toilet, we use a Raspberry Pi board and a magnetic switch to determine the box's maintenance mode. Depending on whether it's open or closed, the state of the box can be changed. The Raspberry Pi reads the events in real time, making it a simple process.
OK. So how do we make an LED into a toilet? Good question. We need to do the same thing. We're going to bring in that Raspberry Pi board, and instead of bringing an LED, we're going to be using a magnetic switch to determine if that box is in maintenance mode or not. And then just depending on the state of whether it's open or closed, we can change the state of the box.
OK, so let's see it in practice. I'm going to show you the board or me doing it. And you can see the little switch there, that little white thing. That's the magnetic switch. There's one on each side. And as I open and close that box, you can see that those events being read in real time by my the Raspberry Pi and determining what state the box is in. Pretty, pretty simple.
8. Solving the Load Cell Problem
I had to get creative with solving the load cell problem since I couldn't find a library with Johnny-5 to interface directly with the load cells. Instead, I used the Spawn Child process in Node Core to run a Python script and send the data to my Node program.
9. IoT Data and Box Assembly
Every tenth of a second, the base weight of the box is read and sent. Real-time registration of weight changes is possible. IoT time series data is stored in a MongoDB database, with new documents created every 24 hours. The events array captures cat entries and box cleanings, designed for easy reporting. Box assembly involves mounting the Pi and connecting wires.
So every tenth of a second, it's just reading the base weight of the box and it sends it up. I convert it into a float, update the average, and then I just keep waiting for that cat-sized event to happen.
All right, so let's take a look at it. Underneath that piece of plywood, I have the load cells in each corner. And it's hard because I couldn't get too far enough away, but I'm pressing on the board. And you'll see here in just a moment, those presses are being registered in realtime on my Node application. So I'm able to register and see in realtime what's happening or, like, the weight of the box at all times.
Okay, I promised you I would talk about my IoT time series data here. And I'm still going to follow through with that promise. So this is what it looks like. Every single 24 hours, I create a brand-new document in my MongoDB database. And in there I have some metadata about me and the cat in case I wanted to scale this up to multiple boxes and cats and owners. And I have an events array. So in my events array, every single time a cat goes in the box or I clean the box out, I add a brand-new document or subdocument into that events array. I designed it this way because of how we use it, right? I'm reading this data to display on a dashboard. And I want to show all the events per day of what's happening. So I designed my IOT schema to be easily read for my reporting that I'm doing on this. Which is, like, the number one rule of MongoDB schema design. Just design your schema based on the needs of your application. How are you going to be using that data? And this was how I'm going to be using it. You can do this, like, once a week, once a year. But for a little box like this, it makes sense just to do it once a day.
All right, cool. So box assembly. I put the whole box together. You can see the Pi mounted on the inside there. I got some wires. And I got a little wire to plug it in. And that's it. It's pretty simple.
10. The Future of IoT and How to Get Started
You know, it doesn't look elegant when you open the box up. But it works. It looks pretty good when it's all closed up. And there's my cat. I had to bribe him some treats to get this photo.
11. Conclusion and Poll Results
Don't worry about monetizing or making something professional or cool. Explore and share your projects. Connect with me on Twitter at Joe Carlson1. Thank you all for being incredible. Let's discuss the poll results: 50% have no experience with IoT, 34% have a little experience, 16% have made a project, and 0% work full time in IoT.
I think don't worry about having to monetize it or making something that's professional or cool. I think it's fun just to explore and see what you get. And try to share it if you can. I love seeing that stuff. I'd love to see what you work on.
Okay. I'm in the chat if anyone has any questions. Otherwise, you can definitely hit me up on Twitter at Joe Carlson1. And, yeah, I would love to connect with you anyway, even if you don't have questions. All the links for this talk, video slides, code samples, everything, available at the link there or if you scan that QR code.
Thank you so much, everyone. You've been incredible. I've had a blast here. Bye.
Now let's discuss the poll. The question is, what's your experience with IoT? Not judgments. Just curious. None said 50% of them says none. Just interested in potentially getting into some day. A little. With 34%. A little I have made a blank one time. 16% responded I have a couple of projects under my belt. And 0% said I do IoT work full time. Nobody does it full time. But most of them have. That's about what I expected. That's about what I expected. I mean this is a gentle introduction to Internet toilets. I hope too even if you have been a master maybe still learn something new.
Cool IoT Projects and Small Experiments
But you know this is a great time for newbies. That's great. Awesome. Let's go to the Q&A. Tell me about some other cool IoT projects you have been working on. I recently made the magic mirror project, which involves putting a monitor behind a two-way mirror and hooking it up to a Raspberry Pi. I also made my own internet-connected nano leaves using a 3D printer and LEDs. Another project I worked on was a digital graffiti board that allows people to draw on it using their phones. If you're new to IoT programming, I recommend getting a Raspberry Pi and experimenting with making an LED blink or creating a web app that translates text into Morse code.
But you know this is a great time for newbies. That's great. Awesome. Let's go to the Q&A.
Practical IoT Projects and Conclusion
If you're just starting out with IoT, it's best to do what you know. There are many practical and everyday IoT projects you can explore, such as network-wide ad blockers and network attached storage. You can also create art projects or simply experiment with raspberry pi beginner projects. Join Joe in his speaking rooms on Spatial Chat for more discussions.
Yeah, I think everybody that starts with IoT, they always start with the roster by it's like most common and yeah, so. Oh, totally. And like you couldn't get into it like I've gotten into the more advanced embedded chips and smaller things and whatever like cool but like if you're just starting out, why make your life hard just like do what you know, you know, I agree.
So, the question is, in your opinion, what are some other practical or everyday IoT projects that you've come across. Um, I mean, anything that has a chip in it. I personally like there's a ton of amazing cool private projects out there that are IoT projects like my pie hole is one of my coolest things I've I currently use I didn't make pie hole, it's like a network wide ad blocker works at the DNS, which is super cool. I made a NOS or network attached storage with raspberry pi's which is cool. Little art projects. The point is that you can make practical things for your home, you can make dumb art projects, you can make useless stuff. It kind of depends on whatever you want to do. Just give it a Google like raspberry pi beginner projects, you're going to find a bunch of cool stuff to make. That's a great advice. Thank you, Joe.
So it seems that we don't have any more questions, but please join Joe in his speaking rooms on Spatial Chat. The link to join is on the timeline. Thank you Joe. See you later. Thank you. Bye.