Stap 2:3. Servo Motor controle met behulp van de Arduino en Android
In deze tutorial zal u het creëren van een app voor het beheersen van een servomotor, zal u schuifregelaar in uw app uw servo overstappen 0-180, moet u een servomotor te worden aangesloten op de arduino-kant, zorg ervoor dat u ook het aansluiten van externe voeding zodat je Arduino niet opnieuw tijdens dit proces opgestart wordt,
#include // TX RX software library for bluetooth #include // servo library Servo myservo; // servo name int bluetoothTx = 10; // bluetooth tx to 10 pin int bluetoothRx = 11; // bluetooth rx to 11 pin SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); void setup() { myservo.attach(9); // attach servo signal wire to pin 9 //Setup usb serial connection to computer Serial.begin(9600); //Setup Bluetooth serial connection to android bluetooth.begin(9600); } void loop() { //Read from bluetooth and write to usb serial if(bluetooth.available()> 0 ) // receive number from bluetooth { int servopos = bluetooth.read(); // save the received number to servopos Serial.println(servopos); // serial print servopos current number received from bluetooth myservo.write(servopos); // roate the servo the angle received from the android app } }