Summary of Contents for ADEEPT Ultimate Sensor Kit for Raspberry Pi
Page 2
Package List Name Picture LCD1602 I2C Interface Module DHT-11 Temperature and humidity Sensor DS18B20 Digital temperature Sensor Ultrasonic Distance Sensor Module ADC0832 Module BMP180 Barometer Sensor ADXL345 Accelerometer PS2 Joystick Module Relay Module DC Motor Module...
Page 3
Segment Display Module 8x8 LED Matrix Module Potentiometer Module Slide Potentiometer Module Rotary Encoder Module PIR Sensor Module MQ-2 Gas Sensor Module LED Bar Graph Module Active Buzzer Module Passive Buzzer Module MIC Module Touch Button Module...
Page 4
Line Finder Module Flame Sensor Module Vibration Sensor Module CM Module Water Level Sensor Module Soil Moisture Sensor Module Photoresistor Module Analog Temperature Sensor(Thermistor Module) Hall Sensor Module Limit Switch Module...
Page 6
5-Pin Wires Hookup Wire Set 2-Pin Female to Female Wires Male to Female Jumper Wires Breadboard Band Resistor Card...
Page 7
Preface About Adeept Adeept is a technical service team of open source software and hardware. Dedicated to applying the Internet and the latest industrial technology in open source area, we strive to provide best hardware support and software service for general makers and electronic enthusiasts around the world. We aim to create infinite possibilities with sharing.
Content About the Raspberry Pi .................... 10 Raspberry Pi Pin Numbering Introduction ..............11 Raspberry Pi GPIO Library Introduction ..............13 How to Use wiringPi and RPi.GPIO ................15 Lesson 1 Blinking LED ..................... 19 Lesson 2 Controlling an LED by Button ..............22 Lesson 3 Controlling an RGB LED by PWM ..............
Page 9
Lesson 31 Soil Moisture Detection ................118 Lesson 32 MQ-2 Gas Sensor ..................121 Lesson 33 Sound Sensor ..................125 Lesson 34 PS2 Joystick ..................128 Lesson 35 LCD1602 Display ................... 131 Lesson 36 How to Make a Simple Thermometer(1) ............ 137 Lesson 37 How to Make a Simple Thermometer(2) ............
About the Raspberry Pi The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python.
Raspberry Pi Pin Numbering Introduction There are three methods for numbering Raspberry Pi’s GPIO: 1. Numbering according to the physical location of the pins, from left to right, top to bottom – the left is odd and the right is even. 2.
Raspberry Pi GPIO Library Introduction Currently, there are two major GPIO libraries for Raspberry Pi: RPi.GPIO and wiringPi. RPi.GPIO: RPi.GPIO is a python module to control Raspberry Pi GPIO channels. For more information, please visit: https://pypi.python.org/pypi/RPi.GPIO/ For examples and documentation: http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ The RPi.GPIO module is pre-installed in the official Raspbian operating system, thus you can use it directly.
Page 14
Next, verify whether the wiringPi is installed successfully or not: wiringPi includes a command-line utility gpio which can be used to program and set up the GPIO pins. You can use it to read and write the pins or even control them from shell scripts.
How to Use wiringPi and RPi.GPIO For how to use the wiringPi C library and RPi.GPIO Python module, here we take blinking an LED for example. Step 1: Build the circuit according to the following schematic diagram For Python users: Step 2: Create a file named led.py $ sudo touch led.py...
Page 16
Step 3: Open the file led.py with vim or nano $ sudo vim led.py Write the following source code, then save and exit. Step 4: Run $ sudo python led.py Now you should see the LED blinking. Press ‘Ctrl+C’ and the program execution will be terminated.
Page 17
$ sudo touch led.c Step 3: Open the file led.c with vim or nano $ sudo vim led.c Write the following source code, then save and exit. Step 4: Compile the code $ sudo gcc led.c -lwiringPi After the command is executed, you'll find a file named a.out appear in the current directory.
Page 18
Before you continue learning, please copy the source code provided with the kit to your Raspberry Pi's /home/ directory, or download the source code directly from our github repository: C Language Source Code: $ git clone https://github.com/adeept/Adeept_Sensor_Kit_for_RPi_C_Code Python Source Code: $ git clone https://github.com/adeept/Adeept_Sensor_Kit_for_RPi_Python_Code...
Lesson 1 Blinking LED Introduction LED is usually used in office lighting, furniture, decoration, sign board, streetlight, etc. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * LED Module - 1 * 3-Pin Wires Experimental Principle...
Page 20
Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/01_LED/blinkingLed.c) Step 3: Compile $ sudo gcc blinkingLed.c -o led -lwiringPi Step 4: Run $ sudo ./led For Python users: Step 2: Edit and save the code with vim or nano.
Lesson 2 Controlling an LED by Button Introduction A button is an electronic switch and usually used for device control. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * Button Module - 1 * LED Module - 2 * 3-Pin Wires...
Page 23
In this experiment, we detect the High or Low level of pin 12 of the Raspberry Pi and then control the LED connected to pin 11 accordingly. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/02_btnAndLed/btnAndLed_1.c) Step 3: Compile...
Page 24
$ sudo gcc btnAndLed_1.c -o btnAndLed -lwiringPi Step 4: Run $ sudo ./btnAndLed For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/02_btnAndLed/btnAndLed_1.py) Step 3: Run $ sudo python btnAndLed_1.py Press the button and you can see the LED toggle between on and off.
Lesson 3 Controlling an RGB LED by PWM Introduction RGB LED is designed based on the principle of three primary colors. In an RGB LED, three LEDs in red, green, and blue respectively are packaged together, thus by controlling the brightness of three LEDs, making the RGB LED flash multiple colors. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board...
Page 26
In this experiment, we make the pin 11, 12, and 13 of the Raspberry Pi output PWM (pulse-width modulation) signals by programming, to make the RGB LED flash different colors. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 27
Step 4: Run $ sudo ./rgbLed For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/03_rgbLed.py) Step 3: Run $ sudo ./03_rgbLed.py Now you can see the RGB LED flash different colors alternately.
Lesson 4 Active Buzzer Introduction Buzzers are a type of integrated electronic alarm devices and powered by DC supply. They are widely applied for sound producing in devices such as computer, printer, duplicator, alarm, electronic toy, vehicle electronic equipment, phone, and timer and so on. Active buzzers can make sounds constantly when connected with a 5V DC supply.
Page 29
The schematic diagram: In this experiment, by programming the Raspberry Pi, we make the pin 11 of the Raspberry Pi output High and Low alternately, so the active buzzer makes sounds accordingly. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 30
$ sudo gcc buzzer.c -o buzzer -lwiringPi Step 4: Run $ sudo ./buzzer For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/04_activeBuzzer.py) Step 3: Run $ sudo ./04_activeBuzzer.py Now you can hear the active buzzer beeps like the sound of "Di Di".
Lesson 5 Passive Buzzer Introduction The difference between an active buzzer and a passive one radically lies in the requirement for input signals. The ideal signals for active buzzers are direct currents(DC), usually marked with VCC or VDD. Inside them there are a simple oscillation circuit that can convert constant direct currents into pulse signal of a certain frequency, causing magnetic fields alternation and then Mo sheet vibrating and making sounds.
Page 32
The schematic diagram: Ω In this experiment, by programming the Raspberry Pi, we make the pin 11 of the Raspberry Pi output square waves of different frequencies alternately, thus driving the passive buzzer to play music. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 33
(code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/05_passiveBuzzer/passiveBuzzer.c) Step 3: Compile $ sudo gcc passiveBuzzer.c -o passiveBuzzer -lwiringPi -lpthread Step 4: Run $ sudo ./passiveBuzzer For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/05_passiveBuzzer.py) Step 3: Run $ sudo ./05_passiveBuzzer.py Now you can hear the passive buzzer play music.
Lesson 6 Controlling an LED by Hall Sensor Introduction Hall 3144 is a Hall switch circuit. When the N pole of a magnet approaches to its print surface, the switch outputs Low; when the N pole moves away, the switch outputs High. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board...
Page 35
In this experiment, by programming the Raspberry Pi, we detect the High or Low level of pin 11 of the Raspberry Pi and then toggle the LED based on the output signal of the hall sensor. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 36
Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/06_hall.py) Step 3: Run $ sudo ./06_hall.py When you place the N pole of a magnet close to or move it away from the Hall Sensor, the state of the LED will be toggled between ON and OFF.
Lesson 7 Controlling an LED by Reed Introduction Reed switch is a special magnet-sensitive switch. Inside the glass tube, the reed sheets placed in parallel with a gap between compose the normally-open contact. When a magnet approaches the reed switch, or after the coil wrapped on the reed is electrified and a magnet field comes into existence thus magnetizing the reed, the contact of the reed will sense it and become the opposite pole.
Page 38
In this experiment, by programming the Raspberry Pi, we detect pin 12 of the Raspberry Pi and then toggle the LED based on the output signal of the reed switch. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 39
$ sudo ./reed For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/07_reed.py) Step 3: Run $ sudo ./07_reed.py Place the magnet near or away from the Reed Module and you will see the state of the LED will be toggled between ON and OFF.
Lesson 8 How to Use a Relay Introduction The relay is an electronic and electrical component that controls large currents by small currents. In the course of building a Raspberry Pi project, generally many large current or high volume devices like solenoid valve, lamp and motor cannot be connected directly to digital I/Os of the Raspberry Pi.
Page 41
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/08_relay/relay.c) Step 3: Compile $ sudo gcc relay.c -o relay -lwiringPi Step 4: Run $ sudo ./relay For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/08_relay.py) Step 3: Run $ sudo ./08_relay.py...
Lesson 9 Laser Transmitter Introduction Semiconductor laser modules are widely used in laser communication, ranging, ladar, ignition and blasting, and testing instruments. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * Laser Transmitter Module - 1 * 3-Pin Wires...
Page 44
In this experiment, by programming the Raspberry Pi, we control the Laser Transmitter Module to emit laser by pin 11 of the Raspberry Pi. Note : DO NOT look directly into the laser! Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 45
Step 4: Run $ sudo ./laser For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/09_laser.py) Step 3: Run $ sudo ./09_laser.py Now you can see the Laser Transmitter Module emit laser and the emission lasts for 1 seconds, and then it stops.
Lesson 10 Laser Receiver Introduction The principle for many laser receiving devices is the same. The laser ray goes through the optical lens and then is received by the photosensitive device, i.e. the photodiode. After receiving the rays, the photodiode will generate currents accordingly (based on the light intensity) which then output electrical signal after running through the amplifier.
Page 47
In this experiment, we use the Laser Receiver module to detect whether there is laser ray shining on the module. If yes, the output pin (S) of the module will output Low. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 48
Step 3: Run $ sudo ./10_laserRecv.py Make the Laser Transmitter module to shoot laser ray onto the Laser Receiver module. Then "Laser received…" will be displayed on the terminal. Remove the transmitter module and "Laser not received" will be shown.
Lesson 11 How to Control a DC Motor Introduction DC motor is a device that converts electrical energy into mechanical energy. Due to the ease of control, it is usually used in fan, electronic toy, shaver, etc. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard...
Page 50
Pin definition: Iutput Iutput This experiment is to control the status of the DC motor via the Raspberry Pi. The statuses include forward, stop and reverse. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/11_motor/motor.c) Step 3: Compile $ sudo gcc motor.c -o motor -lwiringPi...
Page 51
Step 4: Run $ sudo ./motor For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/11_motor.py) Step 3: Run $ sudo ./11_motor.py Now you can see the fan rotates forward, stop, reverse.
Lesson 12 Controlling an LED by Limit Switch Introduction Limit Switch, or travel switch, can be installed on relatively stationary objects such as mounting bracket and door frame, or moving objects like car and door. When the moving object approaches the stationary one, the switch is closed; when the moving one moves away from the static one, the switch is open.
Page 53
The schematic diagram: In this experiment, by programming the Raspberry Pi, we detect the status of the Limit Switch module through pin 12 of the Raspberry Pi and then toggle the LED based on the output signal of the limit switch. Experimental Procedures Step 1: Build the circuit For C language users:...
Page 54
Step 3: Compile $ sudo gcc limitSwitch.c -o limitSwitch -lwiringPi Step 4: Run $ sudo ./limitSwitch For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/12_limitSwitch.py) Step 3: Run $ sudo ./12_limitSwitch.py Press the Limit Switch and you can see that the state of the LED will be toggled between ON and OFF.
Lesson 13 Controlling an LED by Vibration Switch Introduction The vibration digital input module can sense weak vibration signals, thus it can be used for related interaction projects. The core sensor is SW-540, a spring component of no- directional vibration sensing which can be triggered at any angle. The module stays off at any angle when it's still.
Page 56
Pin definition: Output The schematic diagram: This experiment is to make the LED that connected to the pin 11 of Raspberry Pi flicker with the actions of the Vibration Sensor module. Experimental Procedures Step 1: Build the circuit...
Page 57
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/13_vibration/vibration.c) Step 3: Compile $ sudo gcc vibration.c -o vibration -lwiringPi Step 4: Run $ sudo ./vibration For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/13_vibration.py) Step 3: Run $ sudo ./13_vibration.py...
Lesson 14 Rotary Encoder Introduction Rotary encoder switch, or small rotary encoder, is a switch electronic component that has a set of regular and strictly-sequenced pulses. The module supports functions such as increase, decrease, turn pages, etc., by collaboration with a microcontroller. For example, in daily life you can see page turning of the mouse, menu selection, volume adjustment of speakers, temperature adjustment of toaster, frequency adjustment of medical equipment, etc.
Page 60
The schematic diagram: In this experiment, by programming the Raspberry Pi, we change a value by reading the status of the Rotary Encoder. When we turn the knob of the Rotary Encoder clockwise, the value on the terminal will increase; when we turn the knob counterclockwise, the value will decrease.
Page 61
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/14_RotaryEncoder/rotaryEncoder.c) Step 3: Compile $ sudo gcc rotaryEncoder.c -o rotaryEncoder -lwiringPi Step 4: Run $ sudo ./rotaryEncoder For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/14_rotaryEncoder.py) Step 3: Run $ sudo ./rotaryEncoder.py...
Page 62
Now rotate the shaft of the rotary encoder, and the value printed on the screen will change. Rotate the rotary encoder clockwise, the value will increase; Rotate it counterclockwise, the value will decrease; Press the rotary encoder, the value will be reset to 0.
Lesson 15 Controlling an LED by Touch Button Introduction The Touch Button Module is a touch switch module developed based on the principle of capacitive sensing. Touch of human or metal onto the gilded touch surface can be sensed. Besides, it can also detect other such touch with certain materials like plastic and glass between.
Page 64
The schematic diagram: In this experiment, by programming the Raspberry Pi, we detect the High or Low of the output terminal of the Touch Button Module by pin 12 of the Raspberry Pi, so as to tell whether fingers touched the touch button or not. Experimental Procedures Step 1: Build the circuit...
Page 65
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/15_touchBtn/touchBtn.c) Step 3: Compile $ sudo gcc touchBtn.c -o touchBtn -lwiringPi Step 4: Run $ sudo ./touchBtn For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/15_touchBtn.py) Step 3: Run $ sudo python 15_touchBtn.py...
Lesson 16 Movement Detection Based on PIR Introduction The PIR (passive Infrared) sensor can detect the Infrared rays emitted by human or animals and then output On/Off signals. Traditional pyroelectric PIR sensor needs pyroelectric Infrared probe, special chip and complex circuits to make the effect. In this case, the sensor is a large one with complicated circuits and comparatively less credible.
Page 68
Output 3.3V 3.3V The schematic diagram: This experiment is to use the PIR Sensor Module to detect whether there is any human activity. Experimental Procedures Step 1: Build the circuit...
Page 69
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/16_PIR/pir.c) Step 3: Compile $ sudo gcc pir.c -o pir -lwiringPi Step 4: Run $ sudo ./pir For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/16_PIR.py) Step 3: Run $ sudo python 16_PIR.py...
Lesson 17 Flame Sensor Introduction The Flame Sensor detects flames by the special infrared receiver to capture the infrared rays of a specific wavelength in the flames. It supports a detection angle of as high as 60 degrees and works within -25 - 85℃. When in use, you need to pay attention and do not place the probe of the sensor too close to the flames in case of damages.
Page 72
Analog Output In this experiment, by programming the Raspberry Pi, we detects whether a flame has been encountered. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/17_flame/flame.c) Step 3: Compile $ sudo gcc flame.c -o flame -lwiringPi...
Page 73
For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/17_flame.py) Step 3: Run $ sudo python 17_flame.py Then you'll see the data detected by the Flame Sensor module on the terminal. The data includes two parts: "...
Lesson 18 Line Finder Introduction The Line Finder Module applies the principle that infrared rays reflect differently on surfaces of different colors. After electrified, the infrared diode on the module sends out infrared rays constantly. When they encounter a white surface, the diffused reflection happens and the reflected rays are received by the receiver on the module.
Page 75
Output In this experiment, we detect a piece of white and another of black paper via the Line Finder Module. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/18_tracking/tracking.c) Step 3: Compile...
Page 76
$ sudo gcc tracking.c -o tracking -lwiringPi Step 4: Run $ sudo ./tracking For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/18_ tracking.py) Step 3: Run $ sudo python 18_tracking.py Place the sensor module over a piece of white paper and another of black and you will see the data detected on the terminal.
Lesson 19 Measuring the Temperature via DS18B20 Introduction DS18B20 is a single-bus digital temperature sensor of high-precision. The measurement range is-55℃ - +125℃ and inherent temperature resolution is 0.5℃. The sensor support multi-point network and multi-point temperature measurement – the measured result is sent to the controller via serial port in the format of a 9-12-bit number.
Page 78
Data The schematic diagram: Ω Ω In this experiment, by programming the Raspberry Pi, we read the temperature value collected by the DS18B20 module through pin 7 of the Raspberry Pi, and display it on the terminal. Experimental Procedures Step 1: Build the circuit...
Page 79
Step 2: Upgrade Raspberry Pi OS kernel $ sudo apt-get update $ sudo apt-get upgrade Step 3: Modify the configuration files $ sudo vim /boot/config.txt Then scroll to the bottom and type: dtoverlay=w1-gpio Then reboot Raspberry Pi $ sudo reboot Mount the device drivers and confirm whether the device is effective or not $ sudo modprobe w1-gpio $ sudo modprobe w1-therm...
Page 80
The result is as follows: root@rasberrypi:/sys/bus/w1/devices# ls 28-00000355d573 w1_bus_master1 28-00000355d573 is an external temperature sensor device, but it may vary with every client. It is the serial number of your DS18b20. Step 4: Check the current temperature $ cd 28-00000355d573 $ ls The result is as follows: root@rasberrypi:/sys/bus/w1/devices/28-00000355d573# ls...
Page 81
Now, you can see the current temperature is printed on the terminal.
Lesson 20 Temperature & Humidity Sensor - DHT-11 Introduction DHT11 is a composite digital thermal sensor that integrates temperature and humidity detection. It can convert the temperature and humidity analog values into digital values via corresponding sensitive components and built-in circuits, which can be directly read by computer or other data collecting devices.
Page 83
In this experiment, by programming the Raspberry Pi, we read the temperature and humidity data collected by the DHT11 module by pin 11 of the Raspberry Pi and display it on the terminal. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 84
For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/20_dht11.py) Step 3: Run $ sudo python 20_dht11.py Now, you will see the data of current temperature and humidity displayed on the terminal.
Lesson 21 Measuring the Distance Introduction Ultrasonic Distance Sensor module supports a contactless detection within a distance of 2cm-400cm. It contains an ultrasonic emitter, receiver and control circuits. Notes 1. The module is not suggested to connect wires when power is on. If you have to do so, please first connect the GND and then other pins;...
Page 86
This experiment uses the Ultrasonic Distance Sensor module to detect the distance between the obstacle and module and show the data sensed on the terminal. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/21_ultrasonicSensor/distance.c) Step 3: Compile $ sudo gcc distance.c -o distance -lwiringPi...
Page 87
Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/21_distance.py) Step 3: Run $ sudo python 21_distance.py Now, you will see the distance to the obstacle at front of the Ultrasonic Distance Sensor module displayed on the terminal.
Lesson 22 Acceleration Sensor - ADXL345 Introduction The ADXL345 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3-wire or 4-wire) or I2C digital interface.
Page 89
NOTE: The following program uses an I2C interface. Before running the program, please make sure the I2C driver module of Raspberry Pi has loaded normally. For C language users: Step 2: Edit and save the code with vim or nano. (Code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/22_ADXL345/adxl345.c) Step 3: Compile $ gcc adxl345.c -o adxl345 -lwiringPi...
Lesson 23 Barometric Sensor - BMP180 Introduction The BMP180 is the new digital barometric pressure sensor, with a very high performance, which enables applications in advanced mobile devices, such as smart phones, tablet PCs and sports devices. It follows the BMP085 and brings many improvements, like the smaller size and the expansion of digital interfaces.
Page 92
NOTE: The following program uses an I2C interface. Before running the program, please make sure the I2C driver module of Raspberry Pi has loaded normally. For C language users: Step 2: Edit and save the code with vim or nano. (Code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/23_bmp180/bmp180dev3.c) Step 3: Compile $ gcc bmp180dev3.c -o bmp180 -lm...
Lesson 24 Dot-matrix Display Introduction The module drives the 8*8 LED Matrix by cascading two 74HC595 chips. The module communicates with the microcontroller through SPI(Serial Peripheral Interface). It only occupies three I/Os of the Raspberry Pi and save precious ones for connecting other devices.
Page 95
In this experiment, by programming the Raspberry Pi, we send the data to the dot matrix module via the SPI interface and make the display scroll the characters “Adeept”. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano.
Page 96
Step 3: Run $ sudo python 24_LedMatrix.py Now you can see on the dot matrix module, “Adeept” is displayed in the way of scrolling.
Lesson 25 LED Bar Graph Introduction The LED bar is an analog indicating component usually used for volume indication. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * LED Bar Module - 1 * 4-Pin Wires Experimental Principle...
Page 98
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/25_ledBar/ledBar.c) Step 3: Compile $ sudo gcc ledBar.c -o ledBar -lwiringPi -lm Step 4: Run $ sudo ./ledBar For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/25_ledBar.py) Step 3: Run $ sudo python 25_ledBar.py...
Lesson 26 How to Drive the Segment Display Introduction The module consists of a 4-digit 7-segment common-cathode (CC) diode and a chip TM1638. It communicates with the Raspberry Pi via three wires and can show numbers and simple characters. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable...
Page 101
Through programming the Raspberry Pi, make the module display 0000~9999. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/26_segmentDisplay/segment.c) Step 3: Compile $ sudo gcc segment.c -o segment -lwiringPi Step 4: Run $ sudo ./segment For Python users:...
Page 102
Step 3: Run $ sudo python 26_segment.py Now you can see the number 0~9999 shown repeatedly on the digital display.
Lesson 27 Potentiometer Introduction Potentiometer is a resistor whose resistance can be adjusted continuously. When its shaft is turned, the moving contact (or wiper) slides along the resistor. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * ADC0832 Module...
Page 104
The schematic diagram: In this experiment, by programming the Raspberry Pi, we collect the analog values output by the Potentiometer module through pin CH0 of the ADC0832, convert it to digital values and display them on the terminal. Experimental Procedures Step 1: Build the circuit...
Page 106
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/27_potentiometer/potentiometer.c) Step 3: Compile $ sudo gcc potentiometer.c -o potentiometer -lwiringPi Step 4: Run $ sudo ./potentiometer For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/27_potentiometer.py) Step 3: Run $ sudo python 27_potentiometer.py...
Lesson 28 Photoresistor Introduction The photoresistor module is a resistor module designed based on the principle of photoconductive effect of semiconductors, of which the resistance varies with the intensity of incident light. The resistance of the photoresistor we use decreases with stronger incident light and increases with weaker light.
Page 109
The schematic diagram: This experiment is to collect the data of light intensity by the Photoresistor module and then display it on the terminal. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/28_photoresistor/photoresistor.c)
Page 110
Step 3: Compile $ sudo gcc photoresistor.c -o photoresistor -lwiringPi Step 4: Run $ sudo ./photoresistor For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/28_photoresistor.py) Step 3: Run $ sudo python 28_photoresistor.py Now, when you try to cover to the photoresistor, you will find that the value displayed on the screen decreasing.
Lesson 29 Thermistor Introduction Thermistors can be divided into two types by temperature coefficient: positive temperature coefficient (PTC) and negative temperature coefficient (NTC). The typical feature of a thermistor is sensitive to temperature – its resistance varies with ambient temperature changes. For PTC thermistor, when the temperature gets high, its resistance increases;...
Page 112
The schematic diagram: In this experiment, by programming the Raspberry Pi, we collect the analog values output by the Thermistor module through CH0 of the ADC0832, change it to digital values and display them on terminal. Experimental Procedures Step 1: Build the circuit...
Page 113
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/29_thermistor/thermistor.c) Step 3: Compile $ sudo gcc thermistor.c -o thermistor -lwiringPi Step 4: Run $ sudo ./thermistor For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/29_thermistor.py) Step 3: Run $ sudo python 29_thermistor.py...
Lesson 30 Water Level Detection Introduction The module is a simple water level sensor. It measures the water volume by the printed wires exposed to the air on the module. The more water on the surface, more wires connected. Thus, the area of electrified wires gets larger, so the output voltage will increase.
Page 116
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/30_waterLevel/waterLevel.c) Step 3: Compile $ sudo gcc waterLevel.c -o waterLevel -lwiringPi Step 4: Run $ sudo ./waterLevel For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/30_waterLevel.py) Step 3: Run $ sudo python 30_waterLevel.py...
Lesson 31 Soil Moisture Detection Introduction The Soil Moisture Sensor module is a simple sensor that measures the soil moisture. When the soil moisture is insufficient, the output value of the sensor will decrease; on the other hand, the value will increase when there’s enough water. The surface of the sensor is gilded to prolong its life.
Page 119
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/31_soilMoisture/soilMoisture.c) Step 3: Compile $ sudo gcc soilMoisture.c -o soilMoisture -lwiringPi Step 4: Run $ sudo ./soilMoisture For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/31_soilMoisture.py) Step 3: Run $ sudo python 31_soilMoisture.py...
Lesson 32 MQ-2 Gas Sensor Introduction MQ-2 is a sensor that can detect flammable gases such as methane, hydrogen, and propane and so on. It adopts the low conductivity stannic oxide for the basic material. When there are flammable gases in the ambient environment, the conductivity of the sensor will increase as the gases become denser.
Page 122
Pin definition: Digital Output Analog Output In this experiment, by programming the Raspberry Pi, we read the analog values collected by the MQ-2 Gas Sensor and display them on the terminal. Experimental Procedures Step 1: Build the circuit...
Page 123
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/32_MQ-2/mq-2.c) Step 3: Compile $ sudo gcc mq-2.c -o mq-2 -lwiringPi Step 4: Run $ sudo ./mq-2 For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/32_mq-2.py) Step 3: Run...
Page 124
$ sudo python 32_mq-2.py Release some methane near the module, and you will see the corresponding message on the terminal indicating flammable gases. Also the value output by the analog pin of the module will be printed.
Lesson 33 Sound Sensor Introduction The MIC Module is composed of a small microphone and an LM393 voltage comparator. It can capture minor sound signals and convert them into electric ones. The threshold of the comparator can be adjusted by the blue potentiometer on the module. This module can be applied in sound alarm system.
Page 126
This experiment uses the MIC Module to detect the sound and display the data on the terminal. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/33_mic/mic.c) Step 3: Compile $ sudo gcc mic.c -o mic -lwiringPi Step 4: Run...
Page 127
Step 3: Run $ sudo python 33_mic.py Blow at the MIC Module or make some other sounds near it, and you can see the value on the terminal indicating the sound intensity. The higher the sound volume, the larger value on the terminal; the lower volume, the smaller value.
Lesson 34 PS2 Joystick Introduction The PS2 Joystick Module is an input device. It consists of a station and the control knob onside. It functions by sending angle or direction signals to the device controlled. The button on the module can also be recognized by the microcontroller. The module supports two-channel analog output, namely, x- and y-axis offset, and one-channel digital output which indicates whether the user has pressed the button at z-axis or not.
Page 129
The experiment reads the status of the PS2 Joystick Module, then send the data to and display it on the terminal. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/34_PS2Joystick/joystick.c) Step 3: Compile $ sudo gcc joystick.c -o joystick -lwiringPi...
Page 130
Step 3: Run $ sudo python 34_PS2Joystick.py Press or pull the knob and you will see the value of current status displayed on the terminal.
Lesson 35 LCD1602 Display Introduction LCD1602: 1602 crystal, or 1602 character crystal, is a dot-matrix crystal display module used specially to display letters, numbers, symbol, etc. It's composed of several dot-matrix character bits, each of which can display one character. The character bits are separated by one dot pitch and there's a gap between each line.
Page 132
This lesson contains two experiments. The first experiment is controlling LCD1602 directly by the Raspberry Pi's GPIO, the second experiment is controlling via PCF8574- based IIC module. Experiment 1: Procedures Step 1: Build the circuit For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/35_LCD1602/lcd1602.c) Step 3: Compile $ sudo gcc lcd1602.c -o lcd1602 -lwiringPi -lwiringPiDev...
Page 133
Step 4: Run $ sudo ./lcd1602 For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/35_LCD1602/lcd1602.py) Step 3: Run $ sudo python lcd1602.py Experiment 2: Procedures Step 1: Build the circuit...
Page 134
Step 2: The I2C of the Raspberry Pi is not turned on by default, we can use raspi-config enable it $ sudo raspi-config Use the down arrow to select 5 Interfacing Options...
Page 135
Arrow down to P5 I2C Select when it asks you to enable I2C. Also select when it tasks about automatically loading the kernel module. Use the right arrow to select the <Finish> button. Select when it asks to reboot. The system will reboot. when it comes back up, log in and enter the following command: $ ls /dev/*i2c* The Pi should respond with...
Page 136
For Python users: Step 3: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/35_LCD1602/i2c_lcd1602.py) Step 4: Run $ sudo python i2c_lcd1602.py NOTE: If characters are not displayed on the LCD, try to turn the potentiometer(a blue knob) for contrast adjustment on the I2C Interface Module.
Lesson 36 How to Make a Simple Thermometer(1) Introduction In this lesson, we will learn how to make a simple thermometer based on DS18b20 and segment display module. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * DS18b20 Module...
Page 138
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/36_thermometer_1) Step 3: Compile $ sudo ./build.sh Step 4: Run $ sudo ./main For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/36_thermometer_1/) Step 3: Run $ sudo python main.py...
Lesson 37 How to Make a Simple Thermometer(2) Introduction In this lesson, we will learn how to make a simple thermometer based on DS18b20 and LCD1602. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * DS18b20 Module - 1 * I2C Interface Module...
Page 140
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/37_thermometer_2) Step 3: Compile $ sudo ./build.sh Step 4: Run $ sudo ./main For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/37_thermometer_2) Step 3: Run...
Page 141
$ sudo python main.py Now you can see the temperature shown on the LCD1602.
Lesson 38 Make a Distance Measuring Device Introduction In this lesson, we will learn how to make a distance measuring device based on ultrasonic module and LCD1602. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * LCD1602 - 1 * I2C Interface Module...
Page 143
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/38_measureDis) Step 3: Compile $ sudo ./build.sh Step 4: Run $ sudo ./main For Python users: Step 2: Edit and save the code with vim or nano.
Page 144
(code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/38_measureDis/) Step 3: Run $ sudo python main.py Now, you will see the distance to the obstacle at front of the Ultrasonic Distance Sensor module displayed on the LCD1602.
Lesson 39 How to Make a Simple Voltmeter(1) Introduction In this lesson, we will learn how to make a simple voltmeter based on ADC0832 and segment display module. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * ADC0832 Module...
Page 146
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/39_voltmeter_1) Step 3: Compile $ sudo ./build.sh Step 4: Run $ sudo ./main For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/39_voltmeter_1) Step 3: Run $ sudo python main.py...
Page 147
Now you can see the voltage value shown on the segment display.
Lesson 40 How to Make a Simple Voltmeter(2) Introduction In this lesson, we will learn how to make a simple voltmeter based on ADC0832 and LCD1602. Components - 1 * Raspberry Pi - 1 * GPIO Extension Board - 1 * 40-Pin GPIO Cable - 1 * Breadboard - 1 * ADC0832 Module - 1 * I2C Interface Module...
Page 149
For C language users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/40_voltmeter_2) Step 3: Compile $ sudo ./build.sh Step 4: Run $ sudo ./main For Python users: Step 2: Edit and save the code with vim or nano. (code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/40_voltmeter_2)
Page 150
Step 3: Run $ sudo python main.py Now you can see the voltage value shown on the LCD1602.
Need help?
Do you have a question about the Ultimate Sensor Kit for Raspberry Pi and is the answer not in the manual?
Questions and answers