IoT Projects: Raspberry Pi vs Arduino
When embarking on IoT projects, you have to choose the best platform to build your application. People often ask which platforms they should use for what kinds of projects. The answer does depend on what your goals are for your IoT project and what you plan for it to do. In this article, we will discuss when it is best to use Arduino and when to use Raspberry Pi, in some cases, we’ll discuss when you might even want to incorporate both devices into your solution.
In the case of both the Arduino and the Raspberry Pi several models are offered. As of this writing the most common Arduino model is the Arduino Uno so we’ll use that as a baseline reference for the Arduino. With the Raspberry Pi there are several models as well. The Raspberry Pi Model B+ and Raspberry Pi 2 Model B+ are the most common so we’ll use their capabilities as the reference point.
It’s important to realize what the Arduino really is. It’s a microcontroller, not a full fledged computer. It doesn’t have an operating system, or a file system. The processor on these devices is quite simple and cannot multitask between several applications. The Arduino is entirely focused on executing a specific task even if that task involves reading multiple sensors or controlling multiple components via output pins. The typical Arduino device has a very small amount of RAM, about 2KB, and 32KB of flash memory for your application storage. For data values that might change during the execution of your application, but need to be preserved, there is also 1KB of EEPROM storage. With this relatively low amount of computing power available it’s easy to see why only small, highly focused applications can run on an Arduino.
The Raspberry Pi is a substantially more powerful device, but that power comes with some responsibilities that aren’t requirements for Arduino devices. The Raspberry Pi is a full computer. Typically the Raspberry Pi will run some version of the Linux operating system. Recently, Microsoft has made a version of Windows 10 available for the Raspberry Pi 2 as well. In addition to running the operating system the Raspberry Pi can readily be connected to a network via Ethernet, provides ports to connect USB input devices like keyboards and mice, and has an HDMI connector for video output. The Raspberry Pi works pretty much like any PC or Mac that you would load Linux onto albeit with lower performance than PC hardware from even 5 years ago. Most Raspberry Pi models have 512MB or more of RAM making them quite capable of running several programs concurrently. Permanent storage is usually an SD card which is generally from 4 to 32GB in size.
Despite the Raspberry Pi’s advantages, the fact that an Arduino does not have an operating system or a file system can actually be an asset. For one thing, there is no need to worry about an SD card. Your IoT application is directly loaded into flash memory on the Arduino itself. Since there is no OS or file system to worry about your device can be powered up or down at any time. This is of great importance if the device is located where power availability is intermittent. Full fledged computers, like the Raspberry Pi require some time to boot up and need to be shut down in an orderly fashion to ensure no data is corrupted.
With the Arduino’s limited program storage and very small SRAM the efficiency of your application is important. For that reason, applications are generally written in C/C++ using the Arduino IDE. The applications written for the Arduino are rather appropriately called Sketches because they are generally of a very short nature. Their focus is on interacting with the hardware devices you’ve connected to the Arduino and perhaps transmitting data or receiving commands from another computer.
The Arduino provides a complete set of 14 digital and 6 analog inputs and outputs. That lets you turn items on and off (digital) and detect digital changes in state of connected components. Unlike the Raspberry Pi the Arduino also has a complete set of analog inputs. These can be used to measure applied voltages to respond to analog changes in things like temperature, light levels, etc. For cases where you need to apply analog output the Arduino also supports pulse-width-modulation (PWM) which is a means of setting an analog level on a component (like the brightness of an LED). In addition to the the array of inputs and outputs the Arduino also has a hardware design that allows add-on boards, called shields, to be coupled to it. These extend the basic, built-in I/O capabilities to controls things like motors, or add network capabilities.
The Raspberry Pi also provides 8 I/O pins, but they are all digital in nature. If you wish to interact with analog devices you’ll need to wire up an additional chip to the digital pins to interact with those devices. A common means of doing this is through a chip called the MCP3008 which costs under $4. There are also a selection of boards for the Raspberry Pi sometimes referred to as HAT (Hardware Attached on Top) which are similar in overall concept the Arduino shields.
This is an area where the Raspberry Pi has a big lead. The majority of Raspberry Pi boards come with an ethernet connector right on the board. The USB ports found on the Raspberry Pi also makes it easy to hook a WiFi dongle up to the Raspberry Pi and obtain network connectivity that way.
The Arduino provides no built-in network connectivity except in higher priced Arduino boards like the Arduino Yun. For Arduino projects that require network connectivity various shields are available to support either ethernet or WiFi connectivity. These shields however, can add significant costs to your project; often costing as much as the Arduino itself. In addition, the power requirements of the shield may result in the need to add a larger power supply to your project.
As mentioned earlier the Arduino itself is a relatively low power device that can run on a 9V battery or a battery pack with six AA cells. The board itself can supply power to a simple circuit you might create for your project. The addition of shields and a larger set of sensors, display panels, etc. may increase power requirements which might require a separate power supply. The Arduino itself can also be powered off its USB port or from an AC power adapter.
The power requirements of Raspberry Pi are more significant. Most Raspberry Pi projects rely on powering the device from a 5V micro USB power source that outputs at least 1 to 2 amps depending upon what version of the Raspberry Pi you are running. The Pi also has a much narrower range of voltage tolerance and really needs a constant 5 volts. The Arduino is much more tolerant accepting recommended input voltages from 7V to 12V. The current draw and consistent voltage requirement makes the Raspberry Pi unsuitable for being powered by most typical dry-cell batteries as their voltage output generally drops off as they discharge.
Base price for an “official” Arduino Uno is $25 and a Raspberry Pi costs $35. However, that $35 Raspberry Pi still needs a power supply, and an SD card to do anything. The base cost of the Raspberry Pi is closer to $50.
There are several sources of Arduino Uno boards besides the official version from the Arduino foundation. Some of these boards are available for less than $10 although their quality can vary. The Arduino needs a power source which typically costs less than $5 and is otherwise ready to go unless you need network connectivity. If you need network access and are not planning to hook the Arduino directly to the Raspberry Pi via a USB cable you’ll have to either buy a networking shield ($15 to $30) or a version of the Arduino with network support included like the Arduino Yun ($75). As a way to obtain Arduino like functionality with WiFi support at a lower cost, some of us have also begun experimenting with boards based on the ESP8266. These boards can be found between $5 and $10 and our experience with them may be the subject of a future blog post.
On November 26th, the Raspberry Pi foundation released the Raspberry Pi Zero with an attractive price point of $5. It should be noted that this very low priced version is in short supply at the moment, but in coming months these should be more commonly available. The Zero does not come with a Ethernet port so networking is commonly added by connecting a WiFi adapter to the USB port. The Pi Zero also has lower power requirements which may make it somewhat more suitable to battery powered applications, however the requirement for orderly shutdown of the system still exists.
Many people find benefit in incorporating both devices into their projects. The network and processor capabilities of the Raspberry Pi make it ideal to serve a web user interface for your project or communicate with cloud-based IoT services which often have IoT client libraries that are too large to fit in the memory of an Arduino device. The Johnny-Five framework mentioned earlier allows sensors connected to an Arduino to be controlled from a Raspberry Pi. This is useful for developers who need to write a more complex application than can fit in the memory of an Arduino and don’t want the added burden of managing code bases across multiple pieces of hardware.
Some solutions use a hub and spoke model where the Arduino devices connect to the Raspberry Pi over a local network and the Raspberry Pi then acts as the interface to the web. You can imagine a single Raspberry Pi managing most of the sensors and devices in your home and providing not only an API to interact with the sensors, but also serve a web experience as well.
There is no simple answer. It really depends on the requirements of your project. I’ve summarized some of the decision points in the table below. The IoT device market is quite strong right now and new boards appear on the market frequently. New entrants, like the Raspberry Pi Zero, may shift your decision point in the months to come. One thing is for certain, this is an exciting and dynamic market.