Analog Sensor Tutorial with PI

Objective:

The main objective of this post is to explain how to make use of Temperature and Humidity sensor with support of Raspberry Pi to monitor the values.

Introduction:

In our project, we are using DHT11 to sense the Temperature and humidity.  DHT11 sensor can be bought at low cost and small size unlike other sensors.  Because of this reason, DHT11 sensors  are perfect for lots of different electronics projects. Some projects where the DHT11 would be useful include remote weather stations, home environment control systems, and agricultural/garden monitoring systems. The DHT11 is a digital sensor that lets easily get humidity and temperature readings in any of the projects. In this post, I’ll explain how the DHT11 measures humidity and temperature.  The below are the specifications of DHT11 sensor.

  • Humidity Range: 20-90% RH
  • Humidity Accuracy: ±5% RH
  • Temperature Range: 0-50 °C
  • Temperature Accuracy: ±2% °C
  • Operating Voltage: 3V to 5.5V

electronic-brick-humidity-temperature-sensor

Apparatus required :

  1. Bread board.
  2. Raspberry PI
  3. DHT11 sensor
  4. Resistors
  5. Male to Male Jumper Wires
  6.  Ethernet cables

Procedure :

  • First, make the connections as shown below in the fig.  Ensure that the DHT11 sensor is placed on the bread board firmly to prevent any loose connection.
  • The connections from Raspberry PI to DHT11 sensor should be as follows, if any of them goes wrong, then we wouldn’t get the required output.

GND of PI to GND of DHT11

Vcc of DHT11 to 3-5v supply.

Connect a 4.7k-10k ohm resistor (acts as pull-up) between data pin and Vcc of the DHT11.

Connect the data pin to any of the GPIO pins of the Pi( in this project, I have connected to GPIO 4 but it need not the same, we can use any GPIO pin and the same should match with the code.

whatsapp-image-2017-02-14-at-12-52-42-pm

 

Once the connections are made, connect the raspberry pi to a power source and we would be able to see that the DHT11 gets powered ON with a light which means that it’s working fine.

img_2584-1

To enable SSH on PI:

We would require Raspberry Pi connected to the router with Monitor, keyboard and mouse.

Login with the following information when prompted:
Username: pi
Password: raspberry

Type the following command:

sudo raspi-config  in the terminal, then navigate to ssh, hit Enter and select Enable or disable ssh server.

shut down now/reboot.

The above steps, if followed ensures that ssh is enabled on the PI.

VNC is a graphical desktop sharing system that allows you to remotely control the desktop interface of one computer from another computer.  So, obviously we would require VNC for remote desktop.

Enabling VNC(Virtual Network Computing) for the PI:

  • Connect the Pi to the monitor and keyboard and provide power supply to the Pi.
  • Open the terminal and type the command “sudo raspi-config” and press enter.
  • A menu gets popped up,  select Advanced Setting >  navigate to VNC and press enter and select enable VNC.

To trace the IP address of the PI:

Once SSH and VNC are enabled in the PI, it is essential to trace the IP of the PI which can be done by below steps:

  • Make sure that Laptop is connected to wifi(VU_IOT) and the other end of the PI is connected to the network router by means of an Ethernet cable.
  • One of the third party website that depicts the IP address connected to the router is NETGEAR, which is accessed using the IP address 192.168.10.1.
  • Login to the portal using the necessary credentials(username-admin).
  • It lists a number of IP addresses of the devices that are connected to the network router.
  • We can ensure the right IP by accessing putty with any of the IP’s mentioned and if its accessible, that becomes the IP of your pi.
  • In my case, the IP address of my PI is 192.168.10.11

 

img_2583

Software Installation:

  • The python code that I used to work with the DHT11 is available on Github.

https://github.com/adafruit/Adafruit_Python_DHT.

  • Open the putty session and log into your Pi.
  • Then create a directory named Softwares by typing the command “mkdir software”.
  • Now open this directory by typing “cd software”.

2017-02-152

  • Now, to clone the python code into the pi, enter the command “git clone https://github.com/pschragger/Adafruit_Python_DHT”
  • Open the directory with the code, using “cd Adafruit_Python_DHT” command.

Installation of Library:

In order to get the python installed, we would have to set up few dependencies and there are few commands to be executed in order to get those libraries installed.

  • Ru the command, sudo apt-get update.  It takes a while to get the update done, below is the figure.
  • Run the command, sudo apt-get install build-essential python-dev python-openssl.

whatsapp-image-2017-02-14-at-12-52-56-pm.jpeg

  •  To install the library, execute the command “sudo python setup.py install”. Now, any python program can access Adafruit_DHT python module. 

Testing the Library

  • To test the python library we can run some of the example programs in the example folder.
  • The program takes command line parameter .These parameters are type of sensor and GPIO pin for which sensor is connected to and displays the single reading from the sensor.
  • First we need to navigate to the example folder by executing  cd examples  
  • Now run the example on raspberry pi with an AM2302 sensor connected to GPIO  sudo ./AdafruitDHT.py 2302 4 .We need to make sure that we are running the command from root by using the sudo command so that we are on the right path.

untitled

  • Now,run the example on the Pi, use “sudo ./AdafruitDHT.py 11 4”. We typed in 4 because we  connected it to the GPIO4, we could modify the code as in the way that we have connected to the GPIO pin.  We would get the values of the room temperature and humidity.
  • In order to get values continually, add a while loop (an infinite loop) to the code, using pico command(pico AdafruitDHT.py)

untitled.png

untitled1.png

In this way, we get the values of the temperature and humidity.  To see the changes in the values, blow air and the values tend to change.

whatsapp-image-2017-02-14-at-12-52-43-pm

Conclusion:

Hence, we have successfully explained the Analog sensor tutorial on this page to view the values and reports of temperature and humidity using DHT11 sensor and Raspberry Pi kit.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s