Skip to content

Instantly share code, notes, and snippets.

Last active June 7, 2018 07:45
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Remote control servo with Particle Photon. Apache License, copyright 2015 Sean Beck
Servo serv;
int pos = 0;
void setup() {
Spark.function("setpos", setPos);
Spark.variable("getpos", &pos, INT);
void loop() {
int setPos(String pstn) {
pos = pstn.toInt();
return pos;
body {
margin: 1em auto;
max-width: 45em;
padding: 0.8em;
background: white;
<h1>Photon servo control</h1>
<input type="range" min="0" max="180" value="0" onchange="showValue(this.value)"/>
<span id="range">0</span>
<script type="text/javascript">
function showValue(newValue) {
var request = new XMLHttpRequest();
var dev_id = '<your device id here>';
var access = '<your access token here>';
var data = 'params='+newValue+'&access_token='+access;
var url = ''+dev_id+'/setpos/';'POST', url, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
Copy link

See it in action here. Hook up 4 AA battery to servo. Connect servo to pin D0 on the Photon.

Copy link

Hey, I can't seem to get this to work, is serv a missing library?

Copy link

Hi i have edited your html to use 3 servos at same time and i gived the credits to you, can see it here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment