Sending complex Serial data

Planning
Step 1
In this lesson I will describe the process of sending complex serial data, and you will be parsing that data

Once completed you'll be able to send information about multiple servos and specify which servo the value is for

Step 2
The first step is to choose an encoding for servo commands

Change the output code in your HC-05 so that is sends strings in the form of:

"<servo number>:<servo value>'\n' "

So if you want the first servo to have a value of 1300, you would send:

"1:1300'\n' "

And you can build this string using .print() and .println():

//print 1
//print ":"
//println 1300

Remember, println appends a newline character \n to the end of the string.

Step 3
Now you HC-06 Arduino needs to parse this data

We are going to assume all data strings are of the form: <servo number>:<servo value>

Then you can use .readBytesUntil() to read the servoNumber and then again to read the servoValue.

The servo number will decide which digital pin to analogWrite() the servo position to. You can use if statements to make this decision

e.g.

if the servo number is 1
ananlogWrite to pin 9

if the servo number is 2
analogWrite to pin 10

Step 4
Lastly remember that each digital pin needs to go through it's own digital to analog converter (DAC)

So you'll need one capacitor+resistor pair for each digital pin

Challenge
Step 5
Use two potentiometers (or one dual axis joy stick) to control two servos
  • Each potentiometer has it's own analog pin on the HC-05 Arduino.
  • The HC-05 sends a string of the form <servo number>:<servo value> for each analogpin
  • The HC-06 Arduino parses the servoNumber and servoValue from each string it receives
  • The HC-06 Arduino then uses the servoNumber to analogWrite() the servoValue to the correct digital pin
  • The digital pin goes through it's own digital to analog converter which in turn supplies a value to an analog pin on the Servo Arduino
  • The Servo Arduino averages the analog input waves and uses the result to power the servos

If you got all of that congratulations you've mastered the basics of a remote control system!

Planning
Step 6
From here it's up to you

You can add more potentiometers or buttons/switches to your controller. Or maybe you want to try building/3D printing a case for your controller.

Sending complex Serial data Info

Account

MVCode Clubs

Created By

Newprofile jamie

Course:

Build your own remote controller (advanced)

Access Level

premium

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach