Skip to main content
shopping_basket Basket 0
Login

Remote Flying Fish Project Part 5: Motor Testing with Remote XY

lokit
0

In this chapter, we will build a simple mobile application to control the speed and rotation of motors.

To simplify the overall design and reduce the difficulty, RemoteXY is selected as the medium APP creator.

Setup

To begin with, browse http://remotexy.com/en/editor/ and you will see an editor view displaying the layout of the mobile app.

Firstly, click the 'Bluetooth' button on the right-hand side under 'Configuration', it can select the module of the Arduino board and Bluetooth. The following interface will be shown.

Make sure that Bluetooth module HM-10 and Arduino board NANO are selected in the configuration panel.

Secondly, set the connection interface to Hardware Serial. Serial port and data transferring speed are left auto-configured.

After that, drag two Button and one Slider from the tool panel into the app area, you can adjust to the size at free will.

Then, click the Buttons and select the pin number to Pin 7

You can also add up to 5 elements in total for other control purposes. For elements more than 5, you will need to pay for the APP or get a limitation of use time of 30 seconds.

Run-Time

By then, click the green button Get source code to prepare the Arduino code for the controller programme. Log in is required before proceeding to the result page as shown below.

Do not forget to download and install the latest library from http://remotexy.com/en/library/, otherwise, there will be an error during compiling.

Download the Arduino code by clicking 'Download code'. A zip file will be downloaded. Zip it and open the '.ino' file.

A simple Arduino code will be generated. However, it needs some changes in order to control the speed and the rotation of the motor. Please add the BOLD code in the Arduino program. Make sure you remove the connection of 'TX1' and 'RX1' Pins between the Arduino board and Bluetooth before uploading the code. Otherwise, an error will be shown.

/////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,3,0,0,0,57,0,8,13,0,
4,128,20,50,64,9,2,26,129,0,
13,40,18,6,17,83,112,101,101,100,
0,1,0,16,16,12,12,2,31,67,
108,111,99,107,0,1,0,61,17,12,
12,2,31,65,110,116,105,45,99,108,
111,99,107,0 };

// this structure defines all the variables of your control interface
struct {

// input variable
int8_t slider_1; // =0..100 slider position
uint8_t button_1; // =1 if button pressed, else =0
uint8_t button_2; // =1 if button pressed, else =0

// other variable
uint8_t connect_flag; // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////

#define PIN_BUTTON_1 7
#define PIN_BUTTON_2 7
#define PIN_SLIDER_1 9


void setup()
{
RemoteXY_Init ();

pinMode (PIN_BUTTON_1, OUTPUT);
pinMode (PIN_BUTTON_2, OUTPUT);
pinMode (PIN_SLIDER_1, OUTPUT);
// TODO you setup code

}

void loop()
{
RemoteXY_Handler ();

//digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1==0)?LOW:HIGH);
//digitalWrite(PIN_BUTTON_2, (RemoteXY.button_2==0)?LOW:HIGH);

analogWrite(PIN_SLIDER_1, RemoteXY.slider_1*2.55);

if(RemoteXY.button_1==1){

digitalWrite(PIN_BUTTON_1, HIGH);

}

if(RemoteXY.button_2==1){

digitalWrite(PIN_BUTTON_2, LOW);

}


// TODO you loop code
// use the RemoteXY structure for data transfer


}

According to the code, we selected Pin 7 as the direction of the motor, and Pin 9 as the PWM/speed of the motor. The minimum and maximum value of PWM is 0 to 255, so we multiply the 'RemoteXY.slider_1' by 2.55. If the buttons are pressed, it will change the voltage into HIGH or LOW to change the direction.

Testing by Mobile

Download an application from APP Store or Play Store.

Open the Application on your mobile or devices.

Press the '+' on the right upper corner to add a new device connection.

Select 'Bluetooth LE' and select your Bluetooth device.

It will automatically change into the interface you designed in RemoteXY. Now you can test the motor.

Demo

Now we can move on to the next chapter and start to design our own PCB :)

You can download the pdf version of this chapter in the Download section below.

 Parts in this series

lokit has not written a bio yet…

Recommended Articles

DesignSpark Electrical Logolinkedin