IoT: In the Cloud

Enter Your Project for a chance to win an Arduino MKR WAN 1300 Kit with a Compatable Lora Gateway or an MKR 1400 GSM with a Shield Combo + a $100 shopping cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll


This is the story of the transformation of the micro:cycloid in a cloud-controlled IoT thing.

The Project: Evolution of an Idea

Designing automatic drawings based on some math is a fascinating topic, especially if together with the mechanics we include a microcontroller to make the things more interesting and –hopefully– creative.


The Drawing Machine Part 1. The micro:cycloid can be classified as a STEAM project, I think; easy to replicate and to manage with educational purposes, and worth to be part of The month of robots, honoring the memory of Gordon McComb.

Indeed the design of the mechanics is an easy-to-assemble and hackable open-source kit; the best way to prove that this general-purpose machine can be adapted to almost any microcontroller is just hacking it. Why not using the base components to make an IoT thing? Sounds a good project for this month Project14 IoT in the Cloud.



A gallery of some light-painted images created with the machine

{gallery} Light-paint Drawings


Figuring Out the Design

The project aims to continue experimenting with the drawing machine in a wider environment creating an IoT Experimenting Kit accordingly to a number of essential requisites:


  • Controlling the machine from the Web
  • Make the thing Arduino compatible
  • Easy to customize
  • Enabling sensors or other components to change the drawing behavior
  • Finding some original application (appreciated)


Based on these assumptions I figured the design concept like the draft below

Wiring the Hardware

The drawing machine uses a couple of metal geared micro motors, small devices to be powered with 5 V. The main power line comes from a DC wall mount power supply set to 9V (max 2,25 A)  To power properly the two motors controlled by an L298 controller board I have used a cheap DC-DC regulator (I buy them in pack by 10 on Amazon) while the Arduino MKR 1000Arduino MKR 1000 is powered by the power-supply plug; in fact, I have used an MKR-Uno board adapter to make easier setting the PIN in the sketch keeping the compatibility with the popular Arduino UNO pinout.


Controlling the Motors With Only Two PWM Signals

The Arduino MKR1000Arduino MKR1000 has six PWM pins on board, but to control the motors two of them are sufficient; to send the High/Low signal to every motor (to set the rotation direction) I have used four non-PWM pins while the PWM outputs are connected to the Enable signal of every motor. This allows controlling both the speed and direction without consuming too many PWM output. I take into account that any update-upgrade of the base design may need some analog and digital GPIO so I tried to optimize as much as possible the signals used by default.

Above: the L298N motor controller board (left) with the power line wired to the DC-DC Voltage Adapter (right)


Before connecting the MKR1000 software to the Arduino IoT Cloud I have tested the system locally, to be sure that everything was working as expected.


Connecting the Drawing Machine to the Cloud

As the MKR1000 is part of the Arduino family and has been recently launched a stable beta of the Arduino IoT cloud I decided to experiment using it.


Registering and Setting Up the Cloud

I have appreciated the documentation and examples accessible from the main page: clear and exhaustive. It is not so usual that a beta version of a web platform includes complete and comprehensive documentation.

Registering to the cloud, creating the first Thing, adding properties and setting the controls are very easy procedures. A good option for the newbies is to follow the tutorial (strange, it blinks a LED !)

Above: the first step of the registration procedure, configuring the hardware

Below: after all the preliminary operations are done the cloud can connect to your board through the plugin installed on the computer and the USB connection to the Arduino


Also, the step-by-step guide to set up the secrets keys and secure access authorization certificates have been simplified as much as possible.

During the creation of the project, the MKR should be connected to the USB of the computer accessing the web platform; when the user reaches the session I am used to be the most complex, the definition of authorization access keys instead is definitely simplified: the remote procedure do all these tasks automatically programming the encryption chip onboard of the MKR device.

The below image shows the Drawing controls defined in the cloud interface. It is redundant to show the steps to define the controls as the self-explaining process is extremely intuitive.

When the remote system tries to program the Arduino for the first time (including the encryption chip settings), the board should be disconnected by any peripheral, sensor or external component.

Writing the Software

After the experience of writing the sketch online as the only possible choice to manage the MKR1000 programming, I strongly suggest writing and testing locally the sketch and save if on your PC before proceeding to the next step.

Above: the online code editor of the Arduino IoT Cloud, replicating the features of the popular stand-alone Arduino IDE


With the source functions dedicated to the drawing features optimized and running stand-alone is easy copy-and-paste the sources to complete the online self-generated file provided by the online code editor. The features of the online version of the Arduino editor are very similar to the stand-alone Arduino IDE. Using the Arduino IoT Cloud online editor – at least for this Beta version of the platform – any extra file added to the project (for example a header file defining some constants of the program) is lost after the fins saving operation.


 * Headers definitions of the program

// ======================== RGB LED =====================
// RGB LED control pins. Accordingly with the MKR 1000 pinout the
// contorl pins should be PWM output to create a single-led 
// NeoPixel-like colour shading
#define REDPIN A3
#define GREENPIN 4
#define BLUEPIN 5
#define RGBLED_OFF 0    // PWM value to set the LED off
#define RGB_MIN 1       // Absolute min PWM value for LED glowing
#define RGB_MAX 64     // Absolute max PWM value for LED glowing
#define RGB_MID 32     // Mid PWMlight value
#define RGB_UP 1
#define RGB_DOWN -1

// ======================== MOTORS DRIVER ===============
// The motors driver is an L298N board controller. As I am using
// two DC motors, a single bridge board is sufficient to manage
// both independently. The four motors power signals should be
// just a digital ouput while every motor speed is controlled by
// the corresponding Enable pin connected to a PWM digital output
#define ENABLE_MOTOR_A 2  // Enable signal (PWM)
#define ENABLE_MOTOR_B 3  // Enable signal (PWM)
#define MOTOR_A1 6        // Motor control line
#define MOTOR_A2 7        // Motor control line
#define MOTOR_B1 8        // Motor control line
#define MOTOR_B2 9        // Motor control line

// Motor direcitons. A tri=-state flag controlled by the cloud

#define MOTOR_STOPPED 0     /// PWM value to stop a motor


The current beta version of the Arduino IoT Cloud online editor (that must be used to create the code for the platform) does not support extra-files, lost after the sources are saved.

As a best practice, I suggest to include everything in the main sketch (the .ino file).


 * Motor control parameters.
 * This structure is constantly updated wile the design is running
 * and by the IoT cloud callback used to interact with the machine
 struct MotorControl {
  int directionA = MOTOR_CLOCKWISE;
  int directionB = MOTOR_CLOCKWISE;
  int speedA = MOTOR_STOPPED;
  int speedB = MOTOR_STOPPED;

 * Light drawing parmeters. Depending on the state of the program, the
 * lights are glowing with the RGB range
struct LightControl {
  int valGlow = 0;
  int directionGlow = RGB_UP;


The drawing machine behavior is controlled by two structures: MotorControl and LightControl. The remote control changes update the parameters of these two structures wile the loop only launch the two functions to set the motors and controlling the light. The light control gives the light-painting feature to the drawing machine.


void loop() {

  // Check if should glow the LED
  if(LightDrawing == true) {
      // lightGlow();


The structures control approach makes possible a very short loop() function. It is important to design the sketch with high structured functions avoiding delays and long pauses. If needed, it is the case to use a timer interrupt instead to refresh frequently the loop() cycle. As you can see in the code above, the first call of the loop() is ArduinoCloud.update() This method makes possible to exchange data between the board and the cloud. As much frequently the update is called, as more responsive the program will be.


An Add-on to the Drawing Machine

One of the components included in the Elegoo sensor kit is a small PCB with an SMD RGB LED, ready to use; I decided to create a first tool for the Drawing IoT Experimenting Platform: a light-painting device. To fit the LED PCB inside the pen holder I have 3D printed small support (printed in six minutes)  to fix it in place.

With a recyclable cardboard box, I have assembled a small dark room with a hole capable to host both the smartphone (mine has a light paint mode in the camera pp) and my Canon DSLR.

After some experiments, I found the right lighting values with very satisfying results. I should admit that controlling the behavior of the drawing machine from a browser is better and faster than design a hardware interface with buttons, potentiometer sliders, etc.



The full documented sources are available as Open Source under LGPL 3.0 license on GitHub repository arducycloid