BME280 and Light Sensors

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in a previous video I showed you how to connect to the a m203 2 or the dht22 temperature and humidity sensor today we're going to be looking at two other sensors another temperature and humidity sensor as well as a light sensor so this over here is a light sensor it is a photo resistor which measures different resistance depending on what the light level is and then the other temperature and humidity device we're going to use is this one over here which is the BM e28 0 it not only does temperature and humidity but it also does air pressure so let's get started today we're going to be using a breadboard well actually we're going to be using two red boards and that is because the ESP 32 when it sits on top of this breadboard it doesn't expose too many pins if you look on the side here and well expose and opens on this side so what we need to do is we're going to interconnect these two breadboards you'll find that most breadboards will have on the side these clips and that just allows you to connect them together so once that's together we can take this ESP 32 let's get the thing plugged in like that and that exposes more than enough pins to do what we're trying to do we're going to start with the BM e 2 H 0 so it's this little guy over here and this device connects using the I squared C bus I'm not going to go into too much detail about what the I squared C bus is but what you do need to know is that you can have multiple I squared C devices on a single bus and that's quite handy I think up to 127 and what you need to do is just know what the unique addresses of each of these devices so once you've got that connected we need to start connecting up things like power ground and also these SCL and SDA actions it's useful to have a pen out diagram actually I would say it's essential to have a pen out diagram like this and it helps you to find things like the SCL and SDA and in my case SDA is open io 21 and SC l is pen io-22 so I need to connect that to my BM e 2 8 0 next up we're going to connect up the power we're going to be using 3.3 volts so find the 3.3 volts pin and get that into the power rail and we're gonna use ground from there and we're just going to put that into this rail over here the negative rail then we connect up ground to ground positive to positive and that's everything connected we just need to plug it in and write some code so we can get the information from the sensor let's start with a blank sketch in the Arduino IDE the first thing we're going to need to do is install the library for the BM e to H 0 we're going to be using the Adafruit library so just open up manage libraries search for BM e 2 at 0 and it should be the one right at the top and there we go you can see mines installed so we're just going to put that at the top we then need to create the BM e object which we do with this line here so that creates this object called BM e which we can then use to get the readings from our device as I mentioned before the I squared C interface needs to address specific addresses on the devices you're connecting to so if we have a look here we can see that this here is the actual address for the BM e to a 0 that I'm using and by default that is the address that will be for yours as well there is a second address that it could be which is the 0 X 77 and that is something that you can actually set on the device itself by shorting out two pins this is one of the problems one of the drawbacks with the BM e to a zero if you want to use more than 2 BM e to Ed zeros on your ESP 32 that is going to be a bit problematic because there are only two address that you can get from the I squared C interface and this code here is beginning the connection with the BM e to H 0 this exclamation point is basically saying if this returns false then it's going to print out this line which is could not find the BM e to H 0 and check your wiring and this just makes it loop over and over and over it'll never come out of this next thing we're going to do is actually pull the information from the BM e to ed 0 which we do with this code here first thing we're going to do is get the temperature which we use that method there so that's the object which is calling this method and it's returning the value such as printing that you can assign this to a variable if you want and that's probably something that I would suggest if you're doing this with larger sketches but for this demonstration we're gonna leave it just as it is then we've got pressure which again is the object the BMI object calling this method and we're dividing it by a hundred to get hectopascals then we have humidity here which is just again that method and it's coming out as a percentage of relative humidity and we're delaying it by three seconds so this will run every three seconds let's compile and push this to our ESP 32 and see what we get but before we do that I've realized I've forgotten to do something and that is to actually begin the serial connection and let's compile and upload and let's have a look at the serial monitor there we go we can see the temperature the pressure and the humidity in my house at the very moment let's have a quick look at what happens when I touch the device the sensor is that little square thing over there so if I touch it we should see an increase in temperature pretty rapidly and we can see that it's gone up to 25 degrees 25 point 2 and it'll keep on rising and as soon as I let it go it should start cooling down again there you go it's a pretty rapid response from the BM e to Ed's zero in comparison to things like the dht22 also the humidity sensor is much more accurate than the dht22 especially when you're looking at higher humidities so there still are real benefits to using one of these devices next let's take a look at the light sensor it changes the amount of resistance it puts out dependent on how much light hits that head so let's take a look with the multimeter to see that in action let's put this on to that setting over there we can see there that the resistance is quite low when I put this up towards the light so 400 ohms with the light at that distance I have a light just above this device if I take it away or if I cover it over we can see that that resistance goes way up when the lights exposed again the resistance goes down what we're going to be doing is we're going to be passing a current from 3 volts so gonna connect a wire up there 3 volts going into the light sensor and then on the output we're going to be putting that through to ground and we're going to be putting that same pin that's connected to ground we're going to be putting that to one of the GPI opens which will be using it as an analog input so to do this you're going to need to use a voltage divider which is essentially taking a resistor we're going to be using a 10 kilo ohm resistor and wiring that up to the ground we are then going to take power from the 3.3 volts going into one of the pins you'll then need to choose one of the GPIO pins I'm going to connect it up to IO 34 and that's going to go on the other side the light sensor that's it all wired up let's go into the Arduino code and get a reading from the sensor reading the sensor is actually rather simple the first thing we need to do is create a couple variables while actually we're going to create one variable and one constant a constant is similar to a variable in that you can reference this throughout your code however you cannot change the value of a constant within code this over here is a variable which is an integer and this is for the value that we're going to get from our sensor the next thing we need to do is actually read the value from the pin which we're doing over here this is like pin which is that over there so it's number 34 we're gonna read it it's analog read not digital read because we're getting an analog value which is a value on the ESP 32 of between 0 and 409 5 this is because it is a 12 bit resolution and I believe you can change it to higher and actually lower on the ESP 32 I think up to 15 but just bear this in mind because obviously you need to know what if the range is what the resolution is for example the esp8266 has a 10 bit resolution and that is between 0 and 100 to 3 and then if you're doing this on an Arduino you have 8-bit resolution so that would be between 0 & 2 5 4 so that's good to keep in mind you'll see why in just a second anyway that's it for the code that's all we need to do let's push it to the ESP 32 and see what we get and there we have it the light reading is coming through it's 3 8 0 7 and just to show that it is actually showing us a value that is updating live I'll put my hand in front of it which will stop the light from getting to it and you'll see that value go from 3 8 0 7 down to 1664 1535 so the value definitely goes down when there's less light if I put my hand away again then it should go up if I point it towards the light a bit more it should go up in value as well and you can see that happening if I take it closer to the light as well you can see that value going up and remember I told you 409 five is the limit well that's what we're seeing over there it's not going to go any higher than that so there you go you can see the light sensor is working this isn't to be an accurate Lux meter or a proper light meter in the sense of giving you a definitive value what it is is to give you a relative amount of light that it's reading so for example the way I use it I want to know whether the light is above a certain threshold so that I can switch on my pumps or switch on a fan and allow me to do some cool stuff so that's all this is it's a very very cheap device to be able to give you those readings and it works very well for the purposes that I need and I'm sure for the majority of the purposes that you'll need I hope these videos are useful for you and that you're learning a lot if you have any questions let me know in the comments below and I'll do my best to answer until the next video thank you so much for watching and stay spicy
Info
Channel: More ChilliChump
Views: 5,954
Rating: undefined out of 5
Keywords: chillichump, chillichump2, chilli, spicy, stay spicy, pepper, automation, cbgta, chillichumps beginners guide to automation, episode 9, bme280, light sensor, photoresistor, ldr, esp32, arduino, esp8266, temperature sensor, internet of things, humidity sensor, temperature sensor arduino
Id: QT20p66IRDE
Channel Id: undefined
Length: 12min 12sec (732 seconds)
Published: Fri Mar 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.