Devices & Components
Arduino Uno Rev3
HC-05 Bluetooth Module
SG90 Micro-servo motor
Hardware & Tools
Servo Motor, Premium Male/Male Jumper Wires
Breadboard, 270 Pin
Project description
Code
mechanicalArm
c_cpp
1#include <Servo.h> 2#define pinServ1 11 3#define pinServ2 10 4#define pinServ3 9 5#define pinServ4 8 6 7Servo serv1 , serv2 , serv3 , serv4; 8 9int motor1 = 90 ; 10int motor2 = 52 ; 11int motor3 = 67 ; 12int motor4 = 0 ; 13 14 15char buf; 16 17void setup() { 18 Serial.begin(9600); 19 Serial.println("The device started, now you can pair it with bluetooth!"); 20 21 serv1.attach(pinServ1); 22 serv2.attach(pinServ2); 23 serv3.attach(pinServ3); 24 serv4.attach(pinServ4); 25 26 27} 28 29void loop() { 30 while(Serial.available() > 0) 31 { 32 buf = Serial.read(); 33 34 Serial.println(Serial.read()); 35 36 if(buf == 'F'){ 37 serv1.write(motor1 += 4); 38 delay(5); 39 } 40 41 if(buf == 'B'){ 42 serv1.write(motor1 -= 4); 43 delay(5); 44 } 45 46 if(buf == 'L'){ 47 serv2.write(motor2 += 4); 48 delay(5); 49 } 50 51 if(buf == 'R'){ 52 serv2.write(motor2 -= 4); 53 delay(5); 54 } 55 56 if(buf == 'G'){ 57 serv3.write(motor3 += 4); 58 delay(15); 59 } 60 61 if(buf == 'I'){ 62 serv3.write(motor3 -= 4); 63 delay(15); 64 } 65 if(buf == 'H'){ 66 serv4.write(motor4 += 4); 67 delay(15); 68 } 69 70 if(buf == 'J'){ 71 serv4.write(motor4 -= 4); 72 delay(15); 73 } 74 75 76 delay(25); 77 } 78 79}
Comments
Only logged in users can leave comments