Jesse Casman
Published

Mobile Control of DC Motor Using Renesas AE-CLOUD1 Kit

In this tutorial, you'll use the Renesas AE-CLOUD1 kit to learn how to use a mobile app to control the speed and direction of a DC motor.

IntermediateFull instructions provided6 hours349
Mobile Control of DC Motor Using Renesas AE-CLOUD1 Kit

Things used in this project

Hardware components

S5D9 IoT Fast Prototyping Kit
×1
DC motor (generic)
Small hobby DC motor that will work in the range of 3V-5V and draw less than 600mA
×1
Motor Drivers
Texas Instruments Motor Drivers
Texas Instruments L293DNE quad half H-bridge motor driver. Any standard H-bridge or half H-bridge motor driver IC will work as long as the current capacity matches the motor you choose. It also has to work with 3.3V input logic levels. If you use a different motor driver, you’ll have to modify the schematic accordingly.
×1
Robust 5V power supply that can supply 1A
This tutorial uses the same supply to power both the L293DNE chip logic and the L293DNE motor driver. They can be supplied separately, but to keep things simple, this tutorial just uses 5V. Usually, the motor is powered from a separate supply which can be as high as 36 volts. For this tutorial it is fine to use the same supply as long as it is a good one. If you have doubts or if you are using a motor that requires higher voltage, you can provide VCC1 (internal logic supply) and VCC2 (motor drive supply) separately. GND is shared.
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Renesas e2studio 5.4.0.023
Diagnostics Intelligence source code (on GitHub)

Story

Read more

Schematics

Schematic for the PMOD connector

Code

Base Python module

Python
Double click on the Base Python module and replace the code with this Python code snippet
'''
LED Toggle and Blink Workflow
This workflow allows you to control the LED on the board from the cloud. 

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

TOGGLE LED:
- 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

#Toggle 
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")


#Blink

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")

Code snippet #2

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

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

TOGGLE LED:
- 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

#Toggle 
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")


#Blink

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")

Credits

Dan Kane

Posted by Jesse Casman

Comments

Add projectSign up / Login