![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluetooth
IoT Bluetooth Fan Control
Description
This project uses Bluetooth on the smartphone to control a Smart IoT Fan that comes with an thermal sensor and a bluetooth module. The phone can access the temperature read by the thermal sensor, and send send the command to the phone and adjust the speed of the Fan accordingly.
Components
mBed | LM19 |
Vout | Vs |
GND | GND |
P15 | Vout |
mBed | md80a |
GND | GND |
P5 | Ain2 |
P6 | Ain1 |
Vout | STBY |
Project Picture
Demo Video
Code
#include "mbed.h" #include "Motor.h" RawSerial dev(p13, p14); AnalogIn temp(p15); Motor m(p23, p6, p5); float _temp; float _speed = 0; void dev_recv() { while(dev.readable()) { char mode = dev.getc(); if (mode == 'T') { _temp = temp; _temp = 38.0-27.5*_temp; dev.printf("%f\n",_temp); } if (mode=='V') { char type = dev.getc(); if(type=='?') { dev.printf("%f\n",_speed); } if(type=='+') { if (_speed < 1.0) { _speed= _speed + 0.1; } m.speed(_speed); dev.printf("New Speed %f\n",_speed); } if(type=='-') { if (_speed >= 0.1) _speed-= 0.1; m.speed(_speed); dev.printf("New Speed %f\n",_speed); } } } } int main() { dev.baud(9600); dev.attach(&dev_recv, Serial::RxIrq); while(1) { sleep(); } }
Diff: mbed.bld
- Revision:
- 0:84c73f8a4a96
diff -r 000000000000 -r 84c73f8a4a96 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 13 23:43:10 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90 \ No newline at end of file