Mobile Control of a DC Motor Using the S5D9


In this tutorial, you’ll learn how to use the Medium One mobile app to control the speed and direction of a DC motor. The emphasis of this tutorial is on how to use the mobile app rather than how to drive a DC motor from the S5D9. That was covered in the two tutorials listed below.


-Medium One IoT Controller App available on the app store or Google Play.

-Optional Medium One Mobile App quick start guide

It is not necessary to complete the entire guide if you already have Renesas/Medium One account set up to use the Intelligent Diagnostics application with the S5D9 board.

-This tutorial extends “Cloud Driven DC Motor Control Using the S5D9” Parts 1 and 2 available here:

Both of the above tutorials left the original blink/toggle LED functionality in place. It is possible to follow this tutorial without building the DC motor circuit or modifying the binary. Rather than changing the motor speed and direction as discussed below, you’ll just toggle the yellow LED and blink the red LED from your phone on the mobile app.


The mobile app has a different set of available widgets than the the dashboard. In this tutorial you’ll configure a mobile slider widget to transmit motor speed (led blinks) to the S5D9 board. The mobile app has a switch widget which you’ll configure to transmit direction information (yellow LED toggle) to the board. Unlike the boolean widget used by the desktop in the motor control tutorial, the switch widget transmits a string which is either ‘on’ or ‘off.’ You’ll modify workflows to accommodate this change.

Getting the account user, password, and API information correct on the mobile app requires extra care, so the tutorial will walk through those steps.

Step 1: Configure the Mobile App Project

Make sure that your desktop dashboard works and that you can control both the motor direction and speed (or alternatively the LED toggle and blink functions). You need to gather the following 4 pieces of information: active project name, API key, user name, and user password. Note first the active project name in the upper right hand corner.

Next, get the API key you are using. I usually email it to myself so that on my phone I can just copy and paste it rather having to type it all in.

On the dashboard, verify the active username. The default is a long string of characters. It may also be a good idea to email this to yourself so you can copy and paste once you start configuring the mobile app.

Finally, you need to obtain your password. I had multiple password emails from Renesas for multiple projects and multiple S5D9 boards. I tried the one that seemed correct, and it did not work. A sure fire way to get the password correct is to create a new one as shown below. Make sure you create the new password for the user you recorded above.

Now that you have the 4 necessary pieces of information ready, you can create a profile in the mobile app. The following instructions are based on my Android phone. The iphone app looks a little different but you can accomplish the same things with a little experimentation.

On the opening ‘Profiles’ screen, click on “+” and the ‘Settings’ screen will open. Enter the 4 pieces of information that we just obtained, and VERY IMPORTANT in the drop down menu change the setting from ‘Sandbox’ to ‘Renesas.’ Save, and if your credentials are all correct, you’ll see the final screen below. The “+” allows you to add widgets.

Add both a Slider and a Switch. The slider will control the motor speed, and the switch will control the motor direction.

In the Android app, swipe the slider left to reveal the settings options. The first icon allows you to set the stream to ‘raw’ and the second icon allows you to set the tag to ‘blink’. The slider therefore transmits exactly the same information as the desktop blink slider which transmits motor speed.

The switch settings require a little explanation. You can’t just use the toggle tag, because we changed the raw:toggle value to boolean. Since the switch transmits a string (either ‘on’ or ‘off’) we’ll need to create a new tag to transmit. Set the switch stream to “raw” and the tag to “mobile_direction”. The tag doesn’t exist yet, so if you press the switch button several times, the tag will be transmitted and auto-detected in the cloud.

On the desktop dashboard navigate to Config → Data Streams and edit the ‘raw’ stream.

Find the ‘mobile_direction’ tag and check the empty box to its right then scroll all the way down and click ‘Save Stream.’

Step 2: Update the Workflows

In the ‘LED Toggle and Blink’ workflow double click on the Base Python module and add a third input.

Now drag a raw:mobile_direction trigger onto the work space and connect it to the new 3rd input as shown below:

Double click on the Base Python module and replace the code with the following:

LED Toggle and Blink Workflow
This workflow allows you to control the LED on the board from the cloud. 

- Triggered by sending an event with format {"blink": n}, where 'n' is a number
- The red LED on the board will blink 'n' times

- Triggered by sending an event with format {"toggle": n}, where 'n' is a number 
- If 'n' is 1, the yellow LED on the board will turn on
- If 'n' is 0, the yellow LED on the board will turn off
- If 'n' is neither, the yellow LED on the board will switch states from on to off or vice versa

By default, we have only the red LED blink and only the yellow LED toggle. If desired, this
is customizeable. In this workflow, an event is sent to the board in the format of 'L2:' for
toggle or 'B4:' for blink. The '2' and '4' specify which LED to toggle/blink. Change this number to
the following values to change the LEDs controlled:
- Green: 1
- Yellow: 2
- Green + Yellow: 3
- Red: 4
- Green + Red: 5
- Yellow + Red: 6
- Green + Yellow + Red: 7

Last Updated: May 1, 2017

Author: Medium One

# November 3, 2017 Modification by DK
# Re-purpose toggle tag to control DC motor direction
# raw:toggle trigger is now boolean.  'true' = 1 = forward
# false = 0 = reverse
# Blink is a number between 0 and 100 which still blinks the red LED
# but now also sets the motor speed PWM duty cycle in %

# November 6, 2017 Modification by DK
# Added a third trigger, mobile_direction, from the mobile app
# It is a string - either 'on' or 'off' and it will be used to 
# control the motor direction

import MQTT

if IONode.is_trigger('in1'):
    motor_forward = IONode.get_input('in1')['event_data']['value']
    if motor_forward == True:
        MQTT.publish_event_to_client('s5d9', 'L2:1')
        log("LED turned on, DC motor set to forward")
        log("Desktop toggle")
    else: # motor_forward == False
        MQTT.publish_event_to_client('s5d9', 'L2:0')
        log("LED turned off, DC motor set to reverse")
        log("Desktop toggle")
#    else:
#        MQTT.publish_event_to_client('s5d9', 'L2')
#        log("LED toggled")


elif IONode.is_trigger('in2'):
    blink = IONode.get_input('in2')['event_data']['value']
    MQTT.publish_event_to_client('s5d9', 'B4:' + str(blink))
    log("LED blinked " + str(blink) + " times")
elif IONode.is_trigger('in3'):  #mobile trigger
    switch_state = IONode.get_input('in3')['event_data']['value'] # switch_state is a string - either 'on' or 'off'
    if switch_state == "on":
        MQTT.publish_event_to_client('s5d9', 'L2:1')
        log("LED turned on, DC motor set to forward")
        log("Mobile on")
    else: # switch_state == "off"
        MQTT.publish_event_to_client('s5d9', 'L2:0')
        log("LED turned off, DC motor set to reverse")
        log("Mobile off")

Once you save and activate the code and connect everything as in part 2 of the Cloud-driven-dc-motor-control-using-the-s5d9 tutorial, you’ll be able to control the speed and direction of the motor via your phone.

If you choose not to build the circuit and only want to test the mobile functionality by blinking and toggling LEDs, you should still add a boolean user input widget on the desktop if you want to have that functionality. Because we changed the user input toggle slider to the boolean input widget, the original dashboard toggle slider won’t work with the new code. However, the mobile widget will work fine.

Next Steps:

If you completed all three parts, you now have a motor controlled completely from your phone. By adding mobile control of a servo and perhaps some LEDs there might be a good Halloween project for next year?? If you put a pulley on the motor you could definitely have fun with a spider dropping down onto people. My 7 year old liked that idea…


I just received an email from Renesas that their system automatically reset the user password that I had set while writing this tutorial, so my mobile app no longer worked. I went back and followed the procedure to change my password to the same one I had used before, and that I had entered in the mobile profile. Everything worked as expected again, and the mobile app correctly linked to the project. I’m not sure why my password was automatically changed, but if that happens to you, simply reset the password and everything will connect again.



Customizing the Medium One mobile app to control a DC motor using the S5D9 is explained in detail in this tutorial here. I had a chance to see Dan’s setup personally. He gave me a very nice live demo! It was so cool in action that I took a quick video. I think it helps explain the whole setup nicely. Here it is in action: