BTSmartFan Servo/DC motor controlled using Bluetooth
Fork of BTSmartFan_WIZwiki-W7500 by
Prerequisite
This example is to control a servo motor and DC motor using bluetooth.
To implement this function, you need a Platform board, Easy Module Shield V1, Bluetooth module, DC jack, 5V DC Power Supply.
Below are what we used.
- WIZwiki-W7500 from WIZnet (Platform board)
- Arduino Motor Shield
- Easy Module Shield(Not mandatory)
- HC-05 bluetooth module
- Servo motor(DM-S0300D)
- DC motor(5V)
- DC jack
- 5V DC Power Supply
Hardware Configuration
WIZwiki-W7500 Pin map
Arduino Motor Shield + DC motor(5V) + DC jack + 5V DC Power Supply
Easy Module Shield(Not mandatory) + HC-05 bluetooth module + Servo motor(DM-S0300D)
Software
BlueTerm (Application)
download a BlueTerm App to send a command message to bluetooth module with smart phone.
Pins setting
main.cpp
Serial pc(USBTX, USBRX); Serial bt(PA_14, PA_13); Servo myservo(D14); PwmOut Motor(D3); DigitalOut direction(D12);
Baud rate
main.cpp
pc.baud(115200); //bt.baud(115200); bt.baud(9600);
main.cpp
- Committer:
- stkim92
- Date:
- 2017-04-13
- Revision:
- 4:fc863bb15b24
- Parent:
- 3:1751a2ebf652
File content as of revision 4:fc863bb15b24:
/** ****************************************************************************** * @project Smart BT Fan * @author Justin Kim * @version V1.0.0 * @date 29-JUN-2015 * @brief Main program body ******************************************************************************* **/ /* Includes ------------------------------------------------------------------*/ #include "mbed.h" #include "Servo.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ #if defined(TARGET_WIZwiki_W7500) Serial pc(USBTX, USBRX); Serial bt(PA_14, PA_13); Servo myservo(D14); PwmOut Motor(D3); DigitalOut direction(D12); #endif #if defined(TARGET_WIZwiki_W7500ECO) Serial pc(USBTX, USBRX); Serial bt(PA_13, PA_14); //echo Servo myservo(P10); //echo PwmOut Motor(P21); //echo DigitalOut direction(P29); //echo #endif /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Main Function * @param None * @retval None */ int main(void) { char ch; pc.baud(115200); //bt.baud(115200); bt.baud(9600); pc.printf("Hello World!\n\r"); bt.printf("Hello World!\r\n"); direction.write(1); Motor.period_ms(1); while(1) { if(bt.readable()) { ch=bt.getc(); pc.printf("%c",ch); bt.printf("%c",ch); if(ch == '*') { myservo = 0.5; } else if(ch == '+') { myservo = myservo + 0.1; } else if(ch == '-') { myservo = myservo - 0.1; } else if(ch == '@') { Motor.write(0.8); } else if(ch == '!') { Motor.write(0); } } else if(pc.readable()) { ch=pc.getc(); bt.printf("%c",ch); pc.printf("%c",ch); if(ch == '*') { myservo = 0.5; } else if(ch == '+') { myservo = myservo + 0.1; } else if(ch == '-') { myservo = myservo - 0.1; } else if(ch == '@') { Motor.write(0.8); } else if(ch == '!') { Motor.write(0); } } } }