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@4:fc863bb15b24, 2017-04-13 (annotated)
- Committer:
- stkim92
- Date:
- Thu Apr 13 01:55:15 2017 +0000
- Revision:
- 4:fc863bb15b24
- Parent:
- 3:1751a2ebf652
revision a mistake.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:7441087c2a16 | 1 | /** |
justinkim | 0:7441087c2a16 | 2 | ****************************************************************************** |
justinkim | 0:7441087c2a16 | 3 | * @project Smart BT Fan |
justinkim | 0:7441087c2a16 | 4 | * @author Justin Kim |
justinkim | 0:7441087c2a16 | 5 | * @version V1.0.0 |
justinkim | 0:7441087c2a16 | 6 | * @date 29-JUN-2015 |
justinkim | 0:7441087c2a16 | 7 | * @brief Main program body |
justinkim | 0:7441087c2a16 | 8 | ******************************************************************************* |
justinkim | 0:7441087c2a16 | 9 | **/ |
justinkim | 0:7441087c2a16 | 10 | |
justinkim | 0:7441087c2a16 | 11 | /* Includes ------------------------------------------------------------------*/ |
justinkim | 0:7441087c2a16 | 12 | #include "mbed.h" |
justinkim | 0:7441087c2a16 | 13 | #include "Servo.h" |
justinkim | 0:7441087c2a16 | 14 | |
justinkim | 0:7441087c2a16 | 15 | /* Private typedef -----------------------------------------------------------*/ |
justinkim | 0:7441087c2a16 | 16 | /* Private define ------------------------------------------------------------*/ |
justinkim | 0:7441087c2a16 | 17 | /* Private variables ---------------------------------------------------------*/ |
stkim92 | 3:1751a2ebf652 | 18 | |
stkim92 | 3:1751a2ebf652 | 19 | #if defined(TARGET_WIZwiki_W7500) |
justinkim | 0:7441087c2a16 | 20 | Serial pc(USBTX, USBRX); |
justinkim | 0:7441087c2a16 | 21 | Serial bt(PA_14, PA_13); |
justinkim | 0:7441087c2a16 | 22 | Servo myservo(D14); |
justinkim | 0:7441087c2a16 | 23 | PwmOut Motor(D3); |
justinkim | 0:7441087c2a16 | 24 | DigitalOut direction(D12); |
stkim92 | 3:1751a2ebf652 | 25 | #endif |
stkim92 | 3:1751a2ebf652 | 26 | |
stkim92 | 3:1751a2ebf652 | 27 | #if defined(TARGET_WIZwiki_W7500ECO) |
stkim92 | 3:1751a2ebf652 | 28 | Serial pc(USBTX, USBRX); |
stkim92 | 3:1751a2ebf652 | 29 | Serial bt(PA_13, PA_14); //echo |
stkim92 | 3:1751a2ebf652 | 30 | Servo myservo(P10); //echo |
stkim92 | 3:1751a2ebf652 | 31 | PwmOut Motor(P21); //echo |
stkim92 | 4:fc863bb15b24 | 32 | DigitalOut direction(P29); //echo |
stkim92 | 3:1751a2ebf652 | 33 | #endif |
stkim92 | 3:1751a2ebf652 | 34 | |
stkim92 | 3:1751a2ebf652 | 35 | |
justinkim | 0:7441087c2a16 | 36 | |
justinkim | 0:7441087c2a16 | 37 | /* Private function prototypes -----------------------------------------------*/ |
justinkim | 0:7441087c2a16 | 38 | |
justinkim | 0:7441087c2a16 | 39 | /* Private functions ---------------------------------------------------------*/ |
justinkim | 0:7441087c2a16 | 40 | /** |
justinkim | 0:7441087c2a16 | 41 | * @brief Main Function |
justinkim | 0:7441087c2a16 | 42 | * @param None |
justinkim | 0:7441087c2a16 | 43 | * @retval None |
justinkim | 0:7441087c2a16 | 44 | */ |
justinkim | 0:7441087c2a16 | 45 | int main(void) |
justinkim | 0:7441087c2a16 | 46 | { |
justinkim | 0:7441087c2a16 | 47 | char ch; |
justinkim | 0:7441087c2a16 | 48 | pc.baud(115200); |
stkim92 | 1:1ad093d2a110 | 49 | //bt.baud(115200); |
stkim92 | 1:1ad093d2a110 | 50 | bt.baud(9600); |
justinkim | 0:7441087c2a16 | 51 | pc.printf("Hello World!\n\r"); |
justinkim | 0:7441087c2a16 | 52 | bt.printf("Hello World!\r\n"); |
justinkim | 0:7441087c2a16 | 53 | |
justinkim | 0:7441087c2a16 | 54 | direction.write(1); |
justinkim | 0:7441087c2a16 | 55 | Motor.period_ms(1); |
justinkim | 0:7441087c2a16 | 56 | |
justinkim | 0:7441087c2a16 | 57 | while(1) |
justinkim | 0:7441087c2a16 | 58 | { |
justinkim | 0:7441087c2a16 | 59 | if(bt.readable()) |
justinkim | 0:7441087c2a16 | 60 | { |
justinkim | 0:7441087c2a16 | 61 | ch=bt.getc(); |
justinkim | 0:7441087c2a16 | 62 | pc.printf("%c",ch); |
justinkim | 0:7441087c2a16 | 63 | bt.printf("%c",ch); |
justinkim | 0:7441087c2a16 | 64 | |
justinkim | 0:7441087c2a16 | 65 | if(ch == '*') |
justinkim | 0:7441087c2a16 | 66 | { |
justinkim | 0:7441087c2a16 | 67 | myservo = 0.5; |
justinkim | 0:7441087c2a16 | 68 | } |
justinkim | 0:7441087c2a16 | 69 | else if(ch == '+') |
justinkim | 0:7441087c2a16 | 70 | { |
justinkim | 0:7441087c2a16 | 71 | myservo = myservo + 0.1; |
justinkim | 0:7441087c2a16 | 72 | } |
justinkim | 0:7441087c2a16 | 73 | else if(ch == '-') |
justinkim | 0:7441087c2a16 | 74 | { |
justinkim | 0:7441087c2a16 | 75 | myservo = myservo - 0.1; |
justinkim | 0:7441087c2a16 | 76 | } |
justinkim | 0:7441087c2a16 | 77 | else if(ch == '@') |
justinkim | 0:7441087c2a16 | 78 | { |
justinkim | 0:7441087c2a16 | 79 | Motor.write(0.8); |
justinkim | 0:7441087c2a16 | 80 | } |
justinkim | 0:7441087c2a16 | 81 | else if(ch == '!') |
justinkim | 0:7441087c2a16 | 82 | { |
justinkim | 0:7441087c2a16 | 83 | Motor.write(0); |
justinkim | 0:7441087c2a16 | 84 | } |
justinkim | 0:7441087c2a16 | 85 | } |
justinkim | 0:7441087c2a16 | 86 | |
justinkim | 0:7441087c2a16 | 87 | else if(pc.readable()) |
justinkim | 0:7441087c2a16 | 88 | { |
justinkim | 0:7441087c2a16 | 89 | ch=pc.getc(); |
justinkim | 0:7441087c2a16 | 90 | bt.printf("%c",ch); |
justinkim | 0:7441087c2a16 | 91 | pc.printf("%c",ch); |
justinkim | 0:7441087c2a16 | 92 | |
justinkim | 0:7441087c2a16 | 93 | if(ch == '*') |
justinkim | 0:7441087c2a16 | 94 | { |
justinkim | 0:7441087c2a16 | 95 | myservo = 0.5; |
justinkim | 0:7441087c2a16 | 96 | } |
justinkim | 0:7441087c2a16 | 97 | else if(ch == '+') |
justinkim | 0:7441087c2a16 | 98 | { |
justinkim | 0:7441087c2a16 | 99 | myservo = myservo + 0.1; |
justinkim | 0:7441087c2a16 | 100 | } |
justinkim | 0:7441087c2a16 | 101 | else if(ch == '-') |
justinkim | 0:7441087c2a16 | 102 | { |
justinkim | 0:7441087c2a16 | 103 | myservo = myservo - 0.1; |
justinkim | 0:7441087c2a16 | 104 | } |
justinkim | 0:7441087c2a16 | 105 | else if(ch == '@') |
justinkim | 0:7441087c2a16 | 106 | { |
justinkim | 0:7441087c2a16 | 107 | Motor.write(0.8); |
justinkim | 0:7441087c2a16 | 108 | } |
justinkim | 0:7441087c2a16 | 109 | else if(ch == '!') |
justinkim | 0:7441087c2a16 | 110 | { |
justinkim | 0:7441087c2a16 | 111 | Motor.write(0); |
justinkim | 0:7441087c2a16 | 112 | } |
justinkim | 0:7441087c2a16 | 113 | } |
justinkim | 0:7441087c2a16 | 114 | } |
justinkim | 0:7441087c2a16 | 115 | } |