Friday, 8 July 2016

IoT Adventure: 1 - Setting up Raspberry Pi with sensors

Case

For our Internet of Things experience we use the Raspberry pi 2. With the raspberry it’s easy to connect different sensors and program them to work. There are many connections on the Raspberry, from HDMI to USB and GPIO. 
To connect the sensors to the Raspberry you can use the GPIO (General Purpose Input/Output) pins on the Raspberry board. In figure 1 you will see a picture of the Raspberry pi with the GPIO headers marked.


Figure 1 : Raspberry Pi














You can find more information about the GPIO on the following wiki page : GPIO header.

Solution
Here you will find a brief description about the layout of the GPIO header, including some explanation of the function of the different pins. Also a simple example how to connect the pins with a breadboard.
Once you understand the basics behind the GPIO you will notice that it is pretty easy to work with.
You can use every GPIO PIN on the board as an Input or Output connector. For example you can use one of the pins to receive temperature information from a sensor as input to the Raspberry Pi or you can use a pin as output to turn on or off a LED.

In order for you to make use of these pins as input or output channels you have to write code in programming languages such as Python, C#., VB etc and upload it to the Raspberry Pi. You will find more about the programming in other blogposts.


1) Layout 
There are different Raspberry pi models, we are using the Raspberry pi B/B+ model. For more information about the different models see: Raspberry models
In figure 2 you will find the pin connections (GPIO Header) of the Raspberry Pi 2 B/B+
tip: Print this layout on paper and keep it near your Pi

Figure 1: Pin layout
Figure 2: Pin layout

There are 17 GPIO pins available, all the green pins in figure 1 are standard GPIO pins. But there are more pins.




































Below a brief summary of the remaining pins:
  • PIN 2 and 4 have an output of 5 V
  • PIN 1 and 17 have an output of 3,3V
  • PIN 3 and 5 are used for the I2C protocol (see wiki: I2C Protocol ) (SDA stands for Serial Data and SCL stands for Serial Clock).
  • PIN 19, 21, 23, 24, 26 are used for the Serial Peripheral Interface (SPI) BUS (see wiki: SPI Bus)
  • PIN 8 and 10 are used for Universal Asynchronous Receiver/Transmitter (UART) (see wiki: UART). It is possible to send data from multiple sensors using 1 wire (serial) instead of using 1 wire per sensor.
In the beginning all the different functions of the pins can be a bit daunting, but in our experience it suffices to use the common GPIO pins for the most sensors.


2) Wire Colours
In our posts we will be using the following wire colour standards;
- 3,3V pins: orange wire
- 5V pins: red wire
- GND pins: black wire
- Common GPIO pins: green wire
- I2C pins: blue wire
- UART pins: white wire
- Overall pins: yellow wire
- between the different components: Grey

It’s not necessary for you to use all the different colors I just described, you can use any color (especially if you don’t have all the colors).

3) Breadboard?
When you bought a Raspberry Pi Starters Kit, most likely they included a breadboard. A breadboard is an easy way to plug and unplug LED’s, Resitors, Sensors and more without soldering. They layout of a breadboard is pretty straight forward (if you know what you are doing). 
 
Figure 3 shows the breadboard as it is included in the Starters kit.
Figure 3: Breadboard









In the picture the horizontal line (row) is marked as number 1. The horizontal line is used to connect the 5 or 3,3 Volt pins to the + row and the GND (Ground) pin to the - row. Connecting the pins to these horizontal lines enables you to power the entire board with 5 or 3,3 Volt.


The vertical lines (depicted as the number 2 marker in Figure 2) are to be used to connect the sensors to either the horizontal lines to power the sensor or directly to the GPIO pins on the Raspberry Pi. With the horizontal lines it is usefull to know that it doesnt matter how high or low you connect the wires. The entire vertical line is used to connect to the horizontal line or the GPIO pins on the Raspberry Pi.

The breadboard is split in two, so you can use e.g. one side for the 3,3V+ and the other side for the 5V


4) Connection a sensor
Now that I have described the GPIO header layout and the breadboard we can try something simple like connecting a LED to our Raspberry Pi. In this post we will only explain how to properly connect the sensor and not how to write the correct code to activate/deactivate the sensor. The code will be explained in other posts per sensor using C#, which is our choice of code.

Figure 3 depicts how to use a 3,3V GPIO pin and a GND pin and connect it to the horizontal lines.
- GPIO pin 1 (3,3V) is connected to the breadboard pin using a orange wire
- GPIO pin 6 (GND) is connected to the breadboard using a black wire
- A 560 Ohm Resistor is connected via pins 10C and 14C to protect the power supply to the LED
- A Red led is connected via pins 14E and 15E

When you turn on the Raspberry Pi the LED will light up.

Figure 4: Breadboard


Figure 5 is a power schema of how you can connect the components to the Raspberry. In my opinion the best thing to do is first drawing a power schema. And then connect the components to the breadboard. By drawing a power schema you can see where you have to put the components and calculate e.g. the resistors.
Figure 5: Power schema



Conclusion
In this case I described the GPIO Header layout and how to connect a simple component like the LED. 
Figure 6 is the end resulate of this case.This is just the basic, from here you can build your empire of sensors ;)  
In other blogposts we will describe how to program the sensors. 


Figure 6: the end




















Note
For the schematics we are using Fritzing.

No comments:

Post a Comment

All comments will be verified first to avoid URL spammers. यूआरएल स्पैमर से बचने के लिए सभी टिप्पणियों को पहले सत्यापित किया जाएगा।