echo '' ;

ESP8266 Arduino-Core Interface – LED

LEDs have two legs, an anode (longer leg, positive) and a cathode (shorter leg, negative). Connect the anode to a current-limiting resistor and the other end of the resistor to the microcontroller’s output pin. Connect the cathode directly to the microcontroller’s ground (GND) pin. Interfacing an LED with an ESP8266 using the Arduino core is quite similar to the basic Arduino example. The ESP8266 Arduino core provides a convenient platform for programming ESP8266 modules with the Arduino IDE. Here’s a simple example of “interfacing an LED with an ESP8266 using an Arduino-core”ESP8266 Arduino-Core Interface – LED”:

ESP8266 Arduino Blink In-Build Blue LED

The ESP8266 module has a built-in blue LED. We can create a simple program to blink this blue LED. If you are a beginner, you can start learning from this tutorial, similar to a ‘Hello World’ program. It’s very simple. The blue LED is connected to the GPIO-10 pin, so we set GPIO-10 as an output and write the blink code using the Arduino core.

 Required Hardware Components

  • 1 x ESP8266 Any Module( Used Ai-Thingers ESP-12F)
  • 1 x ESP8266 Programmer (FDTI chip or use your Arduino board)

Required Software and Tools

  • Arduino IDE with ESP8266 Core

Code

/*
http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Arduino-Core
Tested By : Arun(20170219)
Example Name : AEW_LED-Blink.ino

ESP8266 Blink by Simon Peter
Blink the blue LED on the ESP-01 module
This example code is in the public domain

The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)

Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
}

ESP8266 Arduino LED-Fade

  • Required Hardware and ESP8266 with Programmer (or) NodeMCU Dev Kit
  • Required Software Tools are Arduino IDE with ESP8266 Core

Code

/*
http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Ardiuno-core/
Tested By : Arun(20170219)
Example Name : AEW_LED-Fade.ino
*/
/*
Fade

This example shows how to fade an LED on pin 9
using the analogWrite() function.

The analogWrite() function uses PWM, so if
you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

This example code is in the public domain.
*/

int led = LED_BUILTIN; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
// declare pin LED_BUILTIN to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin LED_BUILTIN:
analogWrite(led, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

ESP8266 Arduino LED Blink Without Delay function

Code

/*
ESP8266 Arduino-Core Interface – Button
Tested By : Arun(20170219) Example Name : AEW_LED-BlinkWithoutDelay.ino ESP8266 BlinkWithoutDelay by Simon Peter Blink the blue LED on the ESP-01 module Based on the Arduino Blink without Delay example This example code is in the public domain The blue LED on the ESP-01 module is connected to GPIO1 (which is also the TXD pin; so we cannot use Serial.print() at the same time) Note that this sketch uses LED_BUILTIN to find the pin with the internal LED */ int ledState = LOW; unsigned long previousMillis = 0; const long interval = 1000; void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= interval) { previousMillis = currentMillis; if (ledState == LOW) ledState = HIGH; // Note that this switches the LED *off* else ledState = LOW; // Note that this switches the LED *on* digitalWrite(LED_BUILTIN, ledState); } }

Use of “LED Blink Without Delay

The “LED Blink Without Delay” technique is commonly used in microcontroller programming to create responsive and non-blocking code. The traditional way of blinking an LED using delay() pauses the entire program, making it difficult to perform other tasks simultaneously. With “LED Blink Without Delay,” you can blink the LED while allowing your program to continue running other tasks.

Here are a few scenarios where this technique is beneficial:

  1. Responsive User Interface: If you are developing a project with a user interface, using “LED Blink Without Delay” ensures that your interface remains responsive to user inputs, even while the LED is blinking.
  2. Multitasking: In more complex projects, you might have multiple tasks or processes to handle simultaneously. Using this technique allows you to manage different tasks independently without one task blocking the execution of others.
  3. Sensor Readings: If your project involves reading sensor data, you can perform sensor readings without waiting for the LED to finish blinking. This is crucial for real-time data acquisition.

NEXT

Arduino-Core Get Start (Soon)
ESP32 Arduino Core Interface
ArduinoCore Interface Basics
ArduinoCore Interface WiFi
ArduinoCore Interface – LED
ArduinoCore Interface ADC
ArduinoCore Interface DS18B20
ESP32 Arduino Core Projects
ArduinoCore Project – WebServer
Others
Arduino-Core Sitemap
Arduino-Core All Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading