Components and supplies
Arduino Nano R3
Motor Control driver chip L9110
HC-06 Bluetooth Module
Simple motor
Servos (Tower Pro MG996R)
Project description
Code
finish.ino
arduino
1#include <SoftwareSerial.h> 2#include <Wire.h> //SoftwareSerialWire SoftwareSerial 3#include <Servo.h> 4SoftwareSerial I2CBT(A0,A1); //PIN10PIN11RXTX 5Servo myservo; // create servo object to control a servo 6 7 8int pos = 0; // variable to store the servo position 9int INA = 9; 10int INB = 10; 11//int LED = 13; 12 13void setup() { 14 Serial.begin(9600); //Arduino9600 15 I2CBT.begin(9600); //57600 16 myservo.attach(3); // attaches the servo on pin 3 to the servo object 17 pinMode(INA,OUTPUT); 18 pinMode(INB,OUTPUT); 19} 20 21void loop() { 22 byte cmmd[20]; 23 int insize; 24 servo(90); 25 while(1){ 26 if ((insize=(I2CBT.available()))>0){ 27 Serial.print("input size = "); 28 Serial.println(insize); // 29 for (int i=0; i<insize; i++) { 30 Serial.print(cmmd[i]=char(I2CBT.read()));// 31 //Serial.print("\ 32"); 33 } //for 34 switch (cmmd[0]) { 35 case 97: //'a' 36 //digitalWrite(LED,HIGH); 37 motorforward(); 38 Serial.print(" go"); 39 break; 40 41 case 98: //'b' 42 //digitalWrite(LED,LOW); 43 motorstop(); 44 Serial.print(" stop"); 45 break; 46 47 case 102: //'f' 48 //digitalWrite(LED,LOW); 49 motorback(); 50 Serial.print(" back"); 51 break; 52 53 54 55 56 57 58 case 99: //'c' 59 servo(150); 60 Serial.print(" Left"); 61 break; 62 63 case 100: //'d' 64 servo(90); 65 Serial.print(" Ctr"); 66 break; 67 68 case 101: //'e' 69 servo(30); 70 Serial.print(" Right"); 71 break; 72 73 } //Switch 74 Serial.print("\ 75"); 76 77 78 } //if 79 80 81 82 83 } //while 84} 85 86 87 88 89//************************** 90void servo(int servopos) { 91 myservo.write(servopos); // tell servo to go to position in variable 'pos' 92 delay(15); // waits 15ms for the servo to reach the position 93} 94 95void motorforward() { 96 digitalWrite(INA,LOW); 97 digitalWrite(INB,HIGH); 98 //delay(1000); 99} 100 101void motorstop() { 102 digitalWrite(INA,LOW); 103 digitalWrite(INB,LOW); 104 //delay(1000); 105} 106 107void motorback() { 108 digitalWrite(INA,HIGH); 109 digitalWrite(INB,LOW); 110 //delay(1000); 111} 112
finish.ino
arduino
1#include <SoftwareSerial.h> 2#include <Wire.h> //SoftwareSerialWire 3 SoftwareSerial 4#include <Servo.h> 5SoftwareSerial I2CBT(A0,A1); //PIN10PIN11RXTX 6 7Servo myservo; // create servo object to control a servo 8 9 10int pos 11 = 0; // variable to store the servo position 12int INA = 9; 13int INB = 10; 14//int 15 LED = 13; 16 17void setup() { 18 Serial.begin(9600); //Arduino9600 19 I2CBT.begin(9600); 20 //57600 21 myservo.attach(3); // attaches the servo on pin 3 to the servo object 22 23 pinMode(INA,OUTPUT); 24 pinMode(INB,OUTPUT); 25} 26 27void loop() { 28 29 byte cmmd[20]; 30 int insize; 31 servo(90); 32 while(1){ 33 if ((insize=(I2CBT.available()))>0){ 34 35 Serial.print("input size = "); 36 Serial.println(insize); // 37 38 for (int i=0; i<insize; i++) { 39 Serial.print(cmmd[i]=char(I2CBT.read()));// 40 41 //Serial.print("\ 42"); 43 } //for 44 switch (cmmd[0]) 45 { 46 case 97: //'a' 47 //digitalWrite(LED,HIGH); 48 motorforward(); 49 50 Serial.print(" go"); 51 break; 52 53 case 98: //'b' 54 55 //digitalWrite(LED,LOW); 56 motorstop(); 57 Serial.print(" 58 stop"); 59 break; 60 61 case 102: //'f' 62 //digitalWrite(LED,LOW); 63 64 motorback(); 65 Serial.print(" back"); 66 break; 67 68 69 70 71 72 73 74 case 99: //'c' 75 servo(150); 76 Serial.print(" Left"); 77 78 break; 79 80 case 100: //'d' 81 servo(90); 82 Serial.print(" 83 Ctr"); 84 break; 85 86 case 101: //'e' 87 servo(30); 88 89 Serial.print(" Right"); 90 break; 91 92 } 93 //Switch 94 Serial.print("\ 95"); 96 97 98 } //if 99 100 101 102 103 104 } //while 105} 106 107 108 109 110//************************** 111void 112 servo(int servopos) { 113 myservo.write(servopos); // tell servo to 114 go to position in variable 'pos' 115 delay(15); // waits 116 15ms for the servo to reach the position 117} 118 119void motorforward() { 120 121 digitalWrite(INA,LOW); 122 digitalWrite(INB,HIGH); 123 //delay(1000); 124} 125 126void 127 motorstop() { 128 digitalWrite(INA,LOW); 129 digitalWrite(INB,LOW); 130 //delay(1000); 131 132} 133 134void motorback() { 135 digitalWrite(INA,HIGH); 136 digitalWrite(INB,LOW); 137 138 //delay(1000); 139} 140
Downloadable files
circuit_RkmZDUJZHn.jpeg
circuit_RkmZDUJZHn.jpeg
circuit_RkmZDUJZHn.jpeg
circuit_RkmZDUJZHn.jpeg
Schematic design
by Designspark
Schematic design
Comments
Only logged in users can leave comments