Skip to content

Instantly share code, notes, and snippets.

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');

This comment has been minimized.

Copy link
Owner Author

@ThaWeatherman ThaWeatherman commented Sep 7, 2015

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


This comment has been minimized.

Copy link

@bendespain bendespain commented Feb 27, 2016

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


This comment has been minimized.

Copy link

@dreamtwerks dreamtwerks commented May 20, 2016

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