DEV Community

Iago
Iago

Posted on • Edited on

Arduino remotely controlled (part 2)

Introduction

In the previous post, we learned how to create an Arduino hub using the Simple Repository IO library.

Now it's time to make it talk with an server.

What are the problems I want to solve?

I want to create Arduino Hubs with actuators and sensors, but they must be controlled remotely.
This will (?) ease my mind that wants to create something.

What is the solution?

After creating an Arduino library, I must create a server to do the remote communication.

Weak points

  1. The server is intended to run on your LAN only
    1. You can do changes to make it work on the WEB
  2. I'll create an NPM library to make it easier to call the commands without duplicating code over your servers' code. Packages created.
  3. It relies on Multicast
    1. I don't know your LAN configuration, but if you're here I hope you know how to handle that
    2. Right?

Intended public

I expect you to have some knowledge regarding: TCP, UDP, IP ranges, and Typescript (not only C/C++)

Let's start

Library

In your Arduino IDE install the Simple Repository IO

Changing the wiring from previous post

What Amount
Arduino* 1
breadboard 1
220 ohm resistor 1
Led (built in) 1
Led 1
  • I hope you have a WeMos D1 R1 compatible Arduino board or an Wi-Fi module compatible with ESP8266WiFi and know how to wire it

Pin D10 to resistor
Resistor to LED
LED to GND

Wiring

Code

I created a tag so you can use the same version I used for this article.

  • Hub >> arduino code files
    1. It starts defining the components (see last article to better understanding)
    2. Then it MULTICASTS a message via UDP. Something like "I live, again"
    3. Wait for WiFi TCP messages with some command
  • Server >> typescript node server
    1. It starts two servers
    2. UDP server to add hubs to its list
    3. TCP server to act as an API
      • each endpoint calls the Arduino

Results

When calling http://localhost:3000/Hub_A/write/led/true

Led on

When calling http://localhost:3000/Hub_A/write/led/false

Led off

When the pwm_led is set to 0 (zero) and calling http://localhost:3000/write/Hub_A/pwm_led/100

Animated image of an led turning on

Previous step

  1. Create an Arduino library to remote communication

Next step

  1. Create a React Native app to handle the data

Top comments (0)