Week 11 – Networking and Communication

Exploring UART, I2C, and HTTP Protocols


Overview

In Week 11, I worked on networking and communication between devices. The goal was not just to connect components, but to understand how devices actually exchange data and how this data moves inside a system.

At the beginning, I thought communication is simple — just connect wires and it works. But in practice, I realized that every protocol has its own rules, timing, and logic. If even one small thing is wrong, the whole system stops working.

During this week, I worked with three protocols: - UART
- I2C
- HTTP

Each one showed a different level of communication, from simple direct connection to full wireless control.


1. Understanding the Idea of Communication

Before building anything, I tried to understand what “communication” really means in electronics.

When two devices communicate: - One device sends data
- The other receives it
- Both must understand the format

If they don’t follow the same rules, communication fails.

For example: - Wrong speed → data becomes garbage
- Wrong wiring → no signal
- Missing power → nothing works

This helped me understand that communication is not just wires — it is a system of rules.


2. UART Communication (Two Arduino Boards)

What I Wanted to Do

I wanted to send a simple message from one board to another and check if it arrives correctly.


What I Did (Real Process)

First, I took two Arduino Uno boards.

Then I connected them:

  • TX of first board → RX of second
  • RX of first board → TX of second
  • GND → GND

At first, I connected TX to TX by mistake, and nothing worked. This helped me understand that communication must be crossed.

After wiring, I wrote two programs: - one sends data
- one receives data

The sender sends the word "Hello" every second.

The receiver listens continuously and waits for data.

When data arrives, it reads it and prints it.

What Actually Happens

Inside the system: - Sender converts text into signals
- Signals go through TX wire
- Receiver reads signals from RX
- Converts them back into text

So it's like translating between digital signals and human-readable text.

Code

// Sender
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("Hello");
  delay(1000);
}

// Receiver
void setup() {
  Serial.begin(9600);
}
void loop() {
  if (Serial.available()) {
    String message = Serial.readString();
    Serial.println("Received: " + message);
  }
}

What I Learned

  • Communication needs correct wiring
  • Both devices must use same speed
  • Even simple systems can fail easily

UART helped me understand the basics of communication.


3. I2C Communication (LCD Display)

What I Wanted to Do

Display text on an LCD using only two wires.


What I Did (Real Process)

I connected the LCD to my custom board using:

  • SDA
  • SCL
  • VCC
  • GND

At first, nothing appeared on the screen.

I checked: - wiring
- code
- power

Then I realized: - LCD needs correct address
- LCD needs stable power

After fixing these, it started working.

What Actually Happens

In I2C: - The microcontroller sends a signal
- It includes the address of the device
- Only that device responds

So unlike UART, here many devices can exist, but only one responds at a time.


Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello Abdikarim");
}

void loop() {
}

What I Learned

  • I2C reduces wires
  • Address is very important
  • Power stability matters a lot

This was more complex than UART, but more powerful.


4. HTTP Communication (ESP8266 Wi-Fi)

What I Wanted to Do

Control LEDs from my phone using Wi-Fi.


What I Did (Real Process)

I connected: - 2 LEDs
- resistors
- ESP8266

Then I wrote code to: - connect to Wi-Fi
- create a web server
- show buttons

At first: - Wi-Fi did not connect
- page did not load

I checked: - SSID and password
- serial monitor
- IP address

After fixing mistakes, I opened the IP in browser.

Then I pressed buttons — and LEDs turned ON/OFF.

What Actually Happens

  • Browser sends request (like /on1)
  • ESP8266 receives request
  • Code checks what was requested
  • Executes command (turn LED ON)

So now communication is not just wires — it is over network.


Code

#include <ESP8266WiFi.h>

const char* ssid = "ESP8266_SERVER";
const char* password = "12345678";

WiFiServer server(80);

String header;

String output5State = "off";
String output4State = "off";

const int output5 = 14;  // GPIO14 = D5
const int output4 = 4;   // GPIO4 = D2

unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long timeoutTime = 2000;

void setup() {
  Serial.begin(115200);

  pinMode(output5, OUTPUT);
  pinMode(output4, OUTPUT);
  digitalWrite(output5, LOW);
  digitalWrite(output4, LOW);

  WiFi.softAP(ssid, password);

  Serial.println("WiFi создан!");
  Serial.print("IP адрес: ");
  Serial.println(WiFi.softAPIP());

  server.begin();
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("New Client.");
    String currentLine = "";

    while (client.connected() && currentTime - previousTime <= timeoutTime) {
      currentTime = millis();

      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        header += c;

        if (c == '\n') {
          if (currentLine.length() == 0) {

            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            if (header.indexOf("GET /14/on") >= 0) {
              output5State = "on";
              digitalWrite(output5, HIGH);
            } else if (header.indexOf("GET /14/off") >= 0) {
              output5State = "off";
              digitalWrite(output5, LOW);
            } else if (header.indexOf("GET /4/on") >= 0) {
              output4State = "on";
              digitalWrite(output4, HIGH);
            } else if (header.indexOf("GET /4/off") >= 0) {
              output4State = "off";
              digitalWrite(output4, LOW);
            }

            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<style>body{text-align:center;font-family:Arial;} .button{padding:15px 30px;font-size:20px;} </style></head>");
            client.println("<body><h1>ESP8266 Server</h1>");

            client.println("<p>GPIO 14: " + output5State + "</p>");
            client.println("<a href=\"/14/on\"><button class=\"button\">ON</button></a>");
            client.println("<a href=\"/14/off\"><button class=\"button\">OFF</button></a>");

            client.println("<p>GPIO 4: " + output4State + "</p>");
            client.println("<a href=\"/4/on\"><button class=\"button\">ON</button></a>");
            client.println("<a href=\"/4/off\"><button class=\"button\">OFF</button></a>");

            client.println("</body></html>");
            client.println();

            break;
          } else {
            currentLine = "";
          }
        } else if (c != '\r') {
          currentLine += c;
        }
      }
    }

    header = "";
    client.stop();
    Serial.println("Client disconnected.");
  }
}


What I Learned

  • Devices can be controlled remotely
  • Communication can happen over internet
  • This is the base of IoT

Comparison (My Understanding)

  • UART → easiest, but limited
  • I2C → more flexible
  • HTTP → most powerful but complex

Reflection

This week changed how I understand electronics.

Before: I thought components just work together.

Now: I understand they communicate using rules and signals.

The biggest lesson: Even small mistake → system fails.

Debugging step by step is the most important skill.


Conclusion

This week helped me understand how devices talk to each other.

Now I can: - send data
- receive data
- control devices remotely

This is very important for my final project and future work.


Files

Download files