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
€66.35
List Price:  €94.79
You save:  €28.44
£55.27
List Price:  £78.97
You save:  £23.69
CA$97.91
List Price:  CA$139.89
You save:  CA$41.97
A$107.61
List Price:  A$153.73
You save:  A$46.12
S$94.02
List Price:  S$134.32
You save:  S$40.30
HK$544.76
List Price:  HK$778.26
You save:  HK$233.50
CHF 61.99
List Price:  CHF 88.57
You save:  CHF 26.57
NOK kr773.52
List Price:  NOK kr1,105.08
You save:  NOK kr331.55
DKK kr494.87
List Price:  DKK kr706.99
You save:  DKK kr212.12
NZ$119.04
List Price:  NZ$170.06
You save:  NZ$51.02
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,334.01
List Price:  ৳11,906.24
You save:  ৳3,572.23
₹5,905.12
List Price:  ₹8,436.24
You save:  ₹2,531.12
RM312.96
List Price:  RM447.10
You save:  RM134.14
₦117,219.95
List Price:  ₦167,464.25
You save:  ₦50,244.30
₨19,380.58
List Price:  ₨27,687.73
You save:  ₨8,307.15
฿2,429.14
List Price:  ฿3,470.35
You save:  ฿1,041.21
₺2,412.08
List Price:  ₺3,445.98
You save:  ₺1,033.89
B$405.06
List Price:  B$578.68
You save:  B$173.62
R1,267.31
List Price:  R1,810.53
You save:  R543.21
Лв129.73
List Price:  Лв185.34
You save:  Лв55.60
₩97,779.80
List Price:  ₩139,691.42
You save:  ₩41,911.61
₪261.55
List Price:  ₪373.67
You save:  ₪112.11
₱4,130.77
List Price:  ₱5,901.36
You save:  ₱1,770.58
¥10,901.93
List Price:  ¥15,574.86
You save:  ¥4,672.92
MX$1,414.26
List Price:  MX$2,020.46
You save:  MX$606.19
QR254.33
List Price:  QR363.35
You save:  QR109.01
P948.83
List Price:  P1,355.53
You save:  P406.70
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,478.50
List Price:  E£4,969.50
You save:  E£1,491
ብር8,583.46
List Price:  ብር12,262.61
You save:  ብር3,679.15
Kz63,877.12
List Price:  Kz91,256.94
You save:  Kz27,379.82
CLP$67,980.58
List Price:  CLP$97,119.28
You save:  CLP$29,138.70
CN¥507.18
List Price:  CN¥724.58
You save:  CN¥217.39
RD$4,200.06
List Price:  RD$6,000.34
You save:  RD$1,800.28
DA9,338.81
List Price:  DA13,341.73
You save:  DA4,002.91
FJ$158.92
List Price:  FJ$227.04
You save:  FJ$68.12
Q538.38
List Price:  Q769.16
You save:  Q230.77
GY$14,583.53
List Price:  GY$20,834.51
You save:  GY$6,250.97
ISK kr9,640.42
List Price:  ISK kr13,772.62
You save:  ISK kr4,132.20
DH696.78
List Price:  DH995.44
You save:  DH298.66
L1,273.82
List Price:  L1,819.82
You save:  L546
ден4,077.60
List Price:  ден5,825.40
You save:  ден1,747.79
MOP$559.09
List Price:  MOP$798.74
You save:  MOP$239.64
N$1,260.89
List Price:  N$1,801.35
You save:  N$540.46
C$2,566.52
List Price:  C$3,666.61
You save:  C$1,100.09
रु9,423.16
List Price:  रु13,462.23
You save:  रु4,039.07
S/264.65
List Price:  S/378.10
You save:  S/113.44
K280.62
List Price:  K400.90
You save:  K120.28
SAR262.75
List Price:  SAR375.38
You save:  SAR112.62
ZK1,926.57
List Price:  ZK2,752.36
You save:  ZK825.79
L330.17
List Price:  L471.69
You save:  L141.52
Kč1,676.98
List Price:  Kč2,395.79
You save:  Kč718.80
Ft27,187.34
List Price:  Ft38,840.72
You save:  Ft11,653.38
SEK kr769.78
List Price:  SEK kr1,099.74
You save:  SEK kr329.95
ARS$70,112.88
List Price:  ARS$100,165.56
You save:  ARS$30,052.67
Bs483.65
List Price:  Bs690.96
You save:  Bs207.30
COP$308,470.35
List Price:  COP$440,690.82
You save:  COP$132,220.46
₡35,450.59
List Price:  ₡50,645.88
You save:  ₡15,195.28
L1,762.11
List Price:  L2,517.41
You save:  L755.29
₲543,153.02
List Price:  ₲775,966.15
You save:  ₲232,813.12
$U2,992.07
List Price:  $U4,274.58
You save:  $U1,282.50
zł287.83
List Price:  zł411.21
You save:  zł123.37
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.