Devices & Components
Arduino Uno Rev3
SparkFun XBee Explorer USB
FLOUREON® 11.1V 2200mAh 3S 25C Lipo RC Battery Rechargeable RC Battery with XT60 Plug
UNIKEL A2212 1000KV Brushless Outrunner Motor+30A Brushless ESC for DJI F450 550
Selfie Stick with Bluetooth Remote
5040 Drone Prop
Rotary potentiometer (generic)
Needle Roller Pin Bearing
XBee Series 2 Wireless Chip
Jumper wires (generic)
Hardware & Tools
Metal Lathe
Pillar Drill
Cordless Drill
Tig Welder
Waterjet Cutter
Metal Mitre Saw
Software & Tools
Arduino IDE
XCTU
Project description
Code
Transmitter Code
arduino
Code for the Arduino on the remote transmitting the change in position of the potentiometer.
1/* ~ Simple Arduino - xBee Transmitter sketch ~ 2 3 Read an analog value from potentiometer, then convert it to PWM and finally send it through serial port to xBee. 4 The xBee serial module will send it to another xBee (resiver) and an Arduino will turn on (fade) an LED. 5 The sending message starts with '<' and closes with '>' symbol. 6 7 Dev: Michalis Vasilakis // Date:2/3/2016 // Info: www.ardumotive.com // Licence: CC BY-NC-SA */ 8 9//Constants: 10const int potPin = A0; //Pot at Arduino A0 pin 11//Variables: 12int value ; //Value from pot 13 14void setup() { 15 //Start the serial communication 16 Serial.begin(9600); //Baud rate must be the same as is on xBee module 17} 18 19void loop() { 20 //Read the analog value from pot and store it to "value" variable 21 value = analogRead(A0); 22 //Map the analog value to pwm value 23 value = map (value, 0, 1023, 0, 255); 24 //Send the message: 25 Serial.print('<'); //Starting symbol 26 Serial.print(value);//Value from 0 to 255 27 Serial.println('>');//Ending symbol 28}
Transmitter Code
arduino
Code for the Arduino on the remote transmitting the change in position of the potentiometer.
1/* ~ Simple Arduino - xBee Transmitter sketch ~ 2 3 Read an analog 4 value from potentiometer, then convert it to PWM and finally send it through serial 5 port to xBee. 6 The xBee serial module will send it to another xBee (resiver) 7 and an Arduino will turn on (fade) an LED. 8 The sending message starts with 9 '<' and closes with '>' symbol. 10 11 Dev: Michalis Vasilakis // Date:2/3/2016 12 // Info: www.ardumotive.com // Licence: CC BY-NC-SA */ 13 14//Constants: 15 16const int potPin = A0; //Pot at Arduino A0 pin 17//Variables: 18int value 19 ; //Value from pot 20 21void setup() { 22 //Start the serial communication 23 24 Serial.begin(9600); //Baud rate must be the same as is on xBee module 25} 26 27void 28 loop() { 29 //Read the analog value from pot and store it to "value" variable 30 31 value = analogRead(A0); 32 //Map the analog value to pwm value 33 value = 34 map (value, 0, 1023, 0, 255); 35 //Send the message: 36 Serial.print('<'); //Starting 37 symbol 38 Serial.print(value);//Value from 0 to 255 39 Serial.println('>');//Ending 40 symbol 41}
Receiver Code
arduino
Code from the Arduino Uno attached to the receiver chip which is on the Camera rig arm. I did not write this code.
1/* ~ Simple Arduino - xBee Receiver sketch ~ 2 3 Read an PWM value from Arduino Transmitter to fade an LED 4 The receiving message starts with '<' and closes with '>' symbol. 5 6 Dev: Michalis Vasilakis // Date:2/3/2016 // Info: www.ardumotive.com // Licence: CC BY-NC-SA */ 7 8//Constants 9const int ledPin = 3; //Led to Arduino pin 3 (PWM) 10 11//Variables 12bool started= false;//True: Message is strated 13bool ended = false;//True: Message is finished 14char incomingByte ; //Variable to store the incoming byte 15char msg[3]; //Message - array from 0 to 2 (3 values - PWM - e.g. 240) 16byte index; //Index of array 17 18void setup() { 19 //Start the serial communication 20 Serial.begin(9600); //Baud rate must be the same as is on xBee module 21 pinMode(ledPin, OUTPUT); 22} 23 24void loop() { 25 26 while (Serial.available()>0){ 27 //Read the incoming byte 28 incomingByte = Serial.read(); 29 //Start the message when the '<' symbol is received 30 if(incomingByte == '<') 31 { 32 started = true; 33 Serial.print("true"); 34 index = 0; 35 msg[index] = '\\0'; // Throw away any incomplete packet 36 } 37 //End the message when the '>' symbol is received 38 else if(incomingByte == '>') 39 { 40 ended = true; 41 break; // Done reading - exit from while loop! 42 } 43 //Read the message! 44 else 45 { 46 if(index < 4) // Make sure there is room 47 { 48 msg[index] = incomingByte; // Add char to array 49 index++; 50 msg[index] = '\\0'; // Add NULL to end 51 } 52 } 53 } 54 55 if(started && ended) 56 { 57 int value = atoi(msg); 58 59 60 analogWrite(ledPin, value); 61 Serial.println(value); //Only for debugging 62 index = 0; 63 msg[index] = '\\0'; 64 started = false; 65 ended = false; 66 } 67}
Downloadable files
Receiver Setup
Receiver Setup

Transmitter Setup
Transmitter Setup

Transmitter Setup
Transmitter Setup

Receiver Setup
Receiver Setup

Comments
Only logged in users can leave comments