Reader small image

You're reading from  Raspberry Pi Sensors

Product typeBook
Published inApr 2015
Publisher
ISBN-139781784393618
Edition1st Edition
Right arrow
Author (1)
Rushi Gajjar
Rushi Gajjar
author image
Rushi Gajjar

Rushi Gajjar is an entrepreneur, embedded systems hardware developer and a lifetime electronics enthusiast. He works in the field of research and development of high-speed single-board embedded computers and wireless sensor nodes for the Internet of Things. Prior to that, his extensive work as a freelancer in the domain of electronics hardware design introduced him to rapid prototyping development boards and single board embedded computers such as the Raspberry Pi. In the spare time, he loves to develop the projects on Raspberry Pi including sensors, imaging, data logging, web-servers, and machine learning automation systems. He authored a DIY and hardware based book titled Raspberry Pi Sensors which takes deep dive in developing sensor interfacing based projects with Raspberry Pi. His vision encompasses connecting every entity in world to the Internet for enhancing the human living experience. https://www.linkedin.com/in/rushigajjarhttp://www.amazon.com/Raspberry-Pi-Sensors-Rushi-Gajjar/dp/1784393614/ref=sr_1_9?ie=UTF8&qid=1453884207&sr=8-9&keywords=raspberry+Pi+Sensorshttp://rushigajjar.blogspot.in/
Read more about Rushi Gajjar

Right arrow

Chapter 4. Monitoring the Atmosphere Using Sensors

It is highly unlikely to find an equipment without sensors nowadays. Most appliances, such as air conditioners, smoke detectors, fire detectors, gas/CO2 sensors, LCD displays, refrigerators, toasters, thermostats, microwave ovens, and geysers installed in our house have sensors integrated in their circuits to measure surrounding atmospheric entities. When we take a look at our surrounding atmosphere, there are so many entities that can be measured, for example, temperature, humidity, vapor, dust, air quality, various gas levels, wind speed, rain, water quality, light (natural and artificial), presence, motion, moisture, and so on. On a broader level, technologies such as sensor networks and the Internet of Things uses "sensor nodes" that measure one or multiple of these entities and send data to the intended computer or user. The best example of this is the "nest" thermostat (www.nest.com/thermostat/). This device is an example of artificial...

Sensor selection process


The process of sensor selection, especially when building an environmental monitoring system, is very confusing in the development phase of a product. We may be unsure about which sensor can be used and which cannot. In the industries, the design and development engineers face this problem every time they start building a project. Sensors are always difficult to control while we interface them with the processor or a controller, because they are sluggish compared to processors. Additionally, we need to take care of a lot of incoming values of sensors that come into the processors. For example, in safety critical systems, such as life support systems or baby incubators, signal conditioning circuitry and signal processing units are used to measure the sensor values precisely and take actions (such as controlling the temperature and oxygen levels for newborn babies or patients) accordingly. Therefore, the first step in selecting the sensor is to find out the exact application...

InsideDHT – temperature and humidity sensors


DHT is a combined pack of temperature and humidity sensors. These sensors are ideal for hobbyists who just want to do some data logging. DHT11 sensors are slow in terms of retrieving data. As it is a combined pack, it contains a resistive thermal sensor (a thermistor) and capacitive humidity sensor. A thermistor changes its resistance value depending on the changes in temperature. Technically, all resistors act as thermistors because they dissipate heat when the current is passed through them and are responsible for power losses. However, a resistor's characteristic is that when they are heated up from the external source, the resistance values changes a little bit, which is not so effective to be measured. But this is not the case with the thermistor; its resistance values change in terms of several hundred ohms when there is a slight change in the ambient temperature. A DHT11 temperature sensor provides accuracy near to 2 degree Celsius in the...

Introducing the photoresistor (photocell)


Did you know that the RasPi does not have an analog-to-digital (A2D) convertor integrated inside? This is the biggest drawback while using microprocessor-based development boards such as the RasPi. But do not worry; we have a technique to hack it. A photocell or light-dependent resistor (LDR) is a light-controlled variable resistor. The resistance of an LDR decreases with increasing incident light intensity. More the light, lesser the resistance, and vice versa. The variations in the values vary by about 45 percent, and they shouldn't be used to try to determine precise luminance levels in candela or lux.

Appearance wise, the sensor has a clear shiny, thin surface of glassy material on the top and has two terminals. On the top, there is a photosensitive semiconductor material that is sensitive to light, and we can see the tracks routed in a zigzag pattern.

It's time to introduce you to some mathematics of resistors and capacitors. Understanding the...

Building the project


Whether you have the RasPi 2 model B, RasPi 1 Model B, or Model B+, the hardware setup will remain same and therefore the code too. Once you start coding, you will gradually learn how the RasPi board and DHT11 sensor communicates. In parallel, you will also understand how to interface it to the LDR sensor. You will get to know how multiple sensors can be integrated to get the data. However, first, let's take a look at the circuitry we need to build.

Hardware setup

This project has minimal requirements. It is easy to make the connections on the breadboard, unlike the voltage divider on the previous project. To make this setup, we will require the following devices on our table:

  • DHT11 temperature and humidity sensor

  • LDR / photoresistor / CdS cellsensor

  • 4.7KΩ, 270 Ω, and 10KΩ resistors (if the seller asks about the wattage of the resistor, ask for 1/4 watts; it is also termed as quarter watts)

  • 1µF-16V through-hole electrolytic capacitor

  • One LED

  • One multimeter

  • Female-to-male jumper...

Putting all the parts together


We can build a project that understands that the temperature and light are high, and hence, would turn off the home tube lights while automatically turning the fan on! We can integrate the whole project and make an LED glow to show the decision made by the RasPi. Does this sound good?

Tip

Whenever we want to control home appliances, we need to be extremely cautious that they work on 110/230V AC and up to 15A of current. It is not recommended to connect the RasPi to any of the AC mains-operated home appliances directly. Relays (which provide good isolation) should be used to control the appliances. However, it is highly recommended that you perform any task related to relays and controlling appliances under the observation of an experienced electrician.

We can order the relay boards from any e-store. The relay boards are separately powered through an adapter or direct mains supply. The +5V or +3.3V pins of the RasPi should not be shared with these boards. Nevertheless...

Troubleshooting common problems


We have covered almost everything on interfacing both of these sensors together. If you are still facing the problem in getting/reading the data, you could go through some of the common problems faced in the following sections. In most of the problems, it is advised that you check the connections made on the breadboard and correct the RasPi GPIO pin.

Received DHT data is not valid

The following points need to be kept in mind when the received DHT data is not valid:

  • First and foremost, as mentioned earlier, the received data directly depends on the connections you have made. Carefully check the connections of the pull-up resistor between data line and +5V line.

  • There can be a wrong value for the resistor. If you have connected 4.7KΩ, try to change it to 5KΩ, or you can use a maximum 10K resistor. A high value of the resistor can turn data into false or corrupted values.

  • Check the DHT orientation. The pin on the left-hand side, seen from front, is the VCC pin.

The...

Summary


In this chapter, we started with the process of selecting a sensor, in which we got to know that the sensor selection process is not as easy as it looks. There can be so many parameters, and none of them should be neglected while selecting a sensor. This affects the system according to the criticality of the application.

Following the explanation to introduction of the DHT and LDR sensors, you continued to learn with the tricky DHT sensors. The timing diagram was somewhat complex to implement. Due to lack of onboard analog-to-digital convertor, you learned about the RC time constant and use of the capacitor to integrate any resistive sensor with the RasPi and the LDR sensor in particular. Finally, we integrated everything and made a project that can be called a small project of home automation. We were able to integrate the LDR and DHT sensors and make a sensor node using the RasPi. Using the data of temperature and light captured from sensors, we controlled the appliances such as...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Sensors
Published in: Apr 2015Publisher: ISBN-13: 9781784393618
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Rushi Gajjar

Rushi Gajjar is an entrepreneur, embedded systems hardware developer and a lifetime electronics enthusiast. He works in the field of research and development of high-speed single-board embedded computers and wireless sensor nodes for the Internet of Things. Prior to that, his extensive work as a freelancer in the domain of electronics hardware design introduced him to rapid prototyping development boards and single board embedded computers such as the Raspberry Pi. In the spare time, he loves to develop the projects on Raspberry Pi including sensors, imaging, data logging, web-servers, and machine learning automation systems. He authored a DIY and hardware based book titled Raspberry Pi Sensors which takes deep dive in developing sensor interfacing based projects with Raspberry Pi. His vision encompasses connecting every entity in world to the Internet for enhancing the human living experience. https://www.linkedin.com/in/rushigajjarhttp://www.amazon.com/Raspberry-Pi-Sensors-Rushi-Gajjar/dp/1784393614/ref=sr_1_9?ie=UTF8&qid=1453884207&sr=8-9&keywords=raspberry+Pi+Sensorshttp://rushigajjar.blogspot.in/
Read more about Rushi Gajjar