Introduction
In this lesson, we’ll teach how to use Raspberry Pi get signal from IR remote controller and use IR controller to remote control 1602 LCD, DHT11, buzzer, and light sensor.

Hardware Preparation
1 * Raspberry Pi 3
1 * Breadboard
1 * IR Receiver(VS1838B)
1 * Infrared Remote Controller
1 * DHT11
1 * IIC 1602
1 * buzzer
1 * light sensor
1 * Resistor(10kΩ)
1 *MCP3008
Several jumper wires
1 * T-Extension Board with 40-Pin Cable(optional)

Software Preparation
Note:
1. In this lesson, we remotely control raspberry pi via PuTTy on PC. To learn how to config raspberry pi, please visit lesson 1: getting started with raspberry pi.
2. When the remote controller can’t work, please connect your raspberry Pi with Ethernet cable

Experimental Principle
When press the key of controller to IR receiver, corresponding device will take the action according to the program. For example, when pressing “1”, 1602 LCD will turn on, when pressing “2”, the 1602 LCD will turn off. The following table is key, corresponding device, and corresponding action:

Key corresponding device corresponding action

Key Corresponding device Corresponding action
1 IIC 1602 Turn on
2 IIC 1602 Turn off
3 Light sensor Get AD value
4 Buzzer Turn on/off
5 DHT11 Get Temperature and Humidity

Schematic diagram of each components
Note: Learn more about GPIO of raspberry pi, please review our lesson 2: Introduction Of Raspberry Pi GPIO

Connection Graph

Software
Note:
1)Please be sure installation and setting LIRC. To learn more about installation, setting and testing LIRC, please review our  lesson 19.

2)  Please enable the I2C and SPI first. Please enter the following command:
sudo  nano  /boot/config.txt

Open the file /boot/config.txt, find the code lines”dtparam=i2c_arm” and dtparam=spi”,checking if there is # sign in front of the line, uncomment it (remove the # in front of this line), and make sure the end of the line is”on”, finally the code should look like this:

Compile program
In this lesson, we’ll provide codes of C language and Python language. New starters can select one according to their interest or habit.

For C language users


Please be sure installation wiringpi. If you have not installed wiringPi, read  installation wiringpi

1) Download and unzip the codes by typing the following commands in pi terminal:
cd ~
wget http://osoyoo.com/driver/pi3_start_learning_kit_lesson_20/lesson20.c

2) Compile program
sudo  gcc -Wall -o lesson20 lesson20.c -lwiringPi -llirc_client

3) Run program

A.Check GPIO mode
Before running program, please run command gpio  readall to check whether MOSI、MISO、SCLK(B10、B9、B11) works as alternative functions, If the terminal shows as following:
Please run the following command to change as alternative functions

gpio  -g  mode  9    alt0
gpio  -g  mode  10   alt0
gpio  -g  mode   11   alt0

If the terminal shows as the following, please go on running program

B.Run program
sudo ./lesson20

Note: If you get error when running the program, please run the following command or reboot your Pi:
sudo /etc/init.d/lirc restart

4) Test project result
Please press controller to IR receiver.  When pressing “1”, 1602 LCD will turn on, when pressing “2”, the 1602 LCD will turn off. When pressing 3, the terminal will print AD value from light sensor. When pressing 4, the buzzer will turn on/off. When pressing 5, the terminal will print temperature and humidity value from DHT11.

For python users


Learn more about Python, please go to Raspberry Pi Starter Kit lesson 4

1) Download and unzip the code by typing the following commands in pi terminal:
cd ~
wget http://osoyoo.com/driver/pi3_start_learning_kit_lesson_20/python-code.tar.gz
tar -xzvf  python-code.tar.gz

2) Edit or create ./lircrc file at the path /home/pi/
cd ~
sudo  nano  .lircrc

.lircrc file is created at lesson 19, please replace the code as the following code, and then press “ctrl” + “X” and then press “y” to save the file, at last, press “enter” to exit

.lircrc
 
  1. begin
  2. prog = irexec
  3. button = KEY_1
  4. config = sudo python /home/pi/open-1602.py
  5. end
  6. begin
  7. prog = irexec
  8. button = KEY_2
  9. config = sudo python /home/pi/close-1602.py
  10. end
  11. begin
  12. prog = irexec
  13. button = KEY_3
  14. config = sudo python /home/pi/get-lightsensor.py
  15. end
  16. begin
  17. prog = irexec
  18. button = KEY_4
  19. config = sudo python /home/pi/controlbeep.py
  20. end
  21. begin
  22. prog = irexec
  23. button = KEY_5
  24. config = sudo python /home/pi/get-tem-hum.py
  25. end

3) Run program
irexec

Note: If you get back a error when runnig the program, please run the following command or reboot your Pi:
sudo /etc/init.d/lirc restart

3) Test project result
Please press controller to IR receiver. When pressing “1”, 1602 LCD will turn on, when pressing “2”, the 1602 LCD will turn off. When pressing 3, the terminal will print AD value from light sensor. When pressing 4, the buzzer will turn on/off. When pressing 5, the terminal will print temperature and humidity value from DHT11.

Leave a Reply

WordPress spam blocked by CleanTalk.
Bombax Theme designed by itx
"