Arduino Local Ethernet Connections via Shared WiFi

There are a ton of great ideas out there for intertube-connected Arduino projects, but you may find yourself in this situation:

  • Router has no more unused ports
  • You prefer not to be chained to your router, which may be inconveniently located
  • Your Arduino network shield is not WiFi enabled

I prefer to work on a Mac laptop with a WiFi connection, but wanted to do network experiments with an ethernet Arduino shield. Here’s the solution:

  1. Go to System Preferences | Sharing
  2. Enable Internet Sharing
  3. Share the connection from WiFi to Ethernet

Now you can connect an Ethernet cable from your Mac to your Ethernet shield. Because the Mac takes care of crossovers automatically, this will “just work.”

Next you need to find out what IP address to use in your Arduino sketches. Open  a Terminal and type:

ifconfig en0

A few lines down, you’ll see something like:

inet 192.168.2.1

Change that “.1” at the end to any number under 255 and you should have an address that’s shared through your WiFi network, through your Mac, and usable in any Arduino ethernet sketches (I’m using 192.168.2.10).  Now you can work without worrying about being tethered to a physical router, or being out of free ports.

 

 

7 Replies to “Arduino Local Ethernet Connections via Shared WiFi”

  1. kobe, there is no code related to this blog post. If you are having trouble connecting, you should post your question in an arduino forum.

  2. Thanks it works but only local.
    So I have an other question, do you know if its possible to speak to an arduino(with ethernet shield) if you are outside his local network ?

  3. You need to configure your modem for port forwarding.
    Say your Arduino Ethernet Shield uses 192.168.2.67 and port will be 8081

    Then use a Dynamic DNS service like this one http://freedns.afraid.org/ to reach your Arduino over ethernet.

    You can find other explanations with keywords above.

  4. thanks!

    after following the steps above for setting up connection sharing you can see what your arduino is configured with using some other function in the Ethernet library. Print those to the serial monitor then setup the server using the settings you see printed to the serial monitor…..see code below.


    // MAC address from Ethernet shield sticker under board
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    //IPAddress ip(192, 168, 2, 2); // IP address printed out to the serial monitor in the code below
    //IPAddress subnet(255, 255, 255, 0); same here
    //EthernetServer server(80); // create a server at port 8080

    void setup()
    {
    Serial.begin(9600);
    while(!Serial);
    Serial.print("Establishing Network Connection...");

    if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed!");
    }
    else {
    Serial.println("OK!");
    Serial.println("IP: ");
    Serial.println(Ethernet.localIP());
    Serial.println("Gateway: ");
    Serial.println(Ethernet.gatewayIP());
    Serial.println("Subnet Mask: ");
    Serial.println(Ethernet.subnetMask());
    Serial.println("DNS Server: ");
    Serial.println(Ethernet.dnsServerIP());
    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *