Connecting Raspberry Pi to AWS IoT

Introduction to Amazon Web Services (AWS) IoT Connecting Things to AWS IoT Core
12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.10
List Price:  €95.86
You save:  €28.76
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.49
List Price:  CA$143.56
You save:  CA$43.07
A$111.96
List Price:  A$159.95
You save:  A$47.99
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.16
List Price:  HK$777.41
You save:  HK$233.24
CHF 62.56
List Price:  CHF 89.37
You save:  CHF 26.81
NOK kr792.29
List Price:  NOK kr1,131.89
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.74
List Price:  NZ$176.78
You save:  NZ$53.04
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,330.24
List Price:  ৳11,900.85
You save:  ৳3,570.61
₹5,945.56
List Price:  ₹8,494.03
You save:  ₹2,548.46
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,149.19
List Price:  ₦154,505.46
You save:  ₦46,356.27
₨19,403.53
List Price:  ₨27,720.51
You save:  ₨8,316.98
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,454.67
List Price:  ₺3,506.82
You save:  ₺1,052.15
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,282.09
List Price:  R1,831.63
You save:  R549.54
Лв131.15
List Price:  Лв187.37
You save:  Лв56.21
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪254.67
List Price:  ₪363.83
You save:  ₪109.16
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,949.58
List Price:  ¥15,642.93
You save:  ¥4,693.35
MX$1,405.49
List Price:  MX$2,007.92
You save:  MX$602.43
QR254.12
List Price:  QR363.05
You save:  QR108.92
P963.49
List Price:  P1,376.48
You save:  P412.98
KSh8,999.72
List Price:  KSh12,857.29
You save:  KSh3,857.57
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,689.79
List Price:  ብር12,414.52
You save:  ብር3,724.72
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,143.42
List Price:  CLP$98,780.55
You save:  CLP$29,637.13
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,244.94
List Price:  RD$6,064.47
You save:  RD$1,819.52
DA9,440.04
List Price:  DA13,486.35
You save:  DA4,046.31
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q537.12
List Price:  Q767.35
You save:  Q230.22
GY$14,584.29
List Price:  GY$20,835.60
You save:  GY$6,251.30
ISK kr9,693.35
List Price:  ISK kr13,848.23
You save:  ISK kr4,154.88
DH701.59
List Price:  DH1,002.31
You save:  DH300.72
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,127.89
List Price:  ден5,897.23
You save:  ден1,769.34
MOP$558.06
List Price:  MOP$797.27
You save:  MOP$239.20
N$1,283.39
List Price:  N$1,833.49
You save:  N$550.10
C$2,565.21
List Price:  C$3,664.75
You save:  C$1,099.53
रु9,482.30
List Price:  रु13,546.73
You save:  रु4,064.42
S/259.58
List Price:  S/370.84
You save:  S/111.26
K282.68
List Price:  K403.85
You save:  K121.16
SAR262.90
List Price:  SAR375.59
You save:  SAR112.68
ZK1,929.21
List Price:  ZK2,756.13
You save:  ZK826.92
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.83
List Price:  Ft39,690.03
You save:  Ft11,908.20
SEK kr772.17
List Price:  SEK kr1,103.14
You save:  SEK kr330.97
ARS$71,242.69
List Price:  ARS$101,779.64
You save:  ARS$30,536.94
Bs481.71
List Price:  Bs688.19
You save:  Bs206.47
COP$305,135.87
List Price:  COP$435,927.07
You save:  COP$130,791.20
₡35,171.10
List Price:  ₡50,246.58
You save:  ₡15,075.48
L1,769.55
List Price:  L2,528.04
You save:  L758.48
₲543,563.42
List Price:  ₲776,552.46
You save:  ₲232,989.03
$U3,109.25
List Price:  $U4,441.97
You save:  $U1,332.72
zł286.15
List Price:  zł408.81
You save:  zł122.65
Already have an account? Log In

Transcript

Video 2.3 connecting a Raspberry Pi to AWS IoT. In this video, they will learn the following connecting sensor to Raspberry Pi installing AWS IoT Python SDK programming Raspberry Pi testing connecting sensor to Raspberry Pi. In this project we will be using and head CSS zero for ultrasonic sensor, which will measure the distance between the source and the target using ultrasonic waves. It has four pins Vcc trigger input, a code bird and a ground pin. The ultrasonic sensor generates a high frequency sound and calculates the time taken for sending a signal and receiving an echo. Therefore, it can be used to measure distance.

Basically it consists of a transmitter, a receiver and a control module. I will explain the working principle in three simple steps First, in order to generate the I dress Sonic sound, we need to set the trigger pin in high state for at least 10 microseconds, then the sensor will send eight cycles Sonic burst, which will travel at the speed of the sound. Finally, if there is any object or an obstacle in its path, then it will bounce back to the receiver, which is the echo pin. Based on the travel time and the speed of the sound, we can calculate the distance. We use simple physics to do this, we know that speed is equal to distance by time. So distance is equal to speed into time, which is speeding duty by to speed, the speed of sound traveling in air, which is 343 meters per second, nothing but 34,300 centimeter per second, T by two wondering why I did this.

This is because the transmitter sends a signal out and then receives the same signal back on reflection. So the total distance and time taken is twice So distance is equal to 34,300 divided by two into t. This gives us 17,150 into T in centimeters. To know more details about the sensor, you can check out the data sheet that is in the resources section. Now we'll start connecting this sensor to the Raspberry Pi. Before you start correcting the sensor, you will need two resistors wondering why here is the reason the echo output pin is a five volt, but the GPIO pin of Raspberry Pi can tolerate up to 3.3 volt. so five volt cannot be directly given to the 3.3 volt input pin.

So we'll use a voltage divider circuit using appropriate resistors to bring down the voltage to 3.3 volts or even less than 3.3 volt voltage divider circuit. This is the voltage divider circuit here near Veen. But if we are giving exports as input then the output At V out, we'll be less than experts based on the resistor values, we can calculate the resistance values using this formula, V out is equal to V in into r two divided by r1 plus r two. So stepping down the voltage from five to 3.3, I'm using one key and two key ohm resistors. In this demo, if you don't have the above mentioned resistors, you can choose any combination of resistors that will satisfy this condition circuit diagram. First, we will place the two resistors in series, one K resistor and then two K resistor.

Now, one of our two is grounded. So connecting the ground pin on the sensor and the ground pin of raspberry pi to one end of our tube. Now given the input five volts to mean so I will be connecting the echo pin which gives a five volt output to one end of the resistor r1. Now V out will be 3.3 volts So connecting V out to GPIO 24. So we have connected the echo pin to GPIO 24, the voltage divider in the middle to step down the voltage. Now, the trigger pin can be directly connected to GPIO 23.

Finally, giving the power supply. I'm connecting the five volt output pin of raspberry pi to the VCC pin on the sensor. I'm attaching the circuit diagram in the resources section. You go through the carefully and make the appropriate connections. Remember, do not connect the echo pin directly use a voltage divider to bring down the voltage to 3.3 volts or is it can burn your Raspberry Pi. As we have completed the hardware connections, let's now install AWS IoT Python SDK in Raspberry Pi.

But wait, why should we install this? Yeah, you are right. AWS IoT Python SDK allows us to Write the Python script which helps devices to access the AWS IoT platform through mq TT. I hope everyone is familiar with mq TT. If not, let's learn the basics. In Qt T stands for message queuing telemetry transport.

Let me explain this to you in basic terms. In mq TT, we will have one broker to which all the devices get connected. A device basically publishes a message on to a topic or subscribes to a particular topic for receiving messages. Okay, to be more clear topic is similar to a filter. topics are the way you register interest for incoming messages, or how you specify where you want to publish the message. Suppose, imagine that you have a light sensor and a temperature sensor connected to your Raspberry Pi.

Also, assume that you have a belt and an AC with the temperature is more, it should send a message to AC and when it's dark, it should send a message to the bulk telling To turn on, but how here, a broker comes into the picture. A broker is primarily responsible for receiving all messages, filtering the messages, deciding who is interested in them, and then publishing those message to all subscribed clients. Okay, now it's time to install AWS IoT Python SDK, open your putty terminal and run these commands. You can find these commands in the resources section. This first command is for installing the SDK on your pipe. Yeah, it's done.

Now, this will have installed the AWS directory on your pipe. Let's navigate into the directory using the second command. Yes. Now, inside this directory, install the Python setup file using the third command. Since we did not log in with root, we will use sudo in the beginning of the command. Now, your Raspberry Pi is almost ready to connect with AWS IoT Core Send the sensor data.

So now we'll go to the final step programming the Raspberry Pi. Clear. Now, we will open the Python file and write the code. So sudo nano test project.pi open the repository that you have downloaded at the beginning of this course. Here, select section two. Now select video 2.3 open the Python file and copy the code and paste it in the test project dot p right now, we will understand the code.

We first imported the libraries that are required in this project. First importing our PI GPIO library and then the time library. This is for importing SDK packages. Here we are initializing the GPIO pins. The GPIO dot BCM means you're referring the pins by the Broadcom SOC channel number. These are the numbers After GPIO for example, GPIO 23 means GPIO number is 23.

But it is not the physical location of the pin on the Raspberry Pi. Next, this is the client name. I'm using the client name as my client ID, but you can use any name of your choice. Next, we will be giving the endpoint. In our case, we will be giving the host address for this address, go to the AWS IoT Core manage things, select the thing that you created in the previous video, which is my art buy. Here you can find interact, select that.

Now, this will be your host address, select and copy this. Now going back to putty and pasting the endpoint address. Next, we will be giving the location of our certificates for mutual authentication purpose. This will be the address where messages advocates are present slash home slash pi slash search slash and then my three certificates. You can see that I have copied the same location where my certificates are present on Raspberry Pi. Next, when there is an unstable internet connection or power supply, the AWS SDK provides an internal cue to store the mq TT messages.

Here. This command allows a connection to the client and This command will publish we can give any name in place of maker dummy here we are initializing trigger and echo pins to pin 23 and pin 24. And here we are setting the pins as GPIO out and GPIO in trigger pin will be the output pin and echo pin will be the input pin. You first need to set the trigger pin to high for 10 microseconds for sending an ultrasonic sound signal. here first we are making showed that the output is low by setting it too low for first two seconds, and then we'll make it high for 10 microseconds and again low. Next, after sending a 10 microsecond signal, we will be calculating the pulse width here, based on when the signal is St. And when it's echo has ended.

This is the formula that we have derived at the beginning of this video, we are rounding the distance up to two decimals. The range of sensor is two centimeters to 400 centimeters. So if the distance is within the limits, then we'll initialize the payload with the distance values. initializing payload here. This will print the distance values present in the payload. The data in the payload will be published to the mq TT topic maker dummies slash data.

Here, I'm printing the data in JSON format. Now to save the file, click Ctrl x, then y, and then enter. Now, make sure that the hardware connections are correct, and then run the Python script using the command Python test project.pi. Now, here you can see the distance by placing an object. I'll place the object at different distances from the sensor, which you can see accordingly. Are you excited to check if the data is being sent to the cloud in AWS IoT on the left hand side, you can find test selected and now you must give the topic name.

The topic name is maker dummies slash data and subscribe. Now, you can see the same data here in the cloud Hurry, we have completed sending the sensor data from Raspberry Pi to AWS IoT. In this video, we learned the following connecting sensor to Raspberry Pi, installing AWS IoT Python SDK interests byte programming Raspberry Pi testing. In the next video, we will connect ESP 32 to AWS IoT Core, the first steps

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.