Tasmota on ESP8266 NodeMCU with Arduino IDE
|
Tasmota is an alternative open-source firmware for devices that are based on the ESP8266 WiFi chipset. The firmware provides the devices with timers, a web interface, Over The Air (OTA) updates and sensors support. It also allows control under HTTP, MQTT, KNX and serial. It is written for the Arduino IDE and PlatformIO.
With the Tasmota firmware installed, your device can read the state of buttons and switches, and many types of sensors for things like temperature, humidity, light, IR, etc. It can also control devices like relays, LEDs, displays, IR transmitters and many more.
In short, Tasmota turns your ESP8266 based board into a versatile IoT device without having to write your own code.


In this blog post, we will install Tasmota on the ESP8266 NodeMCU development board using the Arduino IDE. Then, as an example, we will configure Tasmota to toggle the onboard LEDs and one external LED. This will be a good starting point for future IoT and DIY home automation projects.


It was initially written for Sonoff devices, but it supports devices from many other brands like Electrodragon, MagicHome, AriLux, Blitzwolf, and Allterco. Of course, you can also install it on development boards like the Wemos D1 mini and the ESP8266 NodeMCU.
Preparing the Arduino IDE
First of all, you need to have the Arduino IDE installed. If you need help with that, then you should check out Installing the Arduino IDE on Windows 10 or Install or upgrade to the latest Arduino IDE on Linux.
After you have the IDE installed, you need to add the ESP8266 core to the IDE. You can read more about that in the blog post ESP8266 NodeMcu and Arduino IDE on Linux. The procedure is the same for Windows.
Download and install Tasmota project files
Download the Tasmota zip file from the Tasmota GitHub page. Extract it somewhere on your computer.
Find the location of your Arduino ‘sketchbook’ folder, see File > Preferences > Settings in your Arduino IDE.
- Copy the contents of the Tasmota ‘lib’ folder to the sketchbook ‘libraries’ folder.
- Copy the Tasmota ‘sonoff’ folder to your sketchbook folder.
Find the location of the Arduino IDE folder, see File > Preferences > Settings.
- Inside the Arduino IDE folder, find the directory ‘packages\esp8266\hardware\esp8266\2.x.x ‘
- Replace ‘platform.txt’ with the Tasmota file ‘arduino\version 2.x.x\platform.txt’.
Configure the Tasmota firmware
Connect your ESP8266 development board to your computer. In the Arduino IDE, open the file ‘sonoff.ino‘ from your sketchbook ‘sonoff’ folder.
Open the tab ‘my_user_config.h‘ and change the settings for network and WiFi:
// -- Wifi ---------------------------------------- #define WIFI_IP_ADDRESS "0.0.0.0" // [IpAddress1] Set to 0.0.0.0 for using DHCP or enter a static IP address #define WIFI_GATEWAY "192.168.10.1" // [IpAddress2] If not using DHCP set Gateway IP address #define WIFI_SUBNETMASK "255.255.255.0" // [IpAddress3] If not using DHCP set Network mask #define WIFI_DNS "192.168.10.1" // [IpAddress4] If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY) #define STA_SSID1 "yourwifinetwork" // [Ssid1] Wifi SSID #define STA_PASS1 "yourwifipassword" // [Password1] Wifi password #define STA_SSID2 "" // [Ssid2] Optional alternate AP Wifi SSID #define STA_PASS2 "" // [Password2] Optional alternate AP Wifi password #define WIFI_CONFIG_TOOL WIFI_MANAGER // [WifiConfig] Default tool if wifi fails to connect // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL) #define WIFI_CONFIG_NO_SSID WIFI_MANAGER // Default tool if wifi fails to connect and no SSID is configured
Enter the IP address or set it to “0.0.0.0” if you’re using DHCP.
You can give your device a unique project name, so it will be easier to recognize between the other devices in your network:
// -- Project ------------------------------------- #define PROJECT "Sonoff" // PROJECT is used as the default topic delimiter
I will change the device name later, in the Tasmota web interface.
Also, change the ‘CFG_HOLDER’ parameter to a new (random) value every time you change and upload the settings to the board.
// -- Master parameter control -------------------- #define CFG_HOLDER 234 // [Reset 1] Change this value (max 32000) to load SECTION1 configuration parameters to flash
If you do not change the parameter, the new settings will not take effect. The ‘CFG_HOLDER’ can be found under ‘Master parameter control’.
ESP8266 NodeMCU board settings
Before you compile and upload the firmware. first check the following board settings under the “Tools” menu in the Arduino IDE:
- Board: “Generic ESP8266 Module”
- Flash Size: 1M (no SPIFFS)
- Flash Mode: “DOUT”
- lwIP Variant: “v2 Higher Bandwidth (no features)”
- VTables: “Flash”
- Exceptions: “Disabled”
- Erase Flash: “Only Sketch”
Do not forget to select the right USB/COM-port.


Compile and upload the sketch to your development board.
Configuring Tasmota on the ESP8266 NodeMCU
After your ESP8266 has been flashed and restarted, look for it’s IP address in your network. If you don’t know where to find it, you should probably check your router first.
Enter the IP address of the ESP8266 in your browser. The Tasmota main menu will appear.


Once the Tasmota web interface appears, we need to change the module type from the default “Sonoff Basic” to “Generic”. Go to “Configuration” and choose “Configure Module”. Select “Generic” for Module Type and Save.


The module will restart. Next, we will configure the GPIOs of the ESP8266 board.
Setting the ESP8266 GPIO options
To test Tasmota on the ESP8266, we will first configure the built-in LED on the NodeMCU board to be turned on and off by using the web interface. On this version of the board, the LED is on GPIO16 (D0).
In the Tasmota interface, go to Configuration and then Configure Module. Make sure all the GPIOs are set to “None”. Then set GPIO16 to “Relay1i“. Hit “Save” and return to the Main Menu.


At the top of the Main Menu, you will see a button labeled “Toggle”. Pressing the button will now toggle the built-in LED on the NodeMCU board. This confirms that Tasmota is installed correctly and working as intended.


More LEDs, more fun
While we are at it, let’s add some more controls for LEDs. The NodeMCU board actually has 2 built-in LEDs: the second one is on the ESP-12 module itself. This LED is assigned to GPIO2 (D4). So in the Tasmota configuration, set GPIO2 to “Relay2i“.
After that, we will add an external LED on GPIO4 (D2). The anode (positive, long leg) is connected to the D2 pin via a 470-ohm resistor. The cathode (negative, short leg) is connected to the GND pin via a jumper cable. See the picture below.


Next, in the Module Configuration, we set the GPIO4 to ‘Relay3‘. The configuration should look like the picture below.


On the main page, three buttons now let you toggle the two built-in as well as the external LED.


Also, notice that in the above two pictures I changed the device name from “Sonoff” to “ESP8266” (Configuration > Configure other > Friendly Name 1).
Now, by using the toggle buttons in the Tasmota main menu, you can turn on or off the three LEDs.


Next steps
Now you know how to toggle the GPIOs, you can use Tasmota to toggle relais on the NodeMCU, or use the GPIOs to read values from buttons or sensors. On its own, this is already a very useful application of the firmware.
In the next blog post, we will see how we can use the MQTT functionality of Tasmota. This will let the ESP8288 communicate with applications like Node-Red or Home Assistant, and will turn the NodeMCU into a very versatile DIY device for home automation projects.
I found this to be very useful and informative. Thanks Very much for posting.
Hey – With the new version of Tasmota released, this is now a little out of date because it’s not referred to as Sonof anymore.
Agree with Jay, it appears the folder is now called tasmota
did you post the next blog related to the same topic? (connecting mqtt with tasmota)
Followed all the directions and got the the part of setting the board parameters. When I select generic ESP8266 module, no option is listed for 1M (no spiffs). Any idea what I am doing wrong? thanks in advance.
After several attempts, including one that caused my Mac to crash and forced a complete recovery of the disk, I’ve just succeeded in loading the Tasmota SW on a NodeMCU Lua Lolin V3with ESP8266 12E.
I had to choose the specific module and not the generic ESP8266 (one of the unsuccessful attempts ) In any case I believe the instructions are a bit out of date as 1M (no SPIFFS) option doesn’t exist or it’s differently specified.
What worked for me is:
Flash Size: “4MB(FS:2MB OTA:1019KB)”
Unfortunately I cannot (or I’m not capable to) post the screenshot of the Tools setting.
A funny thing I’ve encountered is that the Toggle control seems to have an inverse logic. It doesn’t show the status of the LED but it shows the action you can carry one. i.e. If the LED is off you see ON and viceversa
Hi
Very interesting article. I downloaded the tasmota and performed all the instructions up till
Connect your ESP8266 development board to your computer. In the Arduino IDE, open the file ‘sonoff.ino‘ from your sketchbook ‘sonoff’ folder.
Open the tab ‘my_user_config.h‘ and change the settings for network and WiFi:
I cant find “sonoff” folder I did find a sonoff.ino file at location C:\Users\meir\Tasmota-development\Tasmota-development\lib\esp-knx-ip-0.5.2\examples\sonoff but the file is nothing like the one in the article??
Regards
Meir
I am geting an error UdpListener.h no such file or directory. Searching on the net didnt yield any result. Could you kindly let me know where I have done a mistake
I am trying to compile Tasmota in Arduino IDE and getting an error: EscapeJSONString was not declared. Can you help me?
Use Tasmotiser, does the flashing and software for you easy.
This website is out of date.