For installations involving multiple sensors and/or outputs connected to Arduino-like development boards, you’ll often find the need to connect them into a network. This page contains basic guidelines that I’ve found useful for this kind of project.
Grigore Burloiu, November 2023
Quick answer:
A) if you’re using WiFi/wireless enabled boards (such as the NodeMCU or Feather) you need a router.
B) if you have Ethernet/wired boards (such as an Arduino UNO with an Ethernet Shield), go for a switch.
Of course, you could combine the two: if you’ve got a larger wired network that also needs wireless connectivity (e.g. to the Internet) you need to plug the switch into the router.
Ethernet Cables Explained | Eaton
What is the User Datagram Protocol (UDP)? | Cloudflare
To make a wired network, simply connect everything to the switch via Ethernet (UTP) cables. Then, in a terminal, run this command: arp -a
and you should see a list of all connected devices.
For wireless, generally your router will by default create a WiFi network for you to connect to. Once connected (over WiFi or cable) to the router, point your PC’s browser to the router’s admin panel and customize the network as needed.
For example, an ASUS router’s admin site allows us to configure the network and see a list of connected devices:
Every device (PCs, SBCs, dev boards) in your network has an IP address. By default these are allocated dynamically, but you should probably make them static. You don’t want IPs changing on you when restarting/reconnecting your devices!
You can find out your IP address with the ipconfig
terminal command on Windows, or ip
/ ifconfig
on Linux and OSX. If you’re connected to several networks (e.g. a wired and a wireless one) you’ll have separate IP addresses for each one.
Note your IPv4 address. It might be something like 192.168.1.x
or 10.0.0.x
and so on.
Let’s standardize this as A.B.C.x
: a safe move is to leave A.B.C
(the subnet) as-is and set different x
values for each device. Normally x=1
should be reserved for the router, if you’re using one.
Windows PC connected via cable to the router that manages the wireless network. All devices can see each other since they are in the same A.B.C
subnet: all their IP addresses start with 192.168.50
To set a static IP in Windows 10:
under IP settings, click "Edit" and choose "Manual" instead of Automatic (DHCP)
turn on IPv4 and set:
A.B.C.x
24
A.B.C.1
(or any unique x
)click "Save"
Setting static IP in Arduino IDE is normally done in the setup()
function of your sketch. Depending on what library you’re using, the code will look slightly different. Check the File > Examples for your specific library.
IPAddress local_IP(192, 168, 50, 40);
IPAddress gateway(192, 168, 50, 155);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(local_IP,gateway,subnet);
// …
WiFi.begin(SSID_name, passw);
See examples of wired and wireless code in my past projects.
Now that your dev boards are networked to your computers, you no longer use serial USB to send and receive data. My go-to solution is OpenSoundControl via UDP.
As with the basic network setup, UDP code can vary slightly. Again, see the included Examples and my code links above.
Note: as of this writing, the official OSC Arduino library doesn’t support v2 of the Arduino IDE, so you should stick with the legacy 1.8.x version.