In this tutorial, you’ll learn how to connect an ESP32 board to Arduino IoT Cloud. You will be able to remotely control an LED. Additionally, you will monitor LDR (Light Dependent Resistor) sensor values. This is a beginner-friendly project, ideal for learning real-time IoT monitoring and control. As well as this project is a part of my free Udemy Internet of things for beginners course.
Components Required
- Doit esp32 devkit v1
- 5MM LED
- 220-ohm resistor (for LED)
- LDR (photoresistor)
- 10k-ohm resistor (for voltage divider with LDR)
- Breadboard and jumper wires
- Arduino account (https://create.arduino.cc/)
Connect the Circuit
Before moving towards the arudino IoT Cloud firstly we need to connect LED and LDR with ESP32 Development board. follow the below steps and diagram.
Diagram

LED
- Anode (+) → GPIO 2 (D2)
- Cathode (–) → 220-ohm resistor → GND
LDR Sensor
- One end of LDR → 3.3V
- Other end → GPIO 32 (analog input) AND one leg of 10k resistor
- Other leg of 10k resistor → GND
This forms a voltage divider to read LDR values using analog input.
Now it’s time to Follow the below steps to set up your Arduino IoT Cloud. Create a Thing, Device, Cloud variable, and Dashboard for data visualizations. If you already have an Arduino IoT Cloud account, then skip the first step.
Step 1: Set Up Arduino IoT Cloud
- Go to: https://create.arduino.cc
- Sign in or create an account.
- Open IoT Cloud from the menu.
- Install the Arduino Create Agent (as it’s mandatory for Arduino Web IDE to communicate with your development board).
Step 2: Create a Thing
- Go to the “Things” tab and click “Create Thing”.
- Name it:
ESP32 LED-LDR
. - Click “Select Device” under Associated Device Section. Then, click “Setup New Device” and choose Third Part Devices. Next, select ESP32 and from the drop down, select DOIT ESP32 DEVKIT V1.
- On the next steps copy the Secret Key which will be used during network configurations.
- Click “Configure” under Network Section. Provide WiFi SSID, Password, and Secret key. Secret key was provided during development board setup.
- Add following Cloud variables.
Add Variables
Variable Name | Declaration | Type | Direction | IoT Cloud Property |
---|---|---|---|---|
LED | lED | Boolean | Read/Write | ON/OFF control |
LDR | lDR | Integer | Read Only | View analog value |

Step 3: Write the Code
Navigate to “Sketch” tab and past the below code.
/*
Sketch generated by the Arduino IoT Cloud Thing "ESP32 LED-LDR"
https://create.arduino.cc/cloud/things/00ff26c4-f1c3-4833-9f6e-b96a7eb2103f
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int lDR;
bool lED;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
void setup() {
//Init the Pins
pinMode(2, OUTPUT); //LED
pinMode(32,INPUT); //LDR
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
int ldrValue=analogRead(32);
Serial.print("LDR=");
Serial.println(ldrValue);
lDR=ldrValue;
delay(100);
}
/*
Since LED is READ_WRITE variable, onLEDChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLEDChange() {
// Add your code here to act upon LED change
if(lED==true){
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
}else{
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
}
}
Step 4: Create a Dashboard
- Go to Dashboards → Click “Dashboard” Green button
- Drag a Switch widget → Link it to
lED
- Drag a Gauge widget → Link it to
lDR
- Customize colors/icons as you like

Test It!
- Open the dashboard on your PC or phone.
- Use the switch to turn the LED on/off remotely.
- Monitor how
lDR
changes with light intensity.
Bonus: Access Anywhere
Once your board is connected to Wi-Fi, you can control it remotely. You can monitor it from anywhere in the world using Arduino IoT Cloud.
What You Learned
- How to connect ESP32 to Arduino IoT Cloud
- How to control an LED remotely
- How to monitor real-time LDR sensor data
- How to create a simple IoT dashboard