For a few lines of code,
Just copy-paste the code blow into an new Arduino sketch.
// ____ _ _ ______ // / __ ) (_)____ ____ (_)_____ / ____/__ __ ___ // / __ |/ // __ \ / __ \ / // ___// __/ / / / // _ \ // / /_/ // // /_/ // / / // // /__ / /___ / /_/ // __/ // /_____//_/ \____//_/ /_//_/ \___//_____/ \__, / \___/ // /____/ // // Created by Yair Kapach 2015 // For build details and more, please visit: // http://www.youtube.com/user/microstrat // http://makestuffordie.blogspot.com/ // // you're welcome to hack it, break it and have fun ! #include <Servo.h> #include <SoftwareSerial.h> #define SERVO_PIN 9 #define BT_RX_PIN 10 #define BT_TX_PIN 11 Servo eye; SoftwareSerial bluetooth(BT_RX_PIN, BT_TX_PIN); int pos = 60; int lastPos = pos; void setup() { bluetooth.begin(9600); // initialize communication eye.attach(SERVO_PIN); // initialize servo eye.write(pos); // look ahead :) } void loop() { if (bluetooth.available()) { // try and read if available int data = bluetooth.read(); // read a single character pos = map(data, '0', '9', 10, 110); // convert digit to degrees } if (lastPos != pos) { // don't resend the same values lastPos = pos; eye.write(pos); } }
Download any Bluetooth terminal app, I preferred one with custom hotkeys, you can set buttons 0-9 to send any data once clicked.
Since our protocol is quite dumb, button 0 sends '0', 1 sends '1' and so on...
Happy Halloween.