Building IoT devices with JavaScript

Using JerryScript and mbed OS 5 on ARM-based microcontrollers

With mbed OS 5 you can use JavaScript to write the code for your IoT devices. It combines a small JavaScript VM with a professional and well-tested ecosystem, allowing you to write fast, secure and battery-efficient applications that run on a $2 microcontroller.

Watch our talk at JSConf Asia

var led = DigitalOut(D0);
var button = InterruptIn(D1);

button.fall(funtion() {
	led.write( ? 0 : 1);

More than a JavaScript runtime

Small footprint

We make use of the JerryScript runtime, which runs on devices with just 64K of RAM. The runtime sits on top of mbed OS, our IoT platform operating system.

Large ecosystem

With over a hundred supported development boards, and thousands of well tested libraries, the mbed ecosystem gives you a strong platform for development.

Epic community

Since 2008, the mbed OS developer community has grown to over 200,000 developers, working on a diverse range of IoT applications.

Getting started

1. Grab an mbed OS 5 development board with at least 64K of RAM.

2. Install node.js, Gulp, and mbed CLI and its dependencies.

3. Connect your development board to your computer - it mounts as a mass storage device.

4. From a terminal, run:

$ git clone
$ cd mbed-js-repl-example
$ npm install
  # Find out your target name by clicking on 'mbed.htm' 
  # on the mass storage device and looking in the top right corner.
$ gulp --target=YOUR_TARGET_NAME

5. Drag build/out/YOUR_TARGET_NAME/mbedos5.bin (or mbedos5.hex) onto the mass storage device.

6. Blinky should be running!

7. Connect a serial monitor to your development board (on baud rate 115,200) to directly interact with the board.

JavaScript on mbed examples


A super simple example that blinks an LED on your target development board via digital out.

View on GitHub »

Bluetooth Low Energy

This application exposes two services: one to show a (fake) battery level, and one to control LED1.

View on GitHub »

Connect to the internet

An example that allows you to connect a device to the internet over WiFi, Ethernet, 6LoWPAN or Thread.

View on GitHub »

As well as these examples, we have an introductory JavaScript on mbed OS blog which provides a detailed overview of the work we've done so far, and a guide to writing bindings for C++ libraries.

Frequently asked questions

I want to use a particular model of sensor, how do I do that?

You can use thousands of mbed C++ libraries to interact with sensors and actuators, but you'll need a C++ to JavaScript binding. If such a binding has not been published, you'll have to provide that to use the library from JavaScript. Follow these instructions, and we'd love it if you pushed the bindings to npm (so they are one npm install mbed-js-your-binding away).

What is the performance impact?

The code within the JavaScript VM runs about a hundred times slower than equivalent C++ code. That sounds like a lot, but everything underneath your application (like drivers, network stacks, crypto) is still C++, so the actual impact will be less noticeable.

How is this different to Johnny Five on Arduino?

With Johnny Five your JavaScript application runs on your computer and then controls your device over USB. With JavaScript on mbed the application runs completely on your device. In other words, you can unplug the device and run it "standalone".

How is this different to node.js on a Raspberry Pi or Tessel 2?

The main difference is power consumption. A Raspberry Pi 3 consumes 220 mA current in idle mode. A microcontroller can use 100,000x less power while in deep sleep. A Bluetooth beacon running JavaScript on mbed can run at least a year on a coin cell.

Can I code without a device?

Not really, but there is a very experimental simulator.

I want to get involved!

That's great! We're just getting started with this project, and we'd love your help. You can help in the following ways:

Contribute code

All of our code is open source (Apache 2.0), and we're happy to welcome contributions. Our main repositories are:

Give feedback or report bugs

Both can be reported at our GitHub repository.

JSConf Asia 2016 - JavaScript on mbed