Devices & Components
Arduino Uno Rev3
Dual H-Bridge motor drivers L293D
HC-06 Bluetooth Module
DC Motor, 12 V
Software & Tools
Arduino IDE
Bluetooth Electronics
Project description
Code
Speed and direction control prgm
c_cpp
1#include<SoftwareSerial.h> 2SoftwareSerial bt_ser(4,5); //connected 3 to RX and TX pins for serial data communication 4char c[6]; 5int i=0,speed_value=0,send_value; 6 7#define 8 pwm1 9 //input 2 9#define pwm2 10 //input 1 10 11boolean motor_dir 12 = 0; 13 14void setup() 15{ 16 Serial.begin(9600); 17 bt_ser.begin(9600); 18 19 pinMode(pwm1, OUTPUT); 20 pinMode(pwm2, OUTPUT); 21} 22 23void loop() 24{ 25 26 27 while(bt_ser.available()) //when data is transmitted 28 { 29 if(bt_ser.available()>0) 30 31 { 32 c[i] = bt_ser.read(); //reading the string sent from master 33 device 34 Serial.print(c[i]); 35 i++; 36 } 37 if(c[i-1]=='N') 38 //if button is pressed 39 { 40 motor_dir = !motor_dir; //toggle 41 direction variable 42 if(motor_dir) //setting direction, 43 pwm1 and pwm2 are opposites 44 digitalWrite(pwm2, 0); 45 else 46 47 digitalWrite(pwm1, 0); 48 } 49 } 50 51 speed_value 52 = (c[1]-48)*100+(c[2]-48)*10+(c[3]-48)*1; //interpreting speed from string 53 54 if(motor_dir) //for a given direction 55 { 56 if(c[i-1]=='#'){ 57 //if data has been transmitted from slider 58 59 analogWrite(pwm1, 60 speed_value-100); //-100 so that when slider is on "0" speed is 0 61 i=0; 62 63 } 64 } 65 else{ //for opposite direction 66 67 if(c[i-1]=='#'){ 68 69 analogWrite(pwm2, speed_value-100); 70 71 i=0; 72 } 73 74 } 75 76 77} 78
Speed and direction control prgm
c_cpp
1#include<SoftwareSerial.h> 2SoftwareSerial bt_ser(4,5); //connected to RX and TX pins for serial data communication 3char c[6]; 4int i=0,speed_value=0,send_value; 5 6#define pwm1 9 //input 2 7#define pwm2 10 //input 1 8 9boolean motor_dir = 0; 10 11void setup() 12{ 13 Serial.begin(9600); 14 bt_ser.begin(9600); 15 pinMode(pwm1, OUTPUT); 16 pinMode(pwm2, OUTPUT); 17} 18 19void loop() 20{ 21 22 while(bt_ser.available()) //when data is transmitted 23 { 24 if(bt_ser.available()>0) 25 { 26 c[i] = bt_ser.read(); //reading the string sent from master device 27 Serial.print(c[i]); 28 i++; 29 } 30 if(c[i-1]=='N') //if button is pressed 31 { 32 motor_dir = !motor_dir; //toggle direction variable 33 if(motor_dir) //setting direction, pwm1 and pwm2 are opposites 34 digitalWrite(pwm2, 0); 35 else 36 digitalWrite(pwm1, 0); 37 } 38 } 39 40 speed_value = (c[1]-48)*100+(c[2]-48)*10+(c[3]-48)*1; //interpreting speed from string 41 if(motor_dir) //for a given direction 42 { 43 if(c[i-1]=='#'){ //if data has been transmitted from slider 44 45 analogWrite(pwm1, speed_value-100); //-100 so that when slider is on "0" speed is 0 46 i=0; 47 } 48 } 49 else{ //for opposite direction 50 if(c[i-1]=='#'){ 51 52 analogWrite(pwm2, speed_value-100); 53 i=0; 54 } 55 56 } 57 58 59}
Downloadable files
Electrical schematic
Electrical schematic
circuit diagram
circuit diagram
Electrical schematic
Electrical schematic
Comments
Only logged in users can leave comments