Use of common Raspberry Pi peripheral sensor

Source: Internet
Author: User

In the use and development of Raspberry Pi, you may often need some hardware and sensors to support your development work, for example, add an ultrasonic ranging module to allow your Raspberry Pi to have ranging function, add a temperature measurement module to achieve temperature measurement function. Today we have prepared 10 of the most commonly used sensors in conjunction with Raspberry Pi, you can use these routines directly in your development work, or you can make changes to access more sensors to your Raspberry Pi project.



This paper takes the Grove electronic module series developed by Seeedstudio as an example, and of course, you can purchase similar modules in more hardware companies such as Sparkfun and Dfrobot.


1. Distance monitoring

Ultrasonic distance measurement is a commonly used ranging method, the principle is that the ultrasonic pulse emitted into the air, when the measurement is reflected to the receiving end, the processor by measuring the return time to calculate the distance of the obstacle. The Grove-ultrasonic Ranger has four pins, namely power supply, ground, signal pin, and one pin dangling.



Connect the Raspberry Pi and module as follows:



After checking out the code from GitHub, enter it in the Raspberry Pi terminal lxterminal:
CD "Grove–ultrasonic Ranger"
sudo python ultrasonic.py
The Raspberry Pi can drive the Ultrasonic Ranger module to work:



2. Infrared human Detection

Infrared human body sensor to detect whether there is a range of human movement, often used in corridor lighting control, anti-theft devices, automatic doors and other facilities. In this example, the sensor is connected to the Raspberry Pi, and when the sensor detects a human motion signal, its output signal is to the Raspberry Pi.




Connect the Raspberry Pi with the module as follows:



Go to the checked-out code directory and execute:
CD "Grove–pir Motion Sensor"
sudo python pir_sensor.py
When the sensor detects human activity, the Raspberry Pi output results:



3. Temperature and humidity measurement

The most commonly used in environmental monitoring is the automatic detection of temperature and humidity. The commonly used temperature and humidity sensor communicates with the processor using a single bus protocol, and the temperature and humidity measurements are output to the Raspberry Pi end. In this routine, temperature and humidity measurements are made using the grove-temperature and Humidity Sensor Pro module (DHT22).



Connection:



The temperature and humidity sensor sample code is developed using C language, which needs to be compiled after the code has been downloaded and entered into the source directory after the terminal input:
CD "Grove-temperature and humidity Sensor Pro"
Make
To compile, and then enter the following command to perform the example:
sudo./seeed_dht22
Raspberry Pi Working effect:



4. Real-Time Clock

Raspberry PI itself is not RTC, in some scenarios, it is necessary to use the external RTC module to provide the real-time clock for the Raspberry Pi. In this example, GROVE-RTC is used to provide a real-time clock for the Raspberry Pi, which communicates with the Raspberry Pi using I²c.



Connection:



The Grove RTC module can connect directly to the 5V pin of the Raspberry Pi, but you need to configure I²C before using RTC.

1. First install the Linux i²c driver module:
sudo aptitude install i2c-tools Libi2c-dev

2. Load i2c-bcm2708 and rtc-ds1307:
sudo modprode i2c-bcm2708
sudo modprobe rtc-ds1307
After the I²c configuration is complete, if it is the model B of Raspberry Pi, then in the terminal input:
sudo i2cdetect–y 1
Of course, if it is model A of Raspberry Pi, then enter:
sudo i2cdetect–y 0
At this point, you can see the output information:




Next, add the obtained RTC hardware address information to the I²C device and enter it at the terminal:
Sudo-i
echo ds1307 0x68 >/sys/class/i2c-adapter/i2c-1/new_device
Hwclock-r

The above command adds a new I²C device to the system and reads the RTC data:



Of course, when you first use the RTC module you need to set an initial time for your RTC. We use the time of the Raspberry Pi system as the initial value of the RTC module, which can be set as follows:
Date
Hwclock–w
Hwclock-r



5.OLED Display

grove-oled display is a 128x64 OLED display that uses the I²C protocol and is particularly suitable as a second display for the Raspberry Pi.






After entering the source directory, enter in the terminal:
CD "Grove–oled Display 128x64"
sudo./oled
grove-oled Display working results:






6. Barometric pressure test

Grove-barometer sensor is an electronic module that integrates air pressure and temperature sensing, and communicates with the Raspberry Pi using the I²c interface.






After entering the source directory, enter in the terminal:
CD "Grove–barometer_sensor"
sudo./barometerdemo
Its work:



7. Light Detection

If you use the Rasbperry pi to make a device that automatically closes the curtains when the glare is strong, you need to use a light sensor to monitor the lighting situation. Grove-digital light sensor to complete the task, which uses the I²C protocol to obtain the illumination value of the current illumination.



Connection:



After entering the source directory, enter in the terminal:
CD "Grove–digital_light_sensor"
sudo./dls
Grove–digital Light Sensor work:




8. Relay Control

Relays are used in a wide range of applications, and you can even build a simple smart home system using a relay, such as a garden sprinkler and an electric rice cooker. Therefore, the Raspberry Pi Plus relay can fully extend its control over external devices.

Dry-reed Relay refers to the reed relays, which are compared with the general relays, and their switching speed and life are greatly improved. The use of the relay is very simple, only the level control of its pin to complete the control of the relay.






After entering the source directory, enter in the terminal:
CD "Grove-relay"
sudo python relay.py
The Rasbperry Pi will control the relay to switch on and off every 0.5 seconds.

9. Analog-to-digital conversion

Raspberry Pi It's a pity that there is no ADC and there is nothing left to do with an external device that faces a large stack of analog signals. However, now we have the GROVE-ADC module to solve this problem.



The ADC code is very simple, and the external voltage value can be obtained by using the READADC () function. Next, an analog level output module: Grove-alcohol sensor, for example, shows how to use the module with an alcohol sensor to measure the alcohol value.



Press the Raspberry Pi, ADC module, and alcohol sensor as connected:



Work as shown, try to alcohol sensor near the alcohol and other liquids, when it detects increased alcohol concentration in the air, the output value will change significantly.
After entering the source directory, enter in the terminal:
CD "GROVE–ADC"
sudo./Adc121_demo
Work as follows:



all of the source code in this article is hosted on Github:Https://github.com/yexiaobo-seeedstudio/Grove-RaspberryPi

Use of common Raspberry Pi peripheral sensor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.