Turning My Roller Gate into a Smart WiFi-Controlled System

DIY WiFi Roller Gate Controller with ESP32-C3

ESP32C3 Board on Proto Board
ESP32C3 Board on Proto Board

Have you ever wondered if you could take any device and control it from your phone? Well, I did! I wanted to transform my home roller gate into a WiFi-controlled system, eliminating the unreliable RF remote provided by the manufacturer.

The Problem with Manufacturer-Provided Remotes

The RF remote that came with my roller gate has been a constant source of frustration:

  • Excessive Battery Drain: The remote’s battery runs out too quickly.
  • Lost Programming: The remote frequently forgets its paired state.
  • Manufacturer Dependency: If the remote malfunctions, I have to rely on the manufacturer to fix it.

To make things worse, the battery used in these remotes is:

  • Difficult to find in Sri Lanka
  • Toxic and disposable – A single-use battery with harmful compounds

Additionally, for some unknown reason, the system often loses its remote pairing, requiring reprogramming. While the controller board has a "Learn Mode", the manufacturer insists on doing the reprogramming themselves, which is both inconvenient and unnecessary.

And let’s not forget the cost—if you lose or damage a remote, replacing it costs over 3,000 rupees!

Time to Put My Electronics Degree to Work!

With all these issues piling up, I decided to take matters into my own hands. Using my background in electronics, I set out to build a WiFi-based solution that would allow me to control my roller gate from anywhere—no more unreliable remotes!

Soldered Prototype Board

Reverse Engineering the Gate Controller

Curious about how the gate controller worked, I decided to take apart the control board and see if I could integrate my own system. On the right side of the board, I found a green terminal block with markings for different functions:

  • UP
  • DOWN
  • STOP

Each pin was pulled up to 12V, meaning that shorting them to ground would activate the corresponding function. This was great news! It meant I could control the gate using simple transistors.

Designing the Circuit

To interface with the controller, I designed a simple circuit that allows an ESP32-C3 to switch these functions using three 2N3904 NPN transistors. Here's the schematic:


       +12V INPUT
           │
         [LM7805] (Voltage Regulator)
           │
           +5V ───────────────────+────────+
           │                      │        │
          GND                     │       GND (ESP32)
           │                      │        │
   .-------+----------------.     │        │
   |       │                |     │        │
   |     [ESP32-C3]         |     │        │
   |       │                |     │        │
   |   GPIOx ──[150Ω]─► B   |     │        │ Gate Controller Inputs
   |   GPIOy ──[150Ω]─► B   |     │        │ (Pulled up to +12V)
   |   GPIOz ──[150Ω]─► B   |     │        │
   '------------------------'     │        │
           │    │    │            │        │
           E    E    E            │        │
           │    │    │            │        │
         [2N3904] [2N3904] [2N3904] │        │
           │    │    │            │        │
           C    C    C            │        │
           │    │    │            │        │
           ├────┼────┼────────────o───────► (UP Pin)
           │    │    │            │
           ├────┼────o────────────o───────► (DOWN Pin)
           │    │    │            │
           ├────o────o────────────o───────► (STOP Pin)
           │    │    │
          GND  GND  GND (Transistors)

   (Note: Collectors (C) connect to gate controller pins.
    When GPIO is HIGH, transistor conducts, pulling gate pin to GND)
                

How It Works

Each 2N3904 transistor acts as a switch:

  • The ESP32-C3 GPIO pins control the base (B) of each transistor through a resistor (150Ω).
  • When the ESP32 outputs HIGH (3.3V), the transistor turns on, connecting the collector (C) to ground and activating the corresponding gate function (by pulling the 12V pin low).
  • The emitter (E) is tied to ground to complete the circuit.

Prototyping the System

With the circuit planned out, I quickly soldered a prototype using:

  • LM7805 (to step down 12V to 5V for the ESP32)
  • ESP32-C3 Supermini (for WiFi control)
  • 2N3904 NPN Transistors (x3)
  • Various resistors (10KΩ pull-downs maybe, 150Ω base resistors)
  • Electrolytic capacitors (for power stability)

This setup allowed me to control the gate wirelessly—no more dependency on the unreliable RF remote!

Close-up of Prototype Board

Setting Up the ESP32-C3 Supermini Web Server

To make the gate easily controllable from anywhere in my home, I configured the ESP32-C3 Supermini to:

  • Connect to my local WiFi network
  • Create its own Access Point (AP) for direct access
  • Host a web server that serves a control interface
  • Use mDNS so I can access it via a simple URL (e.g., `gatecontroller.local`)

With this setup, I could control my gate wirelessly from my phone or computer—no more unreliable RF remotes!

Web Interface Screenshot

Debugging a Strange ESP32-C3 Issue

During unit testing, everything worked perfectly. But once I soldered the ESP32 to the circuit and tried running the system, I was shocked—it wouldn't connect to WiFi!

I started troubleshooting:

  • Was it a soldering issue? 🤔 I checked all joints—everything seemed fine.
  • Was the antenna faulty? I applied pressure on the chip antenna, and suddenly, it connected! 🤨
  • Re-soldering the antenna? Still no luck.
  • Replacing the antenna? Same issue.




 

At this point, I needed an expert opinion. I reached out to Dilshan Jayakody, my mentor, who suggested:

💡 The issue might be WiFi power instability—the 5V rail capacitor could be too small to handle sudden power spikes when both WiFi AP and STA mode were running simultaneously.

The Fix: Adding a 470µF Capacitor

I soldered a 470µF capacitor across the 5V power input pins of the ESP32 module to stabilize the voltage… and it worked like a charm! 🎉

With the WiFi issue solved, I completed the prototype, connected everything, and finally tested the gate control. Success!

The Next Problem: Manual Buttons Stopped Working

Just when I thought everything was perfect, I realized that the manual control buttons on the gate weren’t working when my device was connected. It turned out my circuit was interfering with the existing buttons.

Instead of using three separate transistors for UP, DOWN, and STOP, I looked closer at the controller board and found a 1-key operation input (often labeled 'OSC' or similar) that cycles through the states:

🔼 UP   →   ⏹️ STOP   →   🔽 DOWN   →   ⏹️ STOP   →   (repeat)

This meant I only needed one transistor connected to this single input pin to operate the gate instead of three! I modified the circuit to use just one GPIO and one transistor connected to the 1-key input. A simple modification, and now everything worked perfectly, including the original manual buttons. ✅


Future Improvements

  • 🚀
    Design a dedicated PCB for a cleaner, more compact, and reliable build.
  • ⚡
    Replace the LM7805 linear regulator with an efficient SMPS buck converter (like MP1584EN or similar) to reduce heat generation and power consumption.
  • 📦
    Build a weatherproof enclosure using a standard project box with cable glands to protect the circuit from the elements.

This has been an exciting journey of reverse engineering, prototyping, and debugging! I want to thank Dilshan Jayakody again for his invaluable guidance. Innovation often starts with tackling everyday frustrations—so keep experimenting, learning, and stay curious!

Thank you for reading! 🙌

Running Deepseek R1 on my Laptop CPU (No GPU).

Running DeepSeek on a CPU with Ollama and Docker
AI Concept Image

Running DeepSeek on a CPU with Ollama and Docker

Note: Everything Written Here is from LLMs (OpenAI and Deepseek)

Introduction to DeepSeek

DeepSeek is a powerful AI tool designed for natural language processing and deep learning tasks, often relying on GPUs to accelerate computation. However, not everyone has access to high-performance GPUs, and DeepSeek's adaptability allows it to be deployed on CPU-only systems. In this blog post, I'll demonstrate how to run DeepSeek on a self-hosted server, specifically an 11th Gen Intel i5 laptop CPU. We'll leverage Ollama for model optimization and Docker for containerized deployment, ensuring an efficient and streamlined setup. Whether you're exploring AI for personal projects or lightweight applications, this guide will help you make the most of your hardware resources.

Installing Docker on Linux, macOS, and Windows

Docker is a powerful tool for containerization, making it easy to run and deploy applications in isolated environments. Here's how to install Docker on the three major operating systems.


1. Installing Docker on Linux

For Ubuntu, Debian, and similar distributions:

Step 1: Update your system
sudo apt update
sudo apt upgrade -y
Step 2: Install required dependencies
sudo apt install -y ca-certificates curl gnupg
Step 3: Add Docker’s official GPG key and repository
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 4: Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 5: Start Docker and enable it on boot
sudo systemctl start docker
sudo systemctl enable docker
Step 6: Verify installation
docker --version

2. Installing Docker on macOS

Step 1: Download Docker Desktop
Step 2: Install Docker
  • Open the downloaded .dmg file.
  • Drag the Docker icon into the Applications folder.
Step 3: Start Docker
  • Launch Docker from the Applications folder.
  • Follow the on-screen instructions to complete the setup.
Step 4: Verify installation

Open a terminal and run:

docker --version

3. Installing Docker on Windows

Step 1: Download Docker Desktop
Step 2: Install Docker
  • Run the downloaded .exe file.
  • Follow the installation wizard.
  • During the installation, ensure the option Enable WSL 2 features is selected (required for Windows 10/11).
Step 3: Start Docker
  • Launch Docker Desktop from the Start Menu.
  • Sign in with your Docker Hub account or create one.
Step 4: Verify installation

Open PowerShell or Command Prompt and run:

docker --version

Post-Installation Tips

Add Your User to the Docker Group (Linux):
sudo usermod -aG docker $USER

Log out and back in to apply changes.

Test Docker Installation:

Run a test container:

docker run hello-world
Install Docker Compose (if not included):
docker compose version

Install a Frontend for the LLM

After setting up Docker and Ollama, install a frontend like Chatbox.ai or open-webui for a user-friendly chat interface.

Open-WEBUI Screenshot

Open-WEBUI Interface

Installing Ollama

Ollama is a tool for running large language models (LLMs) locally. It simplifies model management and allows running advanced AI models on your hardware.

1. Installing Ollama on macOS

Ollama currently supports macOS natively. Here's how to install it:

Install Ollama via Homebrew:
brew install ollama/tap/ollama
Start the Ollama service:
ollama serve
Verify Installation:

Run the following command to confirm:

ollama --version

2. Installing Ollama on Windows or Linux

Ollama doesn't yet natively support Windows or Linux, but you can run it on these platforms via macOS virtualization or containerization solutions like Docker. Stay updated by visiting the Ollama official site.

Downloading and Running Different DeepSeek LLMs

Once Ollama is installed, you can easily install and run models like DeepSeek.

1. Install a Model

To install a model, use the ollama run command. This will pull the model if it's not already downloaded. For example, to install and run a DeepSeek model:

ollama run deepseek-r1:8b

(Replace 8b with the desired model size)

2. List Available Models

To see all installed models:

ollama list

3. Run a Model

To use a specific installed model:

ollama run <model_name>

Example:

ollama run deepseek-r1:8b

4. Managing Models

Delete a Model: If you need to remove a model to free up space:

ollama rm <model_name>

Example:

ollama rm deepseek-r1:8b

5. Testing and Using DeepSeek LLMs

You can interact with the DeepSeek models through the terminal after running them. For example:

ollama run deepseek-r1:8b

Then, type your input query to test the model's capabilities.

DeepSeek Models Available

DeepSeek provides multiple models optimized for various tasks. Common versions include:

# 1.5B version (smallest):
ollama run deepseek-r1:1.5b

# 8B version:
ollama run deepseek-r1:8b

# 14B version:
ollama run deepseek-r1:14b

# 32B version:
ollama run deepseek-r1:32b

# 70B version (biggest/smartest):
ollama run deepseek-r1:70b

This is the command to run and install a model from Ollama:

ollama run deepseek-r1:8b

Screenshots

Screenshot 1 Screenshot 2 Screenshot 3

Conclusion

In conclusion, running DeepSeek on an 11th Gen Intel i5 laptop CPU proves to be a practical solution for lightweight AI workloads. With the 8B model, the system achieves a processing speed of 1.5–2 words per second, making it perfectly suitable for small-scale applications. While it utilizes around 80–90% of the CPU during operation, the performance is stable and reliable, demonstrating that even modest hardware can power advanced language models effectively when optimized with tools like Ollama and Docker.

Further Reading

Read this for the comparison of the Models available: https://huggingface.co/deepseek-ai/DeepSeek-V3

Learning Ansible

Week 1 - 27/12/2024



 Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It simplifies complex IT tasks by automating repetitive processes, making it easier to manage large-scale systems.

Key Features of Ansible

  • Agentless: Unlike other automation tools, Ansible does not require any agent software to be installed on the managed nodes. It uses SSH for communication, making it lightweight and easy to set up.

  • Declarative Language: Ansible uses a simple, human-readable language called YAML (Yet Another Markup Language) to define automation tasks. This makes it accessible to both developers and system administrators.

  • Idempotency: Ansible ensures that tasks are idempotent, meaning they can be run multiple times without changing the system's state if it is already in the desired state.

  • Extensible: Ansible has a modular architecture, allowing users to extend its functionality with custom modules, plugins, and roles.

Use Cases

  • Configuration Management: Ansible can manage the configuration of servers, ensuring they are set up consistently and correctly.

  • Application Deployment: Automate the deployment of applications across multiple servers, reducing the risk of human error.

  • Orchestration: Coordinate complex workflows and processes across different systems and environments.

  • Provisioning: Set up and configure new servers and infrastructure components.

Getting Started with Ansible

  1. Install Ansible: You can install Ansible using package managers like pip, apt, or yum. For example, to install Ansible using pip, run:

    bash
    pip install ansible
    
  2. Create an Inventory File: An inventory file lists the hosts and groups of hosts that Ansible will manage. Here's an example of a simple inventory file:

    ini
    [webservers]
    web1.example.com
    web2.example.com
    
    [dbservers]
    db1.example.com
    db2.example.com
    
  3. Write a Playbook: A playbook is a YAML file that defines the tasks Ansible will perform on the managed hosts. Here's an example of a basic playbook:

    yaml
    ---
    - name: Install and configure web server
      hosts: webservers
      become: yes
      tasks:
        - name: Install Apache
          apt:
            name: apache2
            state: present
    
        - name: Start Apache service
          service:
            name: apache2
            state: started
            enabled: yes
    
  4. Run the Playbook: Use the ansible-playbook command to run the playbook:

    bash
    ansible-playbook -i inventory playbook.yml
    

Benefits of Using Ansible

  • Simplicity: Ansible's straightforward syntax and agentless architecture make it easy to learn and use.

  • Scalability: Ansible can manage thousands of nodes efficiently, making it suitable for large-scale environments.

  • Flexibility: Ansible can be used for a wide range of automation tasks, from simple configuration management to complex orchestration

Why Use Ansible Rather than Jenkins 

  1. Configuration Management: Ansible excels in configuration management, automation, and orchestration, while Jenkins is primarily a CI/CD tool.

  1. Agentless Architecture: Ansible operates without the need for agents on target machines, simplifying setup and reducing overhead.

  2. Ease of Use: Ansible uses a simple, human-readable YAML syntax, making it easier to write and understand automation scripts.

  3. Idempotency: Ansible ensures tasks are idempotent, maintaining consistency in your infrastructure.

  4. Integration: Ansible integrates well with a wide range of tools and platforms, focusing on infrastructure management and automation.

  5. Declarative Approach: Ansible follows a declarative approach, defining the desired state, while Jenkins follows an imperative approach, defining the steps to be executed


    As I use Jenkins for Work, it was a refreshing to learn Ansible for Deployments.



Week 2 - 27/12/2024


Learning NodeJS and moving into DENO



What is

  • Runtime Environment: is built on Chrome's V8 JavaScript engine, enabling you to run JavaScript code outside of a web browser.

  • Event-Driven: It uses an event-driven, non-blocking I/O model, making it efficient and suitable for real-time applications.

  • Single-Threaded: Despite being single-threaded, can handle many connections simultaneously thanks to its asynchronous nature.

Key Features

  • NPM (Node Package Manager): A vast library of open-source packages that you can use to extend the functionality of your applications.

  • Asynchronous Programming: uses callbacks, promises, and async/await to handle asynchronous operations.

  • Modules: has a module system that allows you to organize your code into reusable components.

Use Cases

  • Web Servers: is commonly used to build web servers and APIs.

  • Real-Time Applications: Ideal for applications that require real-time communication, such as chat apps and online gaming.

  • Microservices: is well-suited for building microservices due to its lightweight and modular nature.

Getting Started

  1. Install : Download and install from the .

  2. Create a Project: Initialize a new project using npm init and create a package.json file.

  3. Write Your First Script: Create a simple JavaScript file, such as app.js, and write your first code.

Example Code

Here's a simple example of a server:

javascript
const http = require('http');

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello, World!\n');
});

const port = 3000;
server.listen(port, () => {
    console.log(`Server running at http://localhost:${port}/`);
});

This code creates a basic HTTP server that listens on port 3000 and responds with "Hello, World!" when accessed








Using Deno for a NodeJS replacement,

Deno is a modern runtime for JavaScript and TypeScript, created by Ryan Dahl, the original developer of It was designed to address some of the shortcomings of and to provide a more secure and efficient environment for running JavaScript and TypeScript code. Here are some advantages of Deno over Node.js:

  1. Security: Deno has a secure-by-default approach. It runs code in a sandboxed environment and requires explicit permissions for file system access, network access, and environment variables. This reduces the risk of security vulnerabilities.

  2. TypeScript Support: Deno has built-in support for TypeScript, allowing you to write and run TypeScript code without the need for additional tools or configuration. This makes it easier to work with TypeScript out of the box.

  3. Simplified Dependency Management: Deno uses URL-based imports for dependencies, eliminating the need for a separate package manager like npm. This simplifies dependency management and reduces the risk of dependency-related issues.

  4. Standard Library: Deno comes with a standard library that is audited and maintained by the Deno team. This ensures a consistent and reliable set of APIs for common tasks, reducing the need for third-party libraries.

  5. Modern Features: Deno leverages modern JavaScript features and web standards, making it more aligned with current web development practices. It also includes built-in development tooling, such as a linter, formatter, and test runner.

  6. Single Executable: Deno is distributed as a single executable file, making it easy to install and use without the need for additional setup or configuration.

While Deno offers several advantages, it's important to consider your specific use case and requirements when choosing between Deno and has a mature ecosystem, extensive community support, and a vast library of packages, which can be beneficial for many projects.


Getting Deno Working

Getting Started with Deno

  1. Installation:

    • Windows: Use the PowerShell command:

      sh
      iwr https://deno.land/x/install/install.ps1 -useb | iex
      
    • macOS/Linux: Use the shell command:

      sh
      curl -fsSL https://deno.land/x/install/install.sh | sh
      
  2. Running a Script:

    • Create a simple TypeScript file, hello.ts:

      ts
      console.log("Hello, Deno!");
      
    • Run the script using Deno:

      sh
      deno run hello.ts
      
  3. Permissions:

    • Deno is secure by default. To allow network access, use the --allow-net flag:

      sh
      deno run --allow-net server.ts
      
  4. Importing Modules:

    • Deno uses URL-based imports. For example:

      ts
      import { serve } from "https://deno.land/std@0.95.0/http/server.ts";
      
  5. Standard Library:

    • Deno comes with a standard library that you can use without additional dependencies. Check out the for more information.

  6. Development Tools:

    • Deno includes built-in tools like a linter, formatter, and test runner. You can use them as follows:

      sh
      deno lint
      deno fmt
      deno test
      

Deno offers a secure, modern, and efficient environment for JavaScript and TypeScript development.










Setting Up Pip for Python 3 on Ubuntu 24.04 and Above .

Setting Up PIP for Python 3+ on Ubuntu 24 and Above Using pip.conf

Setting Up PIP for Python 3+ on Ubuntu 24 and Above Using pip.conf

Introduction

This guide will walk you through the steps to get PIP install commands working for Python 3+ on Ubuntu 24 and above, using the pip.conf configuration file. In this the Pip Configuration is created because newer versions dont allow PIP packages to be installed from anysite, but the APT repo accepted libraries only

Step 1: Install Python 3 and PIP

  1. Update System Packages:
    sudo apt update
    sudo apt upgrade
  2. Install Python 3 (if not already installed):
    sudo apt install python3
  3. Install PIP for Python 3:
    sudo apt install python3-pip
  4. Verify PIP Installation:
    pip3 --version

Step 2: Configure pip.conf

  1. Create or Edit pip.conf:

    Create the pip.conf file in the appropriate directory. For user-specific configuration, create it in ~/.config/pip/. For global configuration, create it in /etc/pip/.

  2. Add Configuration Settings:

    Open the pip.conf file in a text editor and add the following settings:

    [global]
    break-system-packages = true
    

Step 3: Using PIP with the Configuration

  1. Install a Python Package:
    pip3 install <package-name>
  2. Upgrade a Python Package:
    pip3 install --upgrade <package-name>
  3. Uninstall a Python Package:
    pip3 uninstall <package-name>

Conclusion

By following these steps, you can ensure that PIP install commands work seamlessly for Python 3+ on Ubuntu 24 and above, using the pip.conf configuration file. This setup will help you manage Python packages efficiently and avoid common issues related to package installations.

Feel free to reach out if you need any further assistance! 🚀

Let's talk about RS485

RS-485 Communication

Let's talk about RS-485

What is RS485?

RS485 is a standard for serial communication that allows multiple devices to communicate over a single pair of wires. It's used in industrial environments due to its robustness and ability to cover long distances.

Basic Concepts

  • Differential Signaling: RS485 uses differential signaling, which means it sends data as the difference between two voltages on a pair of wires (A and B). This helps in reducing noise and allows communication over long distances (up to 1.2 km or about 4000 feet).
  • Multi-Device Communication: Up to 32 devices can be connected on a single RS485 bus.
  • Half-Duplex: Communication is typically half-duplex, meaning devices take turns sending and receiving data on the same pair of wires.

Operation

  1. Data Transmission:
    • When a device wants to send data, it generates a differential voltage (e.g., A = +5V and B = 0V for a binary '1', A = 0V and B = +5V for a binary '0').
    • This voltage difference is transmitted over the twisted pair of wires.
  2. Data Reception:
    • The receiving device detects the differential voltage and interprets it back into binary data.
    • This method helps in rejecting common-mode noise because the noise affects both wires equally, and the differential receiver can cancel it out.

Required Electronics

  1. RS485 Transceiver:
    • This IC converts TTL (Transistor-Transistor Logic) level signals from a microcontroller or other logic device to RS485 differential signals.
    • Popular transceivers include MAX485, SN75176, and ADM485.
  2. Microcontroller:
    • A microcontroller or microprocessor to handle the data you want to send or receive. This could be an Arduino, Raspberry Pi, or any other MCU.
  3. Termination Resistor:
    • To prevent signal reflections, a termination resistor (typically 120 ohms) is placed at both ends of the communication line.
  4. Pull-up/Pull-down Resistors:
    • These resistors ensure the line remains in a known state when no device is driving the bus, preventing floating inputs.

Theories Behind RS485

  1. Differential Signaling:
    • By sending the same signal as a positive voltage on one wire and as a negative voltage on another wire, RS485 can effectively cancel out noise picked up along the transmission line.
  2. Common-Mode Rejection:
    • This technique ensures that noise which affects both wires equally does not impact the signal integrity.
  3. Multipoint Communication:
    • RS485 supports multipoint communication, meaning multiple devices can share the same bus without interference, provided only one device transmits at a time.

Steps to Implement RS485 Communication

  1. Set Up the Hardware:
    • Connect the RS485 transceiver to your microcontroller.
    • Connect the A and B lines of the transceiver to the A and B lines of other RS485 devices on the bus.
    • Place a 120-ohm termination resistor at both ends of the RS485 bus.
  2. Initialize the Microcontroller:
    • Configure the UART (Universal Asynchronous Receiver/Transmitter) on your microcontroller to match the baud rate, parity, and stop bits of the RS485 network.
  3. Write Communication Code:
    • Use the UART interface of your microcontroller to send and receive data.
    • Ensure proper timing and control so only one device transmits at any time.
  4. Test the Communication:
    • Use a simple protocol to send and receive messages between devices.
    • Verify data integrity and check for any communication issues like collisions or noise interference.

Example

For an Arduino with a MAX485 transceiver:

  • Connect RO (Receiver Output) to Arduino RX.
  • Connect DI (Driver Input) to Arduino TX.
  • Connect DE (Driver Enable) and RE (Receiver Enable) to a digital pin (e.g., pin 2) to control transmission and reception.

Sample Arduino Code:


#define DE_RE 2

void setup() {
  pinMode(DE_RE, OUTPUT);
  digitalWrite(DE_RE, LOW); // Enable receiver
  Serial.begin(9600);
}

void loop() {
  // Send data
  digitalWrite(DE_RE, HIGH); // Enable transmitter
  Serial.write("Hello RS485");
  delay(100); // Wait to ensure data is sent
  digitalWrite(DE_RE, LOW); // Enable receiver

  // Receive data
  if (Serial.available()) {
    String received = Serial.readString();
    Serial.println("Received: " + received);
  }

  delay(1000); // Wait before next transmission
}
  

This code switches between sending and receiving modes, ensuring no conflict on the RS485 bus.

By understanding these basics, you can effectively design and implement RS485 communication for your project.

SLIR Projects - Small Projects with big theory

 SLIR - Sri Lanka Institute of Robotics - Advanced Robotics Course Projects 


Manipulating a GPIO in a PIC MC
Controlling a LCD using a PIC microcontroller

Connecting a Stepper Motor to Motor Driver
Connecting Motor Driver to arduino 
Optocoupler arduino shield to reduce EMI and
drive high power components
Water Level Adjuster using pump 
Program the System
Running Tests


Complete Setup

Penumatic Converyer belt and part picker
Penumatic Converyer belt and part picker