The First IOT Program

To start learning IoT, first, it is important to learn how to make circuits using a breadboard and a microcontroller. Then it is important to control that circuit using a program. There are some simulators available to make the beginner of IoT learn both these concepts without even having the IoT devices available. However, to get real results, using the circuit components and making the actual circuit is important. In this article, using two different examples, the way to start IoT programming is given. In example 1, the Wokwi simulator is used and in example 2, the actual circuit using a breadboard, ESP32, LEDs, resistors, and wires are made and the components are controlled using the C program made using the Arduino IDE.

Prerequisites: To follow along with Example 2, you'll need Arduino IDE installed on your computer. You can download it from arduino.cc and install the ESP32 board package.

Syntax

Basic IoT programming in Arduino C follows this structure

void setup() {
    // Initialization code - runs once
    pinMode(pin_number, OUTPUT/INPUT);
}

void loop() {
    // Main code - runs continuously
    digitalWrite(pin_number, HIGH/LOW);
    delay(milliseconds);
}

Example 1: Getting Started Using Wokwi Simulator

Wokwi is an online platform where virtual circuits can be made and programs to control these circuits can be written and tested. It is an easy-to-use and free service to start learning IoT. You can access Wokwi at wokwi.com.

Circuit Design Steps

Step 1 Log in to Wokwi. Start a new ESP32 project on Wokwi Simulator.

Step 2 Add a breadboard with ESP32 to the virtual circuit area using the + sign.

Step 3 Connect the breadboard negative rail to the ESP32's GND pin.

Step 4 Add four LEDs. Connect the cathodes (shorter legs) of LEDs to the blue rail and anodes to resistors. Connect the resistors to ESP32 pins (D32, D33, D25, D26).

Step 5 In the diagram tab, change LED colors as needed (they start as red by default).

Step 6 Write the C program in the code area and compile using the play button.

The Code

int delay_times = 200;
int coloredLed_pin[4] = {32, 33, 25, 26};
int n, q;

void setup() {
    for (int n = 0; n < 4; n++) {
        pinMode(coloredLed_pin[n], OUTPUT);
    }
    delay(200);
}

void loop() {
    // Light LEDs from lowest pin to highest pin
    for (n = 0; n < 4; n++) {
        digitalWrite(coloredLed_pin[n], HIGH);
        delay(delay_times);
        digitalWrite(coloredLed_pin[n], LOW);
    }
    
    // Light LEDs from highest pin to lowest pin
    for (q = 3; q >= 0; q--) {
        digitalWrite(coloredLed_pin[q], HIGH);
        delay(delay_times);
        digitalWrite(coloredLed_pin[q], LOW);
    }
}

The program creates a sequential LED light pattern that moves back and forth across four LEDs.

Wokwi Simulator Interface Code Area void setup() { pinMode(32, OUTPUT); } void loop() { digitalWrite(32, HIGH); delay(200); } Circuit Area ESP32

Example 2: Making the First IoT Circuit Using Arduino IDE

First the circuit is made using breadboard, ESP32, 3 colored LEDs, 3 resistors and some male-to-male wires. Arduino IDE is then used to write the C program, compile it and upload it to ESP32 for execution.

Circuit Design Steps

Step 1 Connect the ESP32 microcontroller to the breadboard.

Step 2 Connect the breadboard negative rail to the ESP32's GND pin.

Step 3 Use three differently colored LEDs. Connect the cathodes (shorter legs) to the blue rail and anodes to resistors. Connect the resistors to ESP32 pins (D25, D26, D27).

Step 4 Open Arduino IDE and select the ESP32 board.

Step 5 Write the C program and compile it using the verify button.

Step 6 Upload the program to ESP32 using the upload button.

The Code

// The time between LEDs on and off state
int delay_times = 200;

// Colored LEDs positive line through resistors connected to pins D25, D26, D27
int coloredLed_pin[3] = {25, 26, 27};

// Variables to select LEDs one by one
int n, q;

void setup() {
    for (int n = 0; n < 3; n++) {
        // Set all LEDs as Output components
        pinMode(coloredLed_pin[n], OUTPUT);
    }
    delay(200);
}

void loop() {
    // Light LEDs from lowest pin to highest pin
    for (n = 0; n < 3; n++) {
        // Turn LED ON
        digitalWrite(coloredLed_pin[n], HIGH);
        delay(delay_times);
        // Turn LED OFF
        digitalWrite(coloredLed_pin[n], LOW);
    }
    
    // Light LEDs from highest pin to lowest pin
    for (q = 2; q >= 0; q--) {
        // Turn LED ON
        digitalWrite(coloredLed_pin[q], HIGH);
        delay(delay_times);
        // Turn LED OFF
        digitalWrite(coloredLed_pin[q], LOW);
    }
}

How It Works

Both examples use the same programming logic

  • setup() function initializes all LED pins as outputs
  • loop() function runs continuously, creating a sequential LED pattern
  • digitalWrite() controls LED state (HIGH = ON, LOW = OFF)
  • delay() creates timing between LED changes

Key Differences Between Examples

Aspect Wokwi Simulator Physical Circuit
Cost Free Requires hardware purchase
Learning Curve Beginner-friendly Requires wiring skills
Testing Instant simulation Real-world results
LEDs Used 4 LEDs 3 LEDs

Conclusion

This article demonstrated two approaches to creating your first IoT program using C. The Wokwi simulator provides an excellent starting point for beginners, while physical circuits offer hands-on experience with real components. Both methods teach the fundamental concepts of IoT programming using Arduino C syntax.

Updated on: 2026-03-15T14:28:56+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements