IoT with MuleSoft: Implementing a Temperature Sensor using LED lights, Twilio, and a Raspberry PI

Updated: Apr 13

Hey Muleys,

In this post, I will explain how to implement IoT with a MuleSoft use case. I would like you to try out some new use cases and publish them. I hope this article helps you to implement them!

First of all, why should you use MuleSoft to implement IoT? Why not use other integration platforms? Quick answer: Ease of Integration and Speed of Delivery.

Let's dive in.

Make sure to watch the videos posted at the end of the article! You will get a full idea on how easy it is to implement IoT with MuleSoft.

What is IoT?

The Internet of Things (IoT) is the inter-network of physical devices, vehicles, buildings, and other items embedded with electronics, software, sensors, actuators, and network connectivity that enable these objects to collect and exchange data.

Simplified: IoT is about connecting software with hardware!

MuleSoft + IoT:

  • The Mule engine can be embedded directly into IoT devices, which enables data exchange for the devices by connecting to IoT cloud services and backend apps in the cloud.

  • The Mule Runtime engine can be used to expose APIs on any IoT device. Mule APIs can be deployed on IoT devices and turn them on and off.

  • In this article we will discuss about IoT and how it can be used with MuleSoft, and how Mule APIs can be deployed on IoT devices.

Use Case

When a user passes a receiver’s number in the URL, the receiver should read the current local temperature details to his mobile and on successful receiving of details on his mobile, a green LED light should be blinked. In case of any issue in receiving the details, the red LED light should be blinked instead.

How does it work internally?

When you hit this endpoint:

  1. The request is sent to the Mule application.

  2. The receiver’s number is stored in a variable.

  3. The Mule application connects to Raspberry PI (IoT device) and senses the temperature using a temperature sensor.

  4. The temperature is stored in a variable.

  5. The Mule application sends the details to the receiver’s mobile number using the Twilio Connector.

  6. If the data is received as expected, a green LED light is blinked, otherwise it will be a red LED light.

Let's cook the recipe

Required Software:

Required Hardware:

  • Raspberry Pi 3

  • Micro SD Card of 16GB

  • Ethernet Cable or HDMI cable (in this use case we are using ethernet cable)

  • Adapter Charger for Raspberry Pi 3: Available in electronic stores or any e-commerce websites as a combo.

I was able to find everything here.


  • 4k7 ohms (4.7k) - 1 (used for temp sensor)

  • 22k ohms: 2 in total (used for RED and GREEN LED lights)

  • Jumper wires: Male – Female (10 for safe side)

  • 1 Bread Board

  • Temperature Sensor: DS18B20 model

  • 1 red LED light

  • 1 green LED light

Part 1 - Setting up your environment

Before starting with the Raspberry PI setup, we have to follow these steps.

Step 1: Download and Install Raspberry Pi OS / Raspbian OS

Download Raspbian OS (URL can be found in Required Software above). Select “Raspbian Buster with desktop and recommended software”. It’s almost 2.5 GB.

While it’s downloading, insert your micro SD card into your system and format it using the SD Card formatter.

Now extract the downloaded Raspbian OS into your local. You can see only one file of the type Disk Image.

We can’t unzip them normally. That’s the reason we use Win32 disk imager: to extract and copy them to the Micro SD card.

Open the Win32 disk imager and you will see that the destination folder will be automatically detected (the SD card). Just select the file where you have extracted Raspbian and click on write. It takes around 9 mins to finish. Once it’s done it will say that the writing was successful.

Now your OS is copied successfully in your SD card.

Step 2: Enable SSH

The SSH command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications.

Since we need to see what’s happening in the Raspberry PI, we will need a UI to see this. In order to set this up, we need to have SSH enabled.

Go to the SD card folder where you can see the extracted files (they were extracted using Win32 disk imager). Now just create a text file and name it as ssh.

After creating this, you can remove the SD Card from your PC.

Step 3: Network and Sharing

Now we need to connect our Raspberry device to our system. As I said before, we have 2 ways. One is using an HDMI cable which requires WiFi sharing, a monitor, a keyboard and a mouse to perform operations. To go for the alternative, it’s better to use an ethernet cable which helps us to get connected with our PC itself.

For this article, we are using ethernet connectivity.

After ejecting the SD card from the PC, mount the SD card to your Raspberry PI. See the slot where it needs to be inserted (usually it will be on the downside of the device). Plug the adaptor and switch it on.

Now connect the ethernet cable: one side should be connected to the Raspberry PI and the other to your PC. Make sure your PC is already connected to WiFi or internet before plugging the ethernet cable.

Once the ethernet cable is plugged to your PC. Go to the Network and Sharing center. You will see an unidentified network. You can refer to the next screenshot.

Click on the internet connection which you have already connected to and click on WiFi – properties.

Go to Sharing and make sure the 2 options in Internet Connection Sharing are checked. Also see that Home networking connection is automatically generated with the name “Ethernet” (you can go through the video I shared at the end to verify these steps).

Click on unidentified network (ethernet). Go to Properties and double click on Internet Protocol Version 4 (TCP/IPv4). Under “Use the following IP add