Raspberry Pi Sensor

Raspberry Pi Sensor
Raspberry Pi News
In this article I want to explain you how to use a soil moisture, light and laser module on the Raspberry Pi. I will explain how to connect the Raspberry Pi modules and how to control and read them from the Raspberry Pi.
Raspberry Pi sensors and modules introduced
Quick overview Raspberry Pi Sensors Kits:
Raspberry Pi Sensors Kit with 37 Sensors SunFounder (Link)*.
Raspberry Pi Sensors Kit with 39 Sensors from Quimat (Link)*
Raspberry Pi Sensor: Moisture Module
To connect the soil moisture sensor to the Raspberry Pi, we need a total of five cables and a translation chip to make the incoming data readable.
First, I connect two cables to the soil moisture sensor. These are simply plugged on as shown here. Then I connect the other end to the chip. So the sensor is already connected to the translation chip.
Raspberry Pi humidity sensor connections
Now three more cables follow, which we find on the backside of the translation chip. Once VCC, GND, DO and AO. VCC is the power connection. GND is the ground and DO is the digital output, AO is the analog output. For a better understanding of the cable connections I recommend to watch the video in the login area at www.raspi-config.de/mitgliederbereich now.
Now we need the digital output (DO). That's why I connect the three cables directly next to each other and if you turn the chip over, the right pin remains free. Now we take the end of the cables and plug them into the Raspberry Pi. At the top right I connect the first pin, because this is the connector with 3.3 volts voltage, which we need for the translation chip or sensor.
Now we connect the ground to the Raspberry Pi and directly below DO, the cable for the digital output. With this we have connected the Raspberry Pi sensor and we still need a Python script with which we can pick up the data.
Now you can turn on the Raspberry Pi. At this point you can find a pinout diagram on different sites on the internet. Link to the Raspberry Pi pin assignment plan: www.elektronik-kompendium.de/sites/raspberry-pi/1907101.htm
On the Raspberry Pi pinout diagram you can see how the pins are used on the Raspberry Pi. So at the top the power is connected and next to it the VCC connector with the 3.3 volts voltage. At the fifth pin from the top we have the ground connection, i.e. GND. Then directly below that on pin number 17 we have the data that we need to read out.
To read out the data I have prepared a script which you can download at www.raspi-config.de/mitgliederbereich. The script is relatively simple. At this point maybe a short explanation. At the top there is a library embedded, which allows to access the GPIO pins.
Then there is a time library that allows to set a timer. We'll look at what that's important for later. And then I added a callback function which is always called when a new value is measured at the sensor. For this the output "No water detected" appears when the LED is off.
Raspberry Pi Sensor Humidity Module Script
And if the LED is on, then water was detected at the sensor. So then 'water detected' is output. Then we still define the mode from which we pass the numbering. Then we define the chanel of pin 17 and get the data from there.
Then we define some functions and the timer in the script. That means, pin 17 is monitored continuously and if a new measured value is measured, then the callback function is executed. Now let's have a look at the script in action.
To test the script, I will use a cup with water in which I will carefully dip the sensor 2x and take it out again. Above you have already seen the output of the script that monitors the sensor.
What can you use the whole thing for now? One possibility would be to link this to an email output and thus monitor your favorite flower or flower pot to see if the potting soil is still moist enough. Of course, the same goes for the lawn in your backyard. You can also use this soil moisture sensor very well for that.
By the way, there are also soil moisture sensors with which you can measure even more filigree. These sensors give even more delicate values than mine. This sensor in the example at least recognizes whether it is damp or not.
What would you like to measure with it now?
Raspberry Pi Sensor: Light Module
In this section I want to introduce you to the light sensitivity module and show you how it works. The light sensitivity module consists of only one chip.
We want to connect the light sensitivity sensor to the Raspberry Pi. For this we need three connection cables. We need the connections VCC, GND and DO. There is nothing more.
So once connect the power supply, ground and the digital output for the data. Now connect the Raspberry Pi to power and then let's see the module in action once.
For the light sensitivity module I wrote a Python script that reads the data at PIN 21 of the Raspberry Pi and looks what value it has. You can find the script in the login area at www.raspi-config.de/mitgliederbereich. If the script has the value 0, then the light is on. If it has the value 1, then the light is off.
This script runs all the time on the Raspberry Pi and monitors if there is a change on the PIN's 21 value. We have the power LED on one side of the Raspberry Pi sensor, which simply indicates that power is being supplied to the module. The other is a sort of control diode where you can see the state that is being transmitted.
When executing the script via Thonny, you can see the output from the script in the lower half of the screen.
We want to connect the light sensitivity sensor to the Raspberry Pi. For this we need three connection cables. We need the connections VCC, GND and DO. There is nothing more.
So once connect the power supply, ground and the digital output for the data. Now connect the Raspberry Pi to power and then let's see the module in action once.
For the light sensitivity module I wrote a Python script that reads the data at PIN 21 of the Raspberry Pi and looks what value it has. You can find the script in the login area at www.raspi-config.de/mitgliederbereich. If the script has the value 0, then the light is on. If it has the value 1, then the light is off.
This script runs all the time on the Raspberry Pi and monitors if there is a change on the PIN's 21 value. We have the power LED on one side of the Raspberry Pi sensor, which simply indicates that power is being supplied to the module. The other is a sort of control diode where you can see the state that is being transmitted.
When executing the script via Thonny, you can see the output from the script in the lower half of the screen.
Raspberry Pi Sensor Light Module Script
I will switch the light on and off in a moment. The connected sensor now detects whether the light is on or off and outputs it accordingly in the lower area of Thonny.
This is a practical option if you have lights that are not internet-enabled. Then you can easily check that with this. But there are also many other different variants for using this Raspberry Pi Sensor practically in everyday and professional life.
This is a practical option if you have lights that are not internet-enabled. Then you can easily check that with this. But there are also many other different variants for using this Raspberry Pi Sensor practically in everyday and professional life.
Raspberry Pi Sensor: Laser Module
In this section I want to show you another use for the light sensitivity sensor from the previous sections. This time in combination with the laser module.
I assembled the design from both modules to make a light barrier. On one side on the wooden rod is the laser diode, which is pointed at the light sensitivity sensor on the other side. The idea is that the light sensitivity sensor detects when someone passes through the light barrier.
I assembled the design from both modules to make a light barrier. On one side on the wooden rod is the laser diode, which is pointed at the light sensitivity sensor on the other side. The idea is that the light sensitivity sensor detects when someone passes through the light barrier.
Raspberry Pi Sensor Laser and Light Module
So if the connection between the two sensors is broken and a change in brightness is detected, then this should be output on the screen. This is a much used function to display different states or to build indicator lights.
It's best to watch the video at www.raspi-config.com to better understand how to connect the cables. We attached the light sensitivity sensor to the wooden stick as shown in the picture. We connect the light sensitivity sensor again normally.
Then we attached the light emitting diode to the wooden stick. The light emitting diode has two cables that need to be connected to the Raspberry Pi. One cable for the power supply and one cable for the ground connection. Now you have to connect these two cables.
For this I connect the 3,3 Volt (not 5 Volt). After that the ground for the light emitting diode. If you now connect the Raspberry Pi to the power, the light emitting diode would be on directly, because the power pins have a continuous power supply.
Now let's take a look at the photoelectric sensor in action. For this, I'll again use the Python script, which I already used for the light sensitivity sensor. You can download the script at www.raspi-config.de/mitgliederbereich. Because we read the data from the light sensitivity sensor again.
In this example, of course, it's only built on a very short distance. Theoretically you could also use the laser across a room or over a distance of one meter or more. However, the further away you get, the harder it is to hit the small sensor on the module.
It's best to watch the video at www.raspi-config.com to better understand how to connect the cables. We attached the light sensitivity sensor to the wooden stick as shown in the picture. We connect the light sensitivity sensor again normally.
Then we attached the light emitting diode to the wooden stick. The light emitting diode has two cables that need to be connected to the Raspberry Pi. One cable for the power supply and one cable for the ground connection. Now you have to connect these two cables.
For this I connect the 3,3 Volt (not 5 Volt). After that the ground for the light emitting diode. If you now connect the Raspberry Pi to the power, the light emitting diode would be on directly, because the power pins have a continuous power supply.
Now let's take a look at the photoelectric sensor in action. For this, I'll again use the Python script, which I already used for the light sensitivity sensor. You can download the script at www.raspi-config.de/mitgliederbereich. Because we read the data from the light sensitivity sensor again.
In this example, of course, it's only built on a very short distance. Theoretically you could also use the laser across a room or over a distance of one meter or more. However, the further away you get, the harder it is to hit the small sensor on the module.
You see either two control LEDs light up. This means that the sensor is currently seeing light and the light barrier is not interrupted. Another very important hint at this point. NEVER look directly into the light of the laser diode!
In my setup I hold a wooden stick between the light barrier. You see in the video now the output from the Python script that the whole thing was detected. And if I go up again with the wooden stick, then the light at the sensor is there again.
So you could build a light barrier with this laser diode in combination with the light sensitivity sensor. This is just another example for the use of Raspberry Pi sensors.
Do you have any ideas what you want to do with Raspberry Pi sensors?
In my setup I hold a wooden stick between the light barrier. You see in the video now the output from the Python script that the whole thing was detected. And if I go up again with the wooden stick, then the light at the sensor is there again.
So you could build a light barrier with this laser diode in combination with the light sensitivity sensor. This is just another example for the use of Raspberry Pi sensors.
Do you have any ideas what you want to do with Raspberry Pi sensors?
Quick Overview Raspberry Pi Sensor Kits:
Raspberry Pi Sensors Kit with 37 Sensors SunFounder (Link)*.
Raspberry Pi Sensors Kit with 39 sensors from Quimat (Link)*.
Raspberry Pi Sensors Kit with 39 sensors from Quimat (Link)*.
* = Affiliate Link (raspi-config.com) is participant of the affiliate program of Amazon USA, which is designed to provide a commission for websites to earn advertising fees by placing ads and links to Amazon.com).
What would you like to do next?
Raspberry Pi News