ELECROW RASPBERRY PI STARTER KIT INTRODUCTION Thank you for purchasing Elecrow Starter kit for Raspberry Pi & Arduino! In this lessons file, we’ll go through all the components that you received by purchasing our product, we will explain, step by step, the functionality of each of the components and how to use them.
In order to to use the lessons first we’ll need to clone the repository from GitHub that includes all the examples that we’ll need. To do so, run the following commands: git clone https://github.com/Elecrow-RD/Raspberry-Pi-Starter-Kit.git cd Raspberry-Pi-Starter-Kit/Drivers After cloning the repository and CD (going into the folder) Drivers, we’ll now continue in installing the actual drivers.
Page 5
You will need to install each of those drivers by running the following command for each one: Adafruit_Python_CharLCD: cd Adafruit_Python_CharLCD sudo python setup.py install sudo python3 setup.py install cd .. Adafruit_Python_DHT: cd Adafruit_Python_DHT sudo python setup.py install sudo python3 setup.py install cd ..
Page 6
Make sure there are no errors on the way and congratulations! you’ve successfully installed all the required drivers. Please follow the next steps to prepare for the IR LED driver installation. IR LED driver installation First, let’s install the lirc library, the main library that will help us send and receive IR codes using our sensor later on in this lessons: sudo apt-get install lirc After successfully installing the lirc library, we need to install the python support for lirc so we...
Page 7
sudo nano /boot/config.txt And where it says # Uncomment this to enable the lirc-rpi module #dtoverlay=lirc-rpi change it to this # Uncomment this to enable the lirc-rpi module dtoverlay=gpio-ir,gpio_pin=20 previously it used to be dtoverlay=lirc-rpi but this one got deprecated in the newer version of Raspbian.
Once the reboot successfully finished, run apt-get install Lirc once again to fix the previous errors if any sudo apt-get install lirc Last step, stop the LIRC library so we could use the IR driver with our python script sudo /etc/init.d/lirc stop Note: if you get runtime error that the command cannot be found, maybe you have a different version of LIRC, try this command instead: sudo /etc/init.d/lircd stop...
Page 9
Introduction The Blink LED will be our first lesson, during this lesson we’ll learn what is LED and how it works, how to connect it properly to the raspberry pi using GPIO ports and then we’ll use example script to run and test a code with our hardware.
Page 10
Hardware required Below is the list of the hardware required for us to accomplish the lesson, all the hardware is included in the kit. Please make sure to take the right hardware and prepare it for the lesson. The resistor can be either 220 or 300 ohms, both will work.
Page 11
Breadboard Schematic Below is the breadboard schematics, make sure to be familiar with it. it’s important to understand how the breadboard works in order not to damage components that are included with this kit. Connection Diagram As the diagram states, we will connect the negative pin of the LED to the resistor and the positive directly to the Raspberry Pi GPIO.
Page 12
Raspberry Pi Long Pin (+) GPIO17 Short Pin (-) Code Overview, Code Overview, Compile and run Our code is quite simple. We’ll define GPIO 17 as the blinking LED pin and then setup the pin as GPIO.OUT, we will go through a while loop (forever till the program quit using CTRL-C or CTRL-Z, We will turn the LED on by setting GPIO.HIGH, wait 0.2 seconds (200 milliseconds) and turn it off by setting GPIO.LOW.
It’s inside a while loop, the program will stop by pressing CTRL+C on the keyboard or CTRL+Z. LESSON 2: BUTTON Introduction In this lesson we’ll learn how to use the button. The button is very useful in many applications for example turn on light by press or even play some music. In our specific example we’ll use the button to indicate if it was pressed or released.
Page 14
Hardware required Below is the list of all the components that are required for this lesson. Make sure to note that the resistor is 10K (kilo) ohm and not 10 ohm. Material diagram Material Name Number (amount) Button 10KΩ resistor Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable...
Page 15
Connection Diagram As we can see in the diagram, we connect the button to the 10K ohm resistor on the negative side as well as to the GPIO port at GPIO17. The other pin of the button goes to 3V pin on the raspberry pi. Please note: if you connect the button on the wrong direction the raspberry pi might indicate the opposite, GPIO HIGH when the button is released and GPIO LOW when the button is pressed, therefore the script might not work as expected.
Page 16
Code Overview, Code Overview, Compile and run Let’s take a look through our code: we set the button pin as GPIO 17 then the mode as GPIO.BCM, the button GPIO will be GPIO.IN as we receive input from the button whenever it was pressed or not. Then we go while true (forever) if GPIO.INPUT button is TRUE means the button is pressed, we print “button pressed”...
Application effect Running the program, will print “button pressed” if the button is pressed and “button released” if the button is released. LESSON 3: BALL SWITCH Introduction In this lesson we’ll learn about the ball switch, also called “tilt sensor” once the switch is tilt to one side, it could be either open or closed.
Page 18
Hardware required Below is the hardware list for our lesson, please make sure you are using the 10K ohm resistor and not a 10 ohm resistor for this example. Material diagram Material Name Number (amount) Ball Switch 10KΩ resistor Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable Breadboard...
Page 19
Connection Diagram As can be seen on the diagram, we connect the negative pin to the GND in the raspberry pi as well as to the 10K ohm resistor and to one pin of the ball switch. Note: it doesn’t matter which pin of the ball switch you choose, the decision, might effect the script. For example, GPIO HIGH might be GPIO LOW or GPIO LOW might be GPIO HIGH.
Page 20
Component Raspberry Pi Pin 1 GPIO17 Pin 2 Code Overview, Code Overview, Compile and run Let’s walk through our code: we setup the switch pin to GPIO17 as GPIO.IN because we receive input from the ball switch whenever he close the circuit by tilting it or not. Then we go for while loop (forever) and print “BALL is HIGH” if it’s closing the circuit or “BALL is LOW”...
Application effect The script will print “BALL is HIGH” if it’s closing the circuit or “BALL is LOW” if not. You can tilt the ball switch around to see the data changing. LESSON 4: ACTIVE BUZZER Introduction Active buzzer is a very useful module that can be used in many applications For example: alarm clock, movement detection or as an alert to an UPS to let you know the battery is running low.
Page 22
Hardware required Below is the list of hardware, make sure not to confuse the active buzzer and passive buzzer in the kit. Both of them have a tutorial going through and explaining how they work but for now, we focus on the active buzzer only. Material diagram Material Name Number (amount)
Page 23
Connection Diagram as we can see in the diagram, the connection is pretty simple. we connect the positive pin of the buzzer into GPIO17 on the raspberry pi and the negative pin to the ground. Connection Please note: the long pin of the buzzer is the positive pin while the short pin of the buzzer is the negative pin. Active buzzer Raspberry Pi Long Pin (+)
Page 24
Code Overview, Compile and run Let’s overview and test out buzzer code: the passive buzzer code is pretty simple. We don’t use loop in this code to avoid the buzzing sound, we setup the buzzer as GPIO17 as GPIO.OUT because we will output a GPIO.HIGH or LOW when we want to control the buzzer activity, then we set the GPIO as GPIO.HIGH for 0.5 seconds (prepare the noisy buzzing sound) and after half a second we turn it off by GPIO.LOW command.
Running the program will turn on the buzzer for 0.5 seconds and then turn it off. LESSON 5: PASSIVE BUZZER Introduction In this lesson we’ll learn about the passive buzzer. The passive buzzer is very similar, to the active buzzer. but unite the active buzzer, the passive buzzer is activated by waves (the active buzzer is activated by current running through it) In this lesson we’ll learn how to use the passive buzzer and run a script as examples to prove that it works.
Page 26
Hardware required Below is the hardware we’ll need for this lesson. make sure to prepare the hardware and most importantly don’t confused the passive buzzer with the active buzzer in the kit. Material diagram Material Name Number (amount) Passive Buzzer Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable...
Page 27
Connection Diagram As we can see in the diagram, the design is exactly the same as the previous example with the active buzzer. if you just finished the active buzzer lesson, you can just switch the buzzer module without taking out the rest of the pins.
Page 28
Passive buzzer Raspberry Pi Short Pin (-) Code Overview, Compile and run The passive buzzer is a little more complicated than the active buzzer. The code is quite long and every line is commented to explain exactly what’s happening but we’ll explain here briefly. The passive buzzer uses frequency to control it so we need to give “pitch”...
Application effect The passive buzzer will play do re mi fa sol la si do (piano notes) from do to do and backwards. LESSON 6: RGB LED Introduction Before in our previous lessons we used different types of LEDs (in our kit, we have 5mm LEDs in different colours) the RGB LED is a little bit different.
Page 30
Luminous Intensity: 12000-14000mcd Pin definition Hardware required Below is the hardware we’ll need to complete this lesson. Please note the 220/330ohm resistor, we will need 3 of them. any, either 220 or 330 will work, we can also combine few 220 and few 330ohm resistors, there is no problem with that.
Page 31
Material diagram Material Name Number (amount) Jumper wires Several Connection Diagram As we can see in the diagram, we’ll need to connect each resistor to each pin of the RGB LED except the ground pin.we’ll connect each pin (each colour) to different GPIO so we could control it separately. 31 of 114...
Page 32
Connection Please make sure you connect the pins correctly or you might experience unexpected behaviour during the run time of the script. If you see colours that you are not expected to see, try to replace the pins and see if it gets fixed. remember, each colour controlled by different GPIO pin, if you accidentally place the wrong pin on the wrong colour, this will cause the script to show different things from what we programmed it to show! RGB LED...
Application effect Running the script will turn on red LED, green LED and then blue LED with a space of 0.3 seconds between each turn on and turn off. LESSON 8: 1 DIGIT 7 SEGMENT DISPLAY Introduction In this lesson we’ll learn about the segment display. In our kit we have 2 types of segment display one is single (1 digit) segment display and one is 4 digit.
Page 34
As we can see, the segment LED is marked with letters in this pin definition, the real segment in the kit doesn’t have any letters on it. Please refer to this definition while wiring the segment LED to make sure we wire it correctly. Hardware required Below is the hardware we’ll require for this lesson, 1 digit (don’t confused with 4 digit) segment display and 220 or 330 ohm resistors, we’ll need 8 of them.
Page 35
Connection Diagram As we can see the wiring diagram can be a little bit overwhelming. Take it slowly, following the letters and the pin definition picture we’ve showed before to connect it properly. Please note the small dot on the segment LED that tells you which direction the segment LED should be pointed at. The dot should be pointed downstairs.
Page 36
make sure to not forget to place all the resistors on the pins while connecting them to the GPIO ports. All the pins except the GND (ground) pin should have resistor attached to it. Connection Follow the connection carefully to make sure not to wire accidentally some segment in the wrong way, doing so will result in fault view of the numbers when we run the testing script at the end of the lesson.
Page 37
Code Overview, Compile and run The code is quite long but don’t be afraid! This is due to the class code, the main code is actually very easy. What we did is we setup each led on the segment led as a letter from A to H and then we turn them based on the colours that they should be.
Application effect Looping through numbers from 0 to 9 and showing the numbers on the segment LED with a space of 1 second between each number we will be showing. LESSON 9: 4 DIGIT 7 SEGMENT DISPLAY Introduction In the previous lesson we learned about a single 1 digit segment display, the 4 digit 7 segment display is no different. In this lesson we’ll learn about the 4 digit segment, how to turn it on and control it using a simple python script。the script will get the current time from the raspberry pi and display it on the segment LED.
Page 39
Hardware required We’ll need a 220/330ohm resistor (8 of them, 1 for each pin) for this example. Please note you can use either 220 or 330 or combine both of them, all options will work perfectly fine. Material diagram Material Name Number (amount) Segment Display 220/330Ω...
Page 40
Connection Diagram Please refer to the previous pin definition in order to make sure to connect the right pins to the right place. 40 of 114...
Page 41
We’ll need to add resistor almost to every pin so make sure to connect them properly and put resistor where it should be. The direction of the connection is with the dot at the bottom. Connection 41 of 114...
Page 42
Please refer to the chart below on instructions how to connect the pins, we use GPIO.BCM and not GPIO.BOARD scheme, also make sure to look were you don’t need to connect resistors (yellow rows) and where you do need to connect resistors (white rows) Code Overview, Compile and run 42 of 114...
In this example we’ll show the current time of our raspberry pi system on the 4 segment LED display. Please note, you’ll need to configure the right timezone through the “sudo raspi-config” settings else the time you’ll see might be different from the actual time zone you are at right now.
Page 44
Introduction In this lesson we’ll learn how to use the matrix display. The matrix display is very similar to the segment LED just instead of only few LED’s to give us numbers the matrix LED is many of many LED’s stand in a shape of matrix, this allows us to turn on entire rows, columns or individual LED’s on the matrix.
Page 45
Hardware required For this example just as the previous one we’ll need 8 220 or 330ohm resistors, combining 220 and 330 or using just one type of them will work. Please make sure to note the right connection of the resistors in order for this example to work correctly. Material diagram Material Name Number (amount)
Page 46
Connection Diagram There are many pins that we need to connect and to some of them we need to attach resistors, please look carefully and make sure to follow the diagram. Connection LED MATRIX Raspberry Pi pin1 GPIO26 pin2 GPIO19 pin3 GPIO13 pin4...
Page 47
LED MATRIX Raspberry Pi pin13 GPIO12 pin14 GPIO16 pin15 GPIO20 pin16 GPIO21 Code Overview, Compile and run In this example we’ll active the matrix LED in heart shape, we create an array of LED’s and then decide which LED will be on and which one will be off creating a heart shape by the numbers 1 and 0. Then we go for each place in the array of numbers and send turn on the LED that states 1 (on) and leave the LED off that states 0 (off) Compile the script by going into the samples directory and running: python3 matrix_heart.py...
Application effect The matrix will turn on in a shape of heart, leaving certain LED’s on and certain LED’s off. LESSON 11: 9G SERVO Introduction In this lesson we’ll learn about the 9G servo. The 9G servo is a very useful module allows us to use a servo in certain degree, that allows us to attach certain materials such as wire, cardboard or 3D printed parts in order to perform certain movements or actions in this lesson we’ll learn how to move the servo around by giving it the degree we want it to move to.
Page 49
Hardware required The hardware is pretty straight forward, we don’t need any resistors or special components on this one. We’ll use the servo and connect it to the breadboard using the jumpers, follow the diagram to make sure to connect the servo to the correct GPIO pin.
Page 50
Connection Diagram Red wire for 5V positive black is for the negative, the orange wire which we’ll use for PWN commands will be connected directly to GPIO18. Connection Servo Raspberry Pi Yellow wire GPIO18 Red wire Black wire 50 of 114...
Page 51
Code Overview, Compile and run What we are going to do with our 9G servo is quite simple. We will first initiate the class “sg90” that already have everything pre-coded and prepared for us with the parameter “0” as the initial direction. Then will turn it left by setting the direction to 100 and speed of 80 (out of 100) to turn it to the other direction to the right, we will turn it to -100 (opposite of 100) with the same speed of 80.
LESSON 12: STEP MOTOR Introduction In this lesson we’ll learn about the step motor, step motor similar to the servo is another kind of “motor” but unlike the servo it can turn up to 360 degrees and keep turning around to both direction. The step motor is controlled by a special “driver”, without this driver we are unable to control the step motor directly from the raspberry pi.
Page 53
Hardware required For this example we’ll need 2 special components, the first one obviously will be the step motor but the second one will be the ULN2003 step motor driver board. As we mentioned before, without this driver board we’ll be unable to control the step motor directly.
Page 54
Connection Diagram Please note the diagram is not 100% correct. We’ll need to connect the step motor to the driver first and then follow the diagram to connect the driver to the raspberry pi or T-Cobbler plus. Connection We have total of 4 OUTPUT GPIO pins (IN1,2,3, and 4) that we’ll use to control the steps of the step motor. Step motor Raspberry Pi GPIO12...
Page 55
Code Overview, Compile and run Let’s take a look at our code, the main code will initialise the step motor object and then we’ll run a demo of different type: first demo will be to turn 1 step, then 20 steps, then quarter turn by degree and close the motor. As we can see, we have 2 type of function: 1.
Application effect Running the program will cause the step motor to turn one step, then 20 steps, then quarter turn and at the end stop. You can change the interval of the step motor to make it move slower or faster. LESSON 13: ULTRASONIC RANGING Introduction In this lesson we’ll learn about the ultrasonic ranging sensor.
Page 57
Hardware required The main component we’ll need is the HCSR04 ultrasonic sensor, it’s difficult not to recognise it as it looks like 2 robotic eyes. The sensor have 2 different type of connections which we will explain on the next page, please pay attention to it. Material diagram Material Name Number (amount)
Page 58
Connection Diagram In the connection diagram we have the 2 basic pins one is the negative and the other is the positive (black and red wires) The other wires are the dat wires called TRIG and ECHO we’ll use them to send a pulse and to get back response so we can determine the distance by the time it takes for the pulse to return back to the sensor.
Page 59
Component Raspberry Pi TRIG GPIO23 ECHO GPIO24 Code Overview, Compile and run The distance sensor code is very straight forward. We will measure the pulse and how long it takes it to come back so we will know the distance from the sensor to the object in front of it.
Application effect The distance sensor will measure the distance and afterwards print in the console the distance that it found in cm. LESSON 14: TOUCH LAMP Introduction In this lesson we’ll learn about the touch sensor. The touch sensor is very familiar to the button we used in the previous lessons just except a physical key press there’s capacitive touch surface that we can touch and detect it.
Page 61
Hardware required The main hardware parts we’ll need for this lesson is the touch sensor and the RGB LED we used earlier in previous lesson. The touch sensor is very easy to distinguish, you’ll see there is some kind of “finger print” painting on it, the finger print stands for the finger that will touch the sensor to detect the touch.
Page 62
Material diagram Material Name Number (amount) 40P GPIO Cable Breadboard Jumper wires Several Connection Diagram In the connection diagram we can see that we are going to connect the RGB LED just as we did in previous lessons to GPIO17,27 and 22. The touch sensor have 3 different pins, one is the positive (VCC) another is negative (GND) and GPIO pin that we will configure as GPIO.IN to receive a finger touch over the sensor.
Page 63
Connection RGB LED Raspberry Pi GPIO17 GPIO27 GPIO22 Touch sensor Raspberry Pi GPIO18 Code Overview, Compile and run In our example we’ll use both RGB LED and touch sensor, when pressing the touch sensor, we will randomly choose one colour: red green or blue. Then we will turn the LED of the randomly chosen colour. If we stop touching the touch sensor, the LED will turn off.
Application effect When touching the touch sensor, a colour will be chosen randomly by the script, either red, green or blue. Then the LED will turn on. If the touch sensor is released, the LED will turn off. LESSON 15: PCF8591 MODULE Introduction The PCF8591 module an 8-bit A/D Converter &...
Page 65
The PCF8591 module features I2C pin header on one side, and I2C connector on the opposite side. Hence, it's more flexible to connect the board to your development system. The board also supports I2C cascading, allowing the use of multi module connected to the I2C bus at the same time by connecting the pin header and connector. Please note that we will use the PCF8591 module for many of our lessons from this point on.
Page 66
Material diagram Material Name Number (amount) T-Cubbler Plus 40P GPIO Cable Breadboard Jumper wires Several Connection Diagram The connection diagram is pretty straight forward, the PCF8591 have to sides left side and right side, we’ll use the left side to connect it to our Raspberry Pi and the right side later on to connect with components and sensor. The left side can be treated as output and the right side as input.
Page 67
Connection PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run The code is quite simple and we won’t be changing it for the next couple of lessons, the same code can apply when using the components as well. Using the smbus library we connect to the port A0 address which we will be using in the next few lessons, then we get the value and print it out, pretty straight forward.
Application effect Running the program will result in value change based on the PCF8591 itself. No component is attached yet. LESSON 16: FLAME SENSOR Introduction The flame sensor can be used to detect fire or other wavelength at 760 nm ~ 1100 nm light. In the fire-fighting robot game, the flame plays an important role in the probe, which can be used as the robot's eyes to find fire source or football.
Page 69
Hardware required The main component will be the PCF8591 and the flame sensor. While connecting the flame sensor we’ll also need to use a 10K ohm resistor, please make sure it’s 10K ohm and not 10 ohm. The resistor will go directly to the flame sensor and then to the input pin of the PCF8591 module as will be shown in the next page.
Page 70
Material diagram Material Name Number (amount) Jumper wires Several Connection Diagram The connection is simple, we’ll need to connect the short pin of the flame sensor (the negative pin) to the resistor and to the GND pin as well as to AINT0 pin on the PCF8591 module. The long pin of flame sensor will go directly to 5V on the raspberry pi (there are 2 5V pins so you could use one for the PCF8591 and the other one for the flame sensor) If you forgot how to connect the PCF8591 module to the raspberry pi, refer to the previous lesson.
Page 71
Flame sensor Raspberry Pi Short Pin Long Pin AINT0 PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run We use the same script that we used earlier, by attaching the flame sensor, by introducing flame to it either by lighter or candle the value will change.
Page 72
Application effect Running the program will show a value that changes based on the flame sensor, if flame is introduced the value will be higher. If no flame the value will be lower. LESSON 17: PHOTO RESISTANCE SENSOR Introduction As the resistance of the sensor varies depending on the amount of light it is exposed to, the output voltage changes with the ligth intensity.
Page 73
Hardware required The main hardware component will be the photo resistance sensor, it’s small so it’s a little hard to notice. We’ll need 10K ohm resistor as well to connect the photo resistance sensor to the PCF8591 module, make sure you take the 10K Ohm and not the 10 Ohm resistor accidentally.
Page 74
Material diagram Material Name Number (amount) 40P GPIO Cable Breadboard Jumper wires Several Connection Diagram The diagram is very similar to the previous we’ve made. Let’s take a look over the photo resistance pins, it doesn’t have a short or long one. We’ll need to connect one pin to the 10K ohm resistor and then to the GND as well as to the AINT0 pin on the PCF8591 module.
Page 75
Connection Photo-resistance sensor Raspberry Pi Pin 1 Pin 2 AINT0 PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run 75 of 114...
This time after attaching the light sensor to the PCF module the value will change based on the amount of light currently in the room, try to switch of or on the light or introduce different source of light such as your mobile phone flash light to see the value changing.
Page 77
Introduction The resistance of a thermistor increases when the ambient temperature decreases, so the RPI can detects the voltage and thus to calculate the current temperature.The detection range of this sensor is between -40 to 125 degrees Celsius with an accuracy of ±1.5℃. Same as our previous lessons we’ll use the PCF8591 module to connect the thermistor to the raspberry pi and calculate the temperature.
Page 78
Hardware required The main component in this lesson is the thermistor sensor, it looks like LED with a small black pin at the end of it. We’ll also need the 10K ohm resistor from the previous lessons to connect to the thermistor and GND pin. Please make sure not to confuse 10K ohm resistor with 10 ohm resistor.
Page 79
Connection Diagram As the diagram states, we’ll leave the PCF8591 as we did before. The thermistor doesn’t have specific pins so one pin we connect to the GND through the 10K ohm resistor as well as to AINT0 at the PCF8591 module. The other pin we connect directly to 5V pin, there are 2 5V pins so there is no need in pushing them together at the same spot.
Page 80
Code Overview, Compile and run As in our previous examples, the PCF8591 module will change the value based on the thermistor sensor. Compile the script by going into the samples directory and running: python3 pcf8591.py Application effect Running the program will show different value based on the temperature of the thermistor sensor, the higher temperature the higher the value.
LESSON 19: POTENTIOMETER Introduction In this example, we use a potentiometer, we read its value using one analog input of an RPI board and we change the blink rate of the built-in LED accordingly. The resistor's analog value is read as a voltage because this is how the analog inputs work.
Page 82
Hardware required The main hardware we’ll be using is the potentiometer, unlike the previous examples for the potentiometer we won’t be in need in using 10K ohm resistors due to the resistance of the potentiometer itself. And offcourse, we’ll need to use the PCF8591 module as well to read the value out of the potentiometer. Material diagram Material Name Number (amount)
Page 83
Connection Diagram The diagram stays the same as previous lessons except we don’t connect the resistor right now as we have no use in it for the potentiometer. The potentiometer have 3 pins, GND, VCC and AINT0 make sure to connect the correct pins to the right places. Connection Component Raspberry Pi...
Page 84
PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run This time as we use the potentiometer it will require us to do some manual action, But turning the potentiometer either right or left it will turn the value, higher or lower. By doing so we can control multiple things such as brightness of LED’s etc …...
By running the program it will show the value of the potentiometer, to change the value need to turn the potentiometer physically left or right, this will change his value. LESSON 20: WATER LEVEL MONITORING Introduction This is a water level measurement experiment, it is relatively simple to achieve, only need to read the value of the analog port (A0 or others), and then converted to a percentage.
Page 86
Hardware required We’ll need the water sensor as our main hardware component and connect it to the PCF8591 to get the value once the water has made a contact. Same as our previous examples, for the water sensor we have no use in 10K ohm resistors. Material diagram Material Name Number (amount)
Page 87
Connection Diagram The water sensor have 3 pins, we connect the negative to GND, the positive to 5V and the S pin, the one we use for the GPIO to AINT0. Once the circuit is closed by watering touching the surface of the water sensor it will send signal to the AINT0 pin and we’ll be able to know the amount of water over the sensor.
Page 88
Water sensor Raspberry Pi AINT0 PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run For this example as we use the water sensor, by introducing drops of water to the sensor the value will change. The more water the higher values. But please do note: the water sensor is not waterproof and wasn’t meant to be submarined under the water.
Application effect By running the script the value will change based on the amount of water drops on the sensor, the higher amount of water the higher the value will be. LESSON 21: JOYSTICK Introduction This experiment is to learn how to use the joystick of the analog output and digital output. The joystick experiment will be our last lesson using the PCF8591 module.
Page 90
By finishing the PCF8591 lessons, we hope that you will be able to create any analog circuit for any project that you wish for and continue making everything - easier! Hardware required For the lesson we’ll need the joystick module which is very easy to be recognised. We’ll also need the PCF8591 module, connected to the circuit same as the previous lessons.
Page 91
Material diagram Material Name Number (amount) T-Cubbler Plus 40P GPIO Cable Breadboard Jumper wires Several Connection Diagram The Joystick have 5 pins, 2 of them are the GND and the VCC which goes to 5V pin. The rest are VRX, VRY and SW. make sure to connect those pins to the right place on the PCF8591 module.
Page 92
Connection Joystick Raspberry Pi AINT2 AINT1 AINT0 PCF8591 Raspberry Pi SDA1 SCL1 Code Overview, Compile and run This time note that unlike the previous examples we need to connect to 3 pins of the PCF8591 module instead of one. We need to connect to 0,1 and 2. (one for each direction the joystick will move) After doing so, it should work just fine with a new script we’ve created specially for the pcf8591 called pcf8591_joystick.py Compile the script by going into the samples directory and running: python3 pcf8591_joystick.py...
Application effect Running the script will show values changing based on the joystick direction, try to move it to different directions to see the value changing. LESSON 22: IR REMOTE Introduction In this lesson, we use the lirc library to read infrared signals returned by buttons of the remote control and translate them to button values.
Page 94
Hardware required For this lesson we’ll need to use the IR receiver which looks like a small LED with black pin on the end of it (don’t confuse it with the flame sensor we used earlier, it has 2 pins) as well as the remote control to send the signals to the IR receiver to accept.
Page 95
Material diagram Material Name Number (amount) Breadboard Jumper wires Several Connection Diagram In order for the remote control to send the signal, we just need the remote control itself. But what if we want to accept the signal on the other side, on the raspberry pi? We’ll need to plug the IR receiver to the GPIO pins.
Page 96
Connection Raspberry Pi GPIO21 Code Overview, Compile and run Before we start, make sure that you’ve installed the lirc and python-lirc drivers at the beginning of our lessons. Without the drivers, the lesson will not work properly and you won’t be able to use your IR LED. 96 of 114...
The code is quite simple but a little difficult to understand as we use sockets, it’s not as clean as previous code we used. We receive data rom the IR LED and then we convert the data, after converting it we are able to tell which button exactly was pressed on the IR remote.
Page 98
Introduction In the previous lesson we learned how to accept the commands from the IR remote control and receive them through our python code on the raspberry pi. But what’s the interesting thing in that? During this lesson we’ll take the IR remote control project a little further and we will control the LED using the IR remote control, we’ll learn how to configure specific button to have a specific function to turn our LED once pressed.
Page 99
Material diagram Material Name Number (amount) IR Remote IR Receiver 220/330ohm resistor Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable Breadboard Jumper wires Several Connection Diagram We’ll keep the connection from our previous lesson regarding the IR receiver but this time we connect the LED as well.
Page 100
Connection Raspberry Pi Long Pin (+) GPIO27 Short Pin (-) Raspberry Pi GPIO21 Code Overview, Compile and run Tips: Refer to the operation demo (Step4 to Step7). 100 of 114...
Application effect Running the program, turns on an LED on for one second, then off for one second, repeatedly. LESSON 24: DHT11 101 of 114...
Page 102
Introduction This lesson will teach you how to use DHT11 module, which is simple and easy to use. The DH11 module is a temperature and humidity combined module, it’s affordable and relatively accurate. It is very useful in multiple IoT projects such as smart home or environment monitoring. It can be used both indoor and outdoor.
Page 103
Hardware required The main component we will use is the DHT11, it can be easy recognisable as its blue top layer. Material diagram Material Name Number (amount) DHT11 Module Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable Breadboard Jumper wires Several 103 of 114...
Page 104
Connection Diagram The connection is straight forward, our DHT11 sensor have 3 pins: GND, VCC (5V) and data OUT. Using the data out pin we’ll be able to get the values of the temperature and the humidity. The data pin goes directly to GPIO4 pin while the VCC goes to 5V and GND goes to GND.
Page 105
Code Overview, Compile and run Within the DH11 script we will use the adafruit DHT library which will allow us to get the data from the sensor. We will specific that we use sensor 11 as the DHT family have multiple sensors and the one we use is the DHT-11. In one line of code (line 33) we are going to get both temperature and humidity and print them out if they are not empty.
LESSON 25: LCD1602 WITH IIC Introduction This is an experiment on how to use LCD1602 with IIC, the next lesson will do a temperature and humidity monitoring experiment. In this lesson we’ll just show “hello world” text on our LCD screen to show a good example how we can use the LCD to show certain text.
Page 107
Hardware required The main component we’ll be using is the LCD1602, we won’t be in need in any resistors here. Material diagram Material Name Number (amount) LCD1602 with IIC Raspberry Pi Board T-Cubbler Plus 40P GPIO Cable Breadboard Jumper wires Several 107 of 114...
Page 108
Connection Diagram The connections are quite simple, make sure you put the SDA and SCL pin in the correct locations or you won’t be able to see any data on the LCD display. We don’t need any resistors here so you can connect it directly to the raspberry pi without any problems. Connection LCD1602 Raspberry Pi...
Page 109
Code Overview, Compile and run The code is very simple. We will initialise the LCD using the Adafruit char lcd library, we will turn the backlight so we can see what we print on the screen, we will clean the script just in case some text left from before and then we show a message of “hello world”...
Application effect The LCD will show “hello world” message, you can interrupt the script by pressing CTRL+C or CTRL+Z LESSON 26: TEMPERATURE AND HUMIDITY MONITORING Introduction This is a more complex experiment, it can show the monitoring of indoor temperature and humidity, and in the LCD above display value.
Page 111
Hardware required To this example we’ve also added the DHT11 module, we’ll need both the DHT11 and the LCD module in order to accomplish this lesson, make sure to prepare them both. Material diagram Material Name Number (amount) DHT11 Module LCD1602 with IIC Raspberry Pi Board T-Cubbler Plus...
Page 112
Connection Diagram Connection DHT11 Raspberry Pi DATA OUT GPIO4 LCD1602 Raspberry Pi SDA1 SCL1 112 of 114...
Page 113
Code Overview, Compile and run Our DHT LCD example is very similar to the previous LCD example except this time we don’t just show “hello world” message, we’ll get the current temperature and humidity values from our DH11 sensor and then we gonna display then over the LCD screen.
Page 114
Application effect Running the program will turn on the LCD and show the current room temperature and humidity from the DHT11 sensor. 114 of 114...
Need help?
Do you have a question about the Raspberry Pi & Arduino Starter Kit and is the answer not in the manual?
Questions and answers