Cheapest Way to Connect Arduino to Internet

21,793

136

12

Introduction: Cheapest Way to Connect Arduino to Internet

Cheapest way to connect Arduino to internet

Shields here costly! and this bothers me a lot. It's impossible to build your own automation system without shields.
I found some articles on internet but for my bad luck non of them worked on my routers. All articles were talking about a specific router. I spent a year to figure it out and finally everything worked great. In this tutorial I will show you how to connect your Arduino to any Router without any shields through Serial Port. "Not USB"

What you need!

  • Arduino
  • Router
  • 3 wires that's it

But before I start Just a moment of peace for the Holocaust that I made in my lab before I figure it out.

Cisco e900, TP-Link, UBNT, Motorolla RIP :')

You can connect your Arduino to 3G/4G portable router too like this one

Lets start..

Step 1: DD-WRT Router Firmwere

It's an open source firmware, open this link and search on your router model to download your firmware. after that just follow these steps:

  • Connect your Router to your PC over Ethernet DON'T use WiFi connections.
  • Upload your firmware and just wait until your router restart normally.
  • Open any browser and type the default IP address 192.168.1.1
  • Make sure there is internet on your router.

DO NOT attempt to reset or power cycle the router while it is still in the process of upgrading!
Wait a couple of minutes after upgrade is complete.

Note: If you can't have internet on you router after entering your setting, In this case your router have Dirty NVRAM

Your old firmware files still there, make 30-30-30 Hard reset.

The following procedure will clear out the NVRAM and set dd-wrt back to default values:

  • With the unit powered on, press and hold the reset button on back of unit for 30 seconds.
  • Without releasing the reset button, unplug the unit and hold reset for another 30 seconds
  • Plug the unit back in STILL holding the reset button a final 30 seconds

Step 2: Wire Connections

Most Routers have Serial ports, Open your Router and search on these ports, usually 4/5 pins, If you couldn't find them "They are separate" just google it :)

Arduino Router

TX RX

RX TX

GND GND

NOTE: You can't upload any code to your Arduino if you connect TX-RX to your router, make them removable.

Step 3: First Test "Connections"

To be sure your wires is correct Follow these steps:

  • Upload this code to your Arduino "empty code"
    void setup(){ }
    void loop(){ }
  • Open your Serial Monitor from Arduino IDE and choose the higher Baud Rate 115200

If you could see weird charterers your connections work great, But we still not have the same baud Rate.

Step 4: Second Test Baud Rate

Both devices "Arduino, Router" Must have the same Baud speed.

  • open any browser Then enter this IP address "192.168.1.1"
  • Navigate to Administrations then Commands, Put This code below inside the white box
echo "hello world" > /div/tts/0 115200
  • Open your Serial Monitor again from Arduino IDE and choose the same Baud Rate.

echo it's a command like printIn in C language, tss the serial port and 115200 the baud rate.

NOTE: some routers have two serial ports, If that doesn't work change it from "0" to "1"

If you want show bandwidth/clients/QOS just reset your router all the data will be shown in Serial Monitor.

Check attached file if you want add LCD 16X2 to your router.

Step 5: Coding

There is two type of communications:

  1. Router to Arduino
  2. Arduino to Router

For the first type:

  • just upload this code to your Arduino, That's will turn ON your PIN13 LED.
void setup () {
  pinMode(13,OUTPUT);
  Serial.begin(115200);
}
void loop () {
  int val;
        val=Serial.read();
      if(val=='1') {digitalWrite(13,HIGH); } 
   }
  }
 }
  • From your Router Run This command.
echo "1" > /div/tts/0 115200 

That's it, you can Turn ON your LED at PIN13, add other code line to turn it OFF by using"0" this time.

For the second type:

Each time your Arduino start communicate with your Router, Your router will ask about username and password, so this is the base of your code:

// DD-WRT user-ID,password,serial-speed settings
#define USER_ID "root"
#define PASSWD "XXXX"
#define SERIAL_SPEED 115200
//Server IP and TCP-Port Listening settings
#define SERVER "192.168.X.XXX"
#define PORT "5555"

Be sure your router not blocked your port "5555"

Simple like that! There is allot of apps at Android store for SSH commands, to control
your Arduino over internet, anyway in the next tutorial I will show you how you can build your own webpage or VB.net program, If you have any question, feel free to ask.

My Last project 4KM wireless for my Arduino :)

Be the First to Share

    Recommendations

    • For the Home Contest

      For the Home Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge

    12 Comments

    0
    joelvargas171
    joelvargas171

    5 years ago

    Good tutorial how do I turn off the led?

    0
    --scientists--
    --scientists--

    5 years ago

    Great project just one question ??Can i send commands to router from different network...can i control e.x lights when i am not home ,for example from different city
    Thanks

    0
    DIY Hacks and How Tos

    Good idea. I might have to try this out in a future Arduino project.

    0
    Ivan Igor
    Ivan Igor

    Reply 5 years ago

    If you need any help let me know ;)

    0
    alxandre.alzate
    alxandre.alzate

    7 years ago

    where ca n I see your next project to make my own page? I like your tutorials

    0
    Ivan Igor
    Ivan Igor

    Reply 5 years ago

    Soon :)

    0
    85rocco
    85rocco

    7 years ago on Introduction

    It's worth mentioning that many routers use 3.3v logic for their serial port so a 3.3v/5.0v level converter may be necessary. The DD-wrt or OpenWRT website should help you locate your router's serial port connections and determine whether or not they are 5v compatible.

    0
    Ivan Igor
    Ivan Igor

    Reply 5 years ago

    Yup that's true, thanks for your note :)

    0
    3roBVP0s50C4TxeT
    3roBVP0s50C4TxeT

    6 years ago

    Great article. How do you use a generic 3G/4G portable router? Do you still need to change it to DD-WRT? If so how do you find what version of DD-WRT you use for a generic 3G/4G portable router? These units seem to be quite different in that they are powered through a usb port. I guess my questions amount to how do you hook one of these up compared to a self powered non-generic router?

    0
    Ivan Igor
    Ivan Igor

    Reply 5 years ago

    There is a special DDWRT firmware for these routers, it depends on the
    router processor/nvram size, you can find it on their website in forums
    section

    0
    BoKKeR
    BoKKeR

    7 years ago

    amazing project I like it :)

    0
    Ivan Igor
    Ivan Igor

    Reply 5 years ago

    Thanks :)