Arduino Uno R4 WiFi control LED via Web
In this tutorial, we are going to learn how to control an LED through a web interface using a browser on a PC or smartphone, utilizing the Arduino Uno R4 WiFi. In detail, , the Arduino Uno R4 WiFi will be programmed to work as a web server. Let's assume that the IP address of the Arduino Uno R4 WiFi is 192.168.0.2. Here are the details of how it works:
- When you enter 192.168.0.2 into the web browser, the browser sends a request to the Arduino, and the Arduino responds with a web page that contains the on/off button for controlling the LED.
- Similarly, when you click the "LED ON" button on the web page or type 192.168.0.2/led1/on into the web browser, the Arduino turns on the LED and responds with the control web page.
- Likewise, when you click the "LED OFF" button on the web page or type 192.168.0.2/led1/off into the web browser, the Arduino turns off the LED and responds with the control web page.
The tutorial offers the fundamentals that you can readily and innovatively customize to achieve the following:
- Controlling multiple LEDs through the web
- Redesigning the web user interface (UI)
Hardware Required
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
About LED and Arduino Uno R4
If you do not know about LED and Arduino Uno R4 (pinout, how it works, how to program ...), learn about them in the following tutorials:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Code
Quick Steps
- If this is the first time you use Arduino Uno R4, see how to setup environment for Arduino Uno R4 on Arduino IDE.
- Copy the above code and open with Arduino IDE
- Change the wifi information (SSID and password) in the code to yours
- Click Upload button on Arduino IDE to upload code to Arduino
- Open the Serial Monitor
- See the result on Serial Monitor.
- You will see an IP address, for example: 192.168.0.2. This is the IP address of the Arduino Web Server
- Open a web browser and enter one of the three formats below into the address bar:
- Kindly be aware that the IP address might vary. Please verify the current value on the Serial Monitor.
- You will also see the below output on Serial Monitor
- Check LED state
- You will see the web page of Arduino board on the web browser as below
- You are now able to control the LED on/off via the web interface
You can readily and innovatively customize the above ocde to achieve the following:
- Controlling multiple LEDs through the web
- Redesigning the web user interface (UI)
If you desire to enhance the web page's appearance with an impressive graphic user interface (UI), you can refer to the Arduino - Web Server tutorial for inspiration and guidance.