[00:00] If you had one superhero sense, what would it be? Now Superman can shoot lasers out of his eyes. But can he turn on your lighting automatically? [00:15] Dr. Horrible can create a freeze ray and turn things to ice. But can he control his thermostats using Wi-Fi microcontrollers? And I'd say something about Deadpool, but he's a Welshman, so he's perfect. [00:32] This video is designed to introduce you to some unbelievably powerful yet super-cheap components that you can master to give you superhero powers. [00:45] If you want the powers of heat, motion, light, sound, air, moisture, road and much more, then you really need to watch this. [01:10] I want to give you a short, sharp introduction to all of these senses so that you get that tingle of excitement of what you could accuse. I'm not going to be overly laborious, [01:23] and this isn't meant to be a spoon-feed tutorial for each. Because there's masses of tutorials and guides already out there on all of these. These components are constantly getting upgraded. [01:36] So what I want to do is give you a sense of how accessible this stuff is now. I want to give you the component names to then Google. This is actually half a secret. Once you know that such a thing exists, [01:50] as a temperature sensor, and it's called a BME 280, where are you, my little lovely, then it's actually pretty easy to just Google BME 280 and get a detailed guide and videos on how to do everything [02:05] on whichever chip that you're using. I'll start off fairly slowly to talk you through the process, and by the end, I'll just be flying through at a high level, and by then you'll be able to think for yourself. [02:17] I'll assume a few things. One, that you have home assistant set up. If you don't know what this is, then watch my other videos. You really need to get it set up. [02:29] Secondly, you should have an ESP32 chip and at least one of these sensors, because, well, that's what this whole video is about. Other than that, you just need to pay attention. Quiet down there at the back. [02:46] Now, there are many variations of ESP42 chips. Some have cameras, others have LED screens on them, and you can use these when you get a bit more experienced, but I'm going to use a basic one to keep things simple. [03:02] Let's start by getting the ESP chip running. Two things. First, plug it in. That's it. You've completed the first step. I'm being flippant but I want to stress throughout this how easy this stuff has become. [03:17] This little chip is packed with useful components. It's Wi-Fi enabled, Bluetooth enabled, ultra-low power consumption and it has a surprisingly nifty little processor. What this means is that you've just created a standalone device that you can put anywhere [03:34] in your home. If you think what room you have a plug or USB socket in, well, it's kind of everywhere, isn't it? And even if you wanted to attach a battery or solar panel, then the ultra-low power consumption makes these very effective and they can last a long time. [03:51] So what we have now is a little microcontroller that's running happily away, but it's doing nothing. The rough equivalent of a PC that you've built and turned on, but there's no operating system. So the next step is to install ESP Home. [04:06] This again is super simple. Visit this page. I've put this link in the description as well. Then click ESPHome and follow the simple instructions. This installs ESPHome as an add-on to Home Assistant. [04:20] This is a central hub for all your ESP chips. It doesn't just handle installing code the first time, but it enables Wi-Fi connections which then allow over-the-air updates. [04:33] So, you can have 20 devices in your house, and if you change some of the code, you can just click to install instantly to them all. You can also write code and debug it, validate code, check the logs, [04:47] really everything that you need. We've now got a super powerful help for our devices and a chip running away mindlessly. What we want to do now is connect this chip to the hub [05:00] and install a basic operating system to it. Once you've got your cable connected, you can just plug it in and click through Add Device in USB Home, and it should take you through the steps. [05:13] Clicking Connect should pop up the USB port selector, and you can select your device there, and then you're away. It steps you through the process of installing the initial OS on the device, like naming your device. [05:27] Once this is done, your device will be connected to your home Wi-Fi automatically, connected to your home assistant, and ready to rock forever more. You can disconnect it at this point if you want and all the updates you make will be done over the air So we have now in a matter of minutes set up ESP Home the active central hub for endless devices and connected your first ESP32 and installed the basic software [05:57] We're basically done. The next step is about connecting up sensors. So let's go through eight of the most common to show just how easy it is. Let's start heating things up [06:09] with a temperature sensor. Wouldn't it be cool, pardon the pun, if you could measure the temperature fluctuations around your house every second of the day? Imagine being able to trigger devices to turn on and off [06:23] based on temperature thresholds. Well, that's super cheap and super easy. Let's start with the venerable DHT22. If you Google each of the sensor names in this video, [06:37] you'll see just how cheap they often are. It'll shed new light on the mark-up you pay in all these commercial devices. The DHC22 is a very simple temperature sensor and a great place to start. [06:51] It has three pins, power, ground and data. The first two just power the device and the last is how the sensor readings are sent to ESP home and home assistance. Now, to wire this up, you just need to connect each pin to the right place on the ESP32. [07:09] It's pretty simple. The power goes to the power, the ground goes to the ground, and the data goes to one of the data pins. There are loads of pins on each chip. This gives you the ability to create even more complex sensors. Like, if you wanted a single chip [07:26] that monitored temperature, light levels, noise and more, well, you'd just connect to different pins for each data feed. But we'll keep things simple for now. [07:38] I've picked GPIO23 for my data. You need to remember that for your code later. Almost all ESP32s have the pins listed on the board, but you can also look up your model online [07:51] to see all the diagrams and guides. So coding time. This is where the pen may drop on just how awesome ESPHome really is. It's already handled the bulk of the code for you, so you don't need to worry about Wi-Fi configuration or Bluetooth management, energy settings, encryption and all that stuff. [08:13] You just need to code the sensor and that is as simple as you could imagine. We write sensor to let it know that the sensor is attached. Then we confirm the platform as DHT for this sensor as it's a DHT22. [08:29] All this is available on the eSone site and they do a great job of giving sample code for everything. Then we put in the pin that it's connected to. As I said earlier, I'm using the GPIO-23. [08:45] We put in the model number so it knows how to interact with it. This is all the code you need to set up your sensor. Now, to create sensor values that get tracked in Home Assistant, we just type what they [09:00] are. So, temperature with the name of outdoor temperature. And we can also add humidity, which this sensor tracks in the same way. Now, I'm keeping this code super simple, but one more thing we'll add is the update [09:16] interval. This is handy as it naturally will affect the amount of data that flows into Home Assistant and the energy use of the device. That's it. You've created your first sensor. [09:29] You now just click to install it, and it'll do all the hard work for you. If in the future you wanted to change the frequency, name, sensors, or anything, you can just edit it from here [09:42] and broadcast the new code over the air. Cool, eh? Let's quickly jump into Home Assistant, and you'll see under Integrations the new sensor is already appearing. [09:54] Clicking on it and you can see the values heading through. How exciting! And finally, let's jump into a dashboard page. Create a graph. And bam! [10:06] We've got a detailed sensor that tracks the temperature and humidity constantly. And how easy was that? We can use this sensor easily to trigger anything we want. [10:18] change light colours, play sounds, turn on air conditioning, or simply gather the data to build your knowledge of temperature fluctuations. Final point, I'm deliberately picking the cheap components for each of these demos [10:32] to make it as accessible as possible. There are definitely better sensors out there with improved accuracy. The temperature accuracy of the BHP22 is fine for general sensing, [10:45] and the humidity is actually a proxy sensor by inverting the temperature. For most use cases, I'd actually recommend the BME 280 as its much higher accuracy is really handy. [11:00] There's also the newer BME 680 which is even better but naturally the cost goes up a little each time. So just pick what suits your use case. You now have the power to install the temperature sensor. [11:14] but my little acolyte I can see you crave more so let's get moving with motion sensors I assume you know now how to set up the EST32 chip and we can just jump directly to the wiring and the coding This is the HC They again very cheap and it works by sending ultrasonic waves out [11:41] and then measuring the response times. Because there's two of them they can work much like two eyes do and just distances by the difference in response times. The wiring is very simple. [11:56] Coding is very similar again, we just have a trigger pin to send out the pulse and an echo pin to read the waves bouncing back. Other than that, it's simple, eh? [12:08] You already know what the update interval does. This is worth considering carefully for your use case. If you want a motion sensor for a room, you might actually want it to be quite slow so [12:20] it's not hammering back up new things all the time and triggering on and off. If you want something like my hands-free light and music volume controller, well then you might want it to be much faster to allow a smooth control of light levels. [12:34] This is where NM Wave Sensors come in. They're very similar, but their sensitivity is exceptional. Sub-millimeter as the name suggests. So they will detect you in the room as long as you're breathing. [12:49] And if you're not, well, it might be a fitting end for your smart home to save the lighting and music in times of use using this mortal coil. Katie has been deactivated, though this is quite dramatic. [13:04] Let's now grant you the power of light with lighting sensors. So this will use a BH1750, which is a little sensor that happily detects light levels. [13:17] You're becoming an ESC pro now, so you know what to do. The code is very similar. Just define the name that you want for your sensor, the update interval, and that's it. [13:29] There's an option value for the address that you can set if there are any issues. By default, it sets it to 0x20C. But if you have any problems, just add this and set to 0x5C and you'll be sorted. [13:43] Again, all this is covered in brilliant detail on the ESC home site. Save, compile, and publish your code, and we now have a light sensor that you can use to do all sorts of cool things. [13:58] Again, there are loads of even better sensors. The APGS9960 recognizes colors, so you can have it trigger a different action based on the color of the room. [14:10] I'm not done with you yet. I could hear the squeal of excitement. I could measure it with my sound sensor. Let's use the KY038, a nifty little sensor that measures sound. [14:26] I don't even need to tell you now what to do. You know the drill, and the code is very familiar. Only thing to call out is the attenuation variable. We're not getting through, Nadi. because the ADC or the analog to digital converter on the ESC chip is sensitive [14:42] to the input voltage you need to cater for this. As you've got a 3.3 volt input you just need to enter 11 decibels and that's it. And as you're getting a little more comfortable I've added some filters to the code. These basically let it [14:59] smooth out noise levels. If you imagine the normal sound waves of say you talking its very noisy waves, as it's literally noise. And let's say if you were in a dungeon, [15:13] and the human ear would consider it noisy, that this sensor would more accurately describe it as quiet, punctuated by the sound of bits and tunes, until finally, silent. [15:28] So to make it more useful, you want to average it out a little, to give you a general level of noise. That's it! Now you have a sensor in your house that monitors the sound level. You can also use it as a simple burglar detection for everyone. [15:44] Sutton ninjas. Now I can hear you panting with anticipation. Is this the air you're breathing clean or dirty? Now let's think about an air particulate sensor. [15:58] Things like the HM3301. This has a little fan that sucks in air, blows across a sensor and detects PM1, 2.5 and 10. [16:10] The code is super simple, the wiring is super simple and it's sorted. I will paste the code in the description for each of these. You've now got a sensor that detects dust levels to let you know when you need to hoover or if you suffer from hay fever. [16:27] fever. If you have a workshop, it can alert you to death levels being dangerous. There's so many cool uses of these sensors, but most importantly, it gives you the data about your [16:40] environment so you can understand it better. Okay, hopefully that's got the juices flowing. So why don't we measure them? Unroast your sensor. Imagine every plant in your house [16:53] being able to scream at you when it needs washing. Or a dashboard that shows all our moisture levels, the temperature in the rooms and the humidity levels. [17:06] To do this, you just need one of these dudes, called a capacitive soil moisture sensor. There are loads of types, but I go with a capacitive sensor as they less prone to corrosion than the resistive types And naturally as they in soil and water it be getting a little bit exposed to that [17:27] The code is simple. You just need to name the sensor and pins, as always, and set the attenuation for your device. You'll notice two filters. First, the calibration. [17:40] As the device doesn't know what you're going to use it for, you need to set the values for what wet and dry means. If this was measuring whether your pond was drying up, then wet would be very wet, [17:53] as it would be completely immersed in water. If it was measuring soil moisture, well then wet would be a much lower value. You can naturally set these values in Home Assistant too, [18:05] but it's handy to control them from the device itself sometimes. You can test the values by checking the logs in ESP's home as you use the device, or just use Home Assistant to read state values for the sensor. [18:18] I've also added a medium filter as another example of how you can filter out noise. This basically takes a medium size of three readings, and will send a new medium every time it takes a reading, less than the results. [18:33] And that's it. You can now measure moisture super easily. But let's talk about one more example. when you start to get components like bee parasites. [18:45] This is where you start to see that some options combine things. This nifty little open source approach monitors moisture, temperature, humidity and light levels and it all gets powered by a little battery that can last for years. [19:02] So you could stick a bunch of these in your garden bed and have unbelievable details of how your plants are doing all in one. Okay, the HX711. [19:14] This is a load sensor. The code is super simple and just needs a bit of calibration. So you'll need a precise weight. Say, put a one kilogram weight on it, and if it reads 810, then put that number into the filter. [19:31] This can be used for lots of things. Obviously, the scale is handy. Again, you can get even more precise devices based on your use case. But you could easily have a device that monitors the amount of coffee beans left in your pot, [19:46] or sense when someone steps on your doormat, whether someone is on a chair, or trigger when a present jewel is lifted from its safe, and so on. NPR-121 Capacitive Touch Sensor. [20:00] These detect your touch, just like your phone screen. Different models have different ranges, but it's pretty cool to create a button on the material that senses through it, [20:12] a device that triggers when you tap the material in different places. And finally, you'll very quickly see how you can start to put these senses together into combined all-in-one units. [20:26] As you add more, inevitably it gets more complicated, but it's all achievable. companies like Apollo Automation are great examples love their stuff [20:38] so if you want a quick office house solution with an absolute battery of sensors already available go for it you may think that this is all now easy and in many ways it is [20:50] but there are three tips I'd like to share to save you hours of hobbanging things will of course not work sometimes But it's amazing how many of them will be down for one of these three reasons. [21:04] Number one, connect directly to the device running ESP Home if you're struggling. This takes out lots of potential issues with your home network setup, device authentication and more. [21:18] Number two, check your USB cable. I know, you're sure it's a data cable and it's definitely working. but you'll be amazed at how often this is the cause of problems. [21:32] It's that chaos of USB standards again. Top tip. Get one of these. Just plug the cable in two places and bang, [21:44] it tells you exactly what cable you've got. Number three. Look at the data sheet for your exact microcontroller and sensor. Just Google the name of it. Again, you'll be amazed at how often something changes with a new model and that's the source [22:01] of your problems and you just need to change the data pin you're using or something similar. So that's it! You now have the power. But promise me you'll only use your powers for good. [22:14] I hope this video has helped demystify some of these chips and sensors and you're able to fly off into the world to make great things. things. I'd like to thank the real superheroes [22:27] of this video, who are soaring past my head. My Patreons and YouTube members. If you'd like to see more videos, then think about joining. The link's in the description as always. [22:40] Oh, and many thanks to all of the wonderful developers of ESP Home who do such a great job in helping make the world of microelectronics accessible to everyone. who I'm out