/* motor draait continu- via bluetooth dmv app op mobiele telefoon. - Via Arduino-GG in Bieb Drachten.
gebruik Bluetooth-4.0 adapter voor Apple mobiele telefoon of
gebruik HC-05 adapter voor Android mobiele telefoon.
Motortje is Servo 9G, aangesloten op pin D9
De bluetooth adapter aangesloten op D10 voor TXD en op D11 voor RXD
als app gebruik ik BLEserial Tiny op de Apple mobiele telefoon.
Vul daar in: van 1 = snel naar 70 is langzaam, draait met de klok mee
of 100 = langzaam naar 180 = snel, draait tegen de klok in
zichtbaar in de Seriele Monitor in Arduino IDE.
*/
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myServo; // Create servo object
SoftwareSerial bluetooth(10, 11); // RX, TX pins for Bluetooth
void setup() {
myServo.attach(9); // Attach servo to pin 9
myServo.write(0); // Set initial position to 0 degrees
Serial.begin(9600); // Start serial communication
bluetooth.begin(9600); // Start Bluetooth communication
}
void loop() {
if (bluetooth.available()) {
int angle = bluetooth.parseInt(); // Read angle from Bluetooth
if (angle >= 0 && angle <= 180) {
myServo.write(angle); // Rotate servo to specified angle
Serial.print("Servo moved to: ");
Serial.println(angle);
} else {
Serial.println("Invalid angle received");
}
}
}