Remote Servo Control with Adafruit CC3000


#1

This post will cover how to control a servo remotely from the Internet. This is a very easy project that can be done with a few lines of codes. Will help to know how to define input parameters to the device, and how to define functions without parameters.

Hardware

In this case I will be using an Arduino Nano + Adafruit CC3000 for connecting the chip to the Internet. You can use any other MCU as the code for controlling the servo will be exactly the same. The servo is a small cheap one called Tower Pro Micro Servo 9g (SG90). You can find this one in eBay or AliExpress easily. The servo is attached to digital pin 9, while the Adafruit CC3000 is connected to the Arduino Nano using SPI (with the default configuration for the Adafruit Library).

Software

This how-to will use Arduino IDE with the thinger.io library installed. Click on this link if you do not have the library installed yet. We also need the Servo library that should be installed by default in the Arduino IDE.

Picture

Arduino Sketch

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <ccspi.h>
#include <ThingerCC3000.h>
#include <Servo.h> 

#define USERNAME "your_username"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"

#define SSID "your_ssid"
#define SSID_PASSWORD "your_ssid_password"

#define SERVO_PIN 9

ThingerCC3000 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
Servo servo;

void setup() {
    servo.attach(SERVO_PIN);
    
    // configure wifi network
    thing.add_wifi(SSID, SSID_PASSWORD);

    // controlling servo position
    thing["servo"]["pos"] << [](pson& in){
      servo.write((int)in);
    };

    // reseting servo position
    thing["servo"]["reset"] = [](){
      servo.write(0);
    };
}

void loop() {
  thing.handle();
}

Web Control

Once you enter in your device API you will see two different methods for controlling the servo. One is for setting an absolute position in degrees, and the second one is for resetting the servo position. You can try changing the servo position from 0 to 180 degrees. The servo should move as you click on the Run button.


#2

Very good tutorial!

Now I am trying to use this code within my automatic cat feeder project.
I have a LCD, Realtime clock and a servo. Shouldn’t be to difficult but I can’t put it in the main loop right?
Right now the LCD uses a delay to not constantly print but when migration I cant seem to figure out how to design the code segments. I want to also use the realtime clock for using the time to set the servo. (and not an online time) because the cat feeder should be connection failure save (When internet breaks down)

See my code here:

What is the best approach to integrate the LCD, Real time Clock and the servo within this code?


#3

I answered to your post. It should be easy to integrate all the features! We will go step by step…


#4

esto me vale para el control de la cerradura y le incluimos lo del gps pues ya lo dejamos de 10.