echo '' ;

Archives

8051 Interface – LED

In this 8051 Interface LED tutorial, you will learn how to implement a “Hello World” LED Blinking project in Keil for a microcontroller. Additionally, we have chosen the AT89S51 microcontroller (although you can select any other microcontroller supported by Keil) for demonstration purposes. This project is straightforward and can be easily followed by the steps outlined below.

Read more: 8051 Interface – LED

Light Emitting Diodes (LEDs) are fundamental and widely used electronic components for displaying digital signal states. When current flows through an LED, it emits light. However, excessive current can damage it; therefore, a current-limiting resistor is necessary. Commonly used resistors for this purpose include 220, 470, and 1K ohms. Depending on the desired brightness, any of these resistors can be utilized. Let’s begin by blinking LEDs; subsequently, we can proceed to generate various patterns using the available LEDs.

An essential aspect of any controller is the number of General Purpose Input/Output (GPIO) pins available for connecting peripherals. The 8051 microcontroller features 32 GPIOs organized into four ports, namely P0 to P3.

Required software

Required components and Programmer

  • 1x AT89S51 Controller
  • 1x 4Mhz Crystal
  • 2x 22pf capacitor
  • 1x LED 5v
  • ISP AVR USB programmer

Circuit Diagram

 C code

// http://esp8266iot.blogspot.in/
// http://aruneworld.blogspot.com/
// Tested By 	: Arun(20170227)
// Example Name : AEW_Blink_LED.lua

// Program to blink an LED at Port pin P1.0 (physical pin 1 of IC)

#include<reg52.h>  // special function register declarations for 89s52                

#include<stdio.h>  // prototype declarations for I/O functions

sbit LED = P1^1;    // defining pin P1^0 as LED

void delay(void) ;  //delay function prototype declaration

void main (void)
   
{
    LED = 0 ;              // Make LED pin as Output
    while(1)                //indefinite loop
    {
       LED = 0;           // LED Off
       delay();
       LED = 1;          // LED ON 
       delay();
    }
}

void delay(void)
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

C Code Explanation

This table breaks down each line of the code along with its explanation to provide a clear understanding of the functionality of each part of the program.

Line No.CodeExplanation
1-5// http://esp8266iot.blogspot.in/ // http://aruneworld.blogspot.com/ // Tested By : Arun(20170227) // Example Name : AEW_Blink_LED.luaComments providing information about the code, including source references, testing details, and example name.
7#include<reg52.h>Includes the header file reg52.h, which contains special function register declarations for the AT89S52 microcontroller.
9#include<stdio.h>Includes the standard I/O header file stdio.h, although it seems unnecessary in this code since there are no standard I/O functions used.
11sbit LED = P1^1;Declares a bit-specific variable named LED, representing pin P1.1. This syntax is specific to the 8051 family of microcontrollers.
13-24void delay(void) ;Function prototype declaration for delay().
26-35void main (void)Main function declaration.
28LED = 0 ;Configures the LED pin as an output by setting it to 0.
29-33while(1)Initiates an infinite loop to ensure the LED continues blinking indefinitely.
30LED = 0;Turns off the LED.
31delay();Calls the delay() function to introduce a delay.
32LED = 1;Turns on the LED.
33delay();Calls the delay() function again to introduce another delay.
37-47void delay(void)Function definition for delay().
39-46int j; int i; for(i=0;i<10;i++) { for(j=0;j<10000;j++) { } }Nested loops to generate a time delay. The outer loop iterates 10 times, and the inner loop iterates 10,000 times, creating an approximate delay.

Assembly Code

      ORG 0000H
0000| 	LJMP 082BH 
      ORG 0800H
0800| 	CLR A
0801| 	MOV R7,A
0802| 	MOV R6,A
0803| 	CLR A
0804| 	MOV R5,A
0805| 	MOV R4,A
0806| 	INC R5
0807| 	CJNE R5,#00H,01H
080A| 	INC R4
080B| 	CJNE R4,#27H,0F8H
080E| 	CJNE R5,#10H,0F5H
0811| 	INC R7
0812| 	CJNE R7,#00H,01H
0815| 	INC R6
0816| 	MOV A,R7
0817| 	XRL A,#0AH
0819| 	ORL A,R6
081A| 	JNZ 0E7H
081C| 	RET
081D| 	CLR 91H
081F| 	CLR 91H
0821| 	LCALL 0800H
0824| 	SETB 91H
0826| 	LCALL 0800H
0829| 	SJMP 0F4H
082B| 	MOV R0,#7FH
082D| 	CLR A
082E| 	MOV @R0,A
082F| 	DJNZ R0,0FDH
0831| 	MOV 81H,#07H
0834| 	LJMP 081DH
      	END

Assembly Code Explanations

These tables provide a clear separation of the instructions, making it easier to read and understand each part of the code.

Table 1: Instructions from Address 0000 to 082B

AddressCodeMnemonicDescription
0000LJMP 082BHLJMPLong Jump to address 082Bh
0800CLR ACLRClear Accumulator (A)
0801MOV R7,AMOVMove Accumulator (A) to Register 7 (R7)
0802MOV R6,AMOVMove Accumulator (A) to Register 6 (R6)
0803CLR ACLRClear Accumulator (A)
0804MOV R5,AMOVMove Accumulator (A) to Register 5 (R5)
0805MOV R4,AMOVMove Accumulator (A) to Register 4 (R4)
0806INC R5INCIncrement Register 5 (R5)
0807CJNE R5,#00H,01HCJNECompare and Jump if Not Equal; Compare R5 to 00H, if not equal, jump to address 01H
080AINC R4INCIncrement Register 4 (R4)
080BCJNE R4,#27H,0F8HCJNECompare and Jump if Not Equal; Compare R4 to 27H, if not equal, jump to address 0F8H
080ECJNE R5,#10H,0F5HCJNECompare and Jump if Not Equal; Compare R5 to 10H, if not equal, jump to address 0F5H
0811INC R7INCIncrement Register 7 (R7)
0812CJNE R7,#00H,01HCJNECompare and Jump if Not Equal; Compare R7 to 00H, if not equal, jump to address 01H
0815INC R6INCIncrement Register 6 (R6)
0816MOV A,R7MOVMove Register 7 (R7) to Accumulator (A)
0817XRL A,#0AHXRLExclusive OR with Immediate; Perform exclusive OR operation between A and 0AH
0819ORL A,R6ORLLogical OR between Accumulator (A) and Register 6 (R6)
081AJNZ 0E7HJNZJump if Not Zero; Jump to address 0E7H if the result of the previous operation is not zero
081CRETRETReturn from Subroutine

Table 2: Instructions from Address 081D to 0834

AddressCodeMnemonicDescription
081DCLR 91HCLRClear the content of memory address 91H
081FCLR 91HCLRClear the content of memory address 91H
0821LCALL 0800HLCALLLong Call to subroutine at address 0800H
0824SETB 91HSETBSet the content of memory address 91H
0826LCALL 0800HLCALLLong Call to subroutine at address 0800H
0829SJMP 0F4HSJMPShort Jump to address 0F4H
082BMOV R0,#7FHMOVMove Immediate to Register; Move the value 7FH to Register 0 (R0)
082DCLR ACLRClear Accumulator (A)
082EMOV @R0,AMOVMove Accumulator (A) to the memory location pointed by Register 0 (R0)
082FDJNZ R0,0FDHDJNZDecrement and Jump if Not Zero; Decrement Register 0 (R0) and if the result is not zero, jump to address 0FDH
0831MOV 81H,#07HMOVMove Immediate to Register; Move the value 07H to the memory location pointed by Register 1 (81H)
0834LJMP 081DHLJMPLong Jump to address 081DH

NEXT

8051 – Introduction
8051 – Program Methods
8051 – Flash HEX into 8051
8051 – USB ISP Programmer
8051 – Simulators
8051 Interface
8051 Interface – LED
8051 Interface – LCD
8051 Interface – 7 Segment
8051 Interface – Keypad
8051 Interface – Servo
8051 Protocol Interface
8051 – UART Bit banking
8051 – I2C Bit banking (Add Soon)
8051 Tutorials
8051 – 10Khz Square Wave
Others
8051 – Interview Questions

Embedded Interface – RGB LED

PWM -Pulse width Modulation

RGB LED

 

Type of RGB LED


 

Next Topic

Embedded Interface 7 Segment (Add Soon)
Embedded Interface ADC (Add Soon)
Embedded Interface Button (Add Soon)
Embedded Interface EEPROM (Add Soon)
Embedded Interface LCD (Add Soon)
Embedded Interface LCD HD44780 (Add Soon)
Embedded Interface LED
Embedded Interface MCP23017
Embedded Interface Motor (Add Soon)
Embedded Interface PCF8574 and PCF8574A
Embedded Interface RTC (Add Soon)
Embedded Interface Switch
Embedded Interface Touch Kypad
Embedded Interface RGB LED (Add Soon)

Arduino Interface – LED

This article is a continuation of the series on “Arduino Interface – LED” and carries the discussion on Turn ON/OFF, and blinking of LED in the Arduino Environment.

  • LED (light-emitting diode): LED is a simple diode that emits light in a forward bias
  • Arduino: is an open-source, board that has a Microchip ATmega328P microcontroller on it.

Pre-Request

  • PC
  • Arduino IDE setup or web-based IDE

Components Required

  • LED – 1 Nos,
  • Resistor, 220 Ohm – 1Nos
  • Breadboard (Optional: If required)
  • Arduino UNO
  • Jumper wires

Turn On/Off LED

The program simply turns ON and OFF LED with some delay between them.

  • For Turn OFF LED – Set digital pin Low digitalWrite(LED_BUILTIN, LOW);
  • For Turn ON LED – Set digital pin high digitalWrite(LED_BUILTIN, HIGH);

 

Read more… →

ESP8266 Mongoose-OS Interface – LED

To turn on the led you need to load the gpio_api.js file.


LED Turn ON/OFF

Note : This below example was tested mongoose os with java script app demo-js in ESP8266 NodeMCU Dev Board(ESP-12E)

  • This below example turn on the LED GPIO-4 (NodeMCU Dev Board digital pin 2)
  • Set the GPIO pin mode as OUPUT uisng gpio set mode function ex: GPIO.set_mode(led, GPIO.MODE_OUTPUT)
  • Turn off the LED call the gpio write function with low-0 ex : GPIO.write(led, 0) .
  • Turn on the LED call the gpio write function with low-1 ex : GPIO.write(led, 1) .

Code

load('api_gpio.js');
 
// Configure LED
let led = 4; //lde pin GPIO04
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
GPIO.write(led,1);

 


LED turn ON/OFF using button

  • Use Boot button(GPIO-0)
  • The example code used blink in-build LED, It’s connected to GPIO-10.
  • You can change any other pin Ex : led = 4; // Get LED GPIO-04 pin; 
  • Note : Code 1 and Two are same application and functionality. Main difference is calling function.

Code 1 :

  • Used GPIO-0 pin (Boot button in NodeMCU Dev Board), as interrupt and used Button interrupt handler function.
// http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Mongoose-os/
// Tested By  : Arun(20170430)
// Example Name : AEW_LED-Blink_Using_Button.js
// Firmware  : Mongoose OS for ESP32
//*******************************//
// This example demonstrates how to react on a button press by toggling LED.
//
// To try this example,
//   1. Download <code>{{EJS0}}</code> tool from https://mongoose-os.com/software.html
//   2. Run <code>{{EJS1}}</code> tool and install Mongoose OS
//   3. In the UI, navigate to the <code>{{EJS2}}</code> tab and load this example

// Load Mongoose OS API
load('api_gpio.js');

// Configure LED
let led = ffi('int get_led_gpio_pin()')();  // Get built-in LED GPIO pin
GPIO.set_mode(led, GPIO.MODE_OUTPUT);

let pin = 0;   // GPIO 0 is typically a 'Flash' button
GPIO.set_button_handler(pin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function(x) {
  let value = GPIO.toggle(led);
  print('Button press, pin:', x, 'LED pin:', led, ' Value: ', value);
}, true);

print('Flash button is configured on GPIO pin ', pin);
print('Press the flash button now!');

 

Code 2:

  • In this code i was used GPIO-0 pin (Boot button in NodeMCU dev Kit) as interrupt and used interrupt handler function.
  • If your using interruot handler function then you need o enable the interrupt using GPIO.enable_int(pin)  function
load('api_gpio.js');

GPIO.set_mode(4, 1);
//GPIO.write(10, 0);


GPIO.set_int_handler(0, GPIO.INT_EDGE_NEG, function(pin) {
   print('Pin', 0, 'got interrupt');
   GPIO.toggle(4);
   
}, null);
GPIO.enable_int(0);

 

ESP8266 NodeMCU Interface – LED

LED ON/OFF

Note : Assume the pin GPIO-5 is a LED (NodeMCU pin map is 1)

  • Set LED Mode
    • Set LED pin (gpio-5) as output using gpio.mode(pin, mode [, pullup])  function.
    • Example :  gpio.mode(1, gpio.OUTPUT)
  • Turn LED ON
    • Set LED pin (gpio-5) HIGH using gpio.write(pin, level)  function.
    • Example : gpio.write(1, gpio.HIGH)  or gpio.write(1, 1)
  • Turn LED  OFF
    • Set LED pin (gpio-5) Low using gpio.write(pin, level)  function.
    • Example : gpio.write(1, gpio.LOW) or gpio.write(1,0)

 


LED Blink Using Timer

  • Required NodeMCU Modules (Firmware) GPIO Module, Timer Module
  • Required Hardware ESP8266 with Programmer (or)  NodeMCU Dev Kit, LED- 3v3 or 5v,
  • Required Software Tools ESPlorer IDE Tool

ESP8266 with LED Connection Diagram

  • Will Add Soon

NodeMCU Lua code

-- http://www.ArunEworld.com/embedded/ESPressif/ESP8266/ESP82266_NodeMCU
--[[ Required NodeMCU Modules
 Timer Module
 GPIO Module
]]--

LED_Pin = 1 -- GPIO-5
LED_Blink_Time = 1000 -- ms
gpio.mode(LED_Pin, gpio.OUTPUT)
local function Blink()
 if ( 0 == gpio.read(LED_Pin)) then 
  gpio.write(LED_Pin, gpio.HIGH)
 elseif( 1 == gpio.read(LED_Pin)) then 
  gpio.write(LED_Pin, gpio.LOW)
 end 
end

tmr.alarm(0,LED_Blink_Time,1,function() Blink() end)

Follow steps

  • Connect the circuit as per the connection diagram
  • Save the above code as “AEW_LED-Blink.lua”
  • Open ESPlorer and upload the file “AEW_LED-Blink.lua”
  • Run the file  [ dofile(“AEW_LED-Blink.lua”) ]
  • Done.!(LED will Blink based on blink time)

LED Blink uisng While loop and Timer delay function

  • Use
    -- http://www.ArunEworld.com/embedded/ESPressif/ESP8266/ESP82266_NodeMCU 
    --[[ Required NodeMCU Modules Timer Module GPIO Module ]]--
    LED_Pin = 1 -- GPIO-5
    LED_Blink_Time = 1000 -- ms
    gpio.mode(LED_Pin, gpio.OUTPUT)
    
    while true do
        tmr.delay(1000000)
        if ( 0 == gpio.read(LED_Pin)) then
            gpio.write(LED_Pin, gpio.HIGH) 
        elseif( 1 == gpio.read(LED_Pin)) then
            gpio.write(LED_Pin, gpio.LOW)
        end
    end
    

     


LED Fade using PWM

  • Use this code
    pin = 1
    ------ PWM setup --------------
    pwm.setup(pin, 999, 512)    -- pwm.setup(pin, clock, duty) | set pin index 1 as pwm output, frequency is 100Hz, duty cycle is half.
    
    pwm.start(pin)          -- pwm.start(pin)
    duty = 1000
    
    for i=1000,0,-1 do
     --print(i)
     duty = i
     pwm.setduty(pin, duty)         -- pwm.setduty(pin, duty)
     tmr.delay(1000)
    end
    

     


 

 


Next :

Previous :


 

Embedded Interface – LED

LED (Light Emitted Diode)

Symbol

How to Identify the LED’s Positive and Negative Leads ?

  • Long lead is positive(+) and small lead is negative(-)
  • Round circle lead is positive(+) and flat lead is negative(-)

LED Chemical Substance

Summary of LED’s Colors and Common Chemistries

ColorWavelengthMaterials
   
Amber605-620 nmGallium arsenide phosphide, Aluminum gallium indium phosphide
Blue430-505 nmIInGaN (Indium Gallium Nitride), Gallium nitride, Silicon carbide, Sapphire, Zinc selenide
Green550-570 nmAluminum gallium phosphide, Gallium nitride
Infra-Red850-940 nmGallium arsenide, AL GaAs (Aluminum Gallium Arsenide)
Red630-660 nmAL GaAs (Aluminum Gallium Arsenide), Gallium arsenide phosphide, Gallium phosphide
Ultraviolet370-400 nmIndium gallium nitride, Aluminum gallium nitride
Violet410-420nm 
Yellow585-595 nmAluminum gallium phosphide, Gallium arsenide phosphide, Gallium phosphide

Light wave length

WaveLenthLED APPLICATION
410nm-420nm(violet)Skin therapy
430nm-470nm(blue)Dental curing instrument
470nm(blue)White LED’s using phosphor, blue for RGB white
520nm-530nm(green)Green traffic signal lights, amber for RGBA white lights
580nm-590nm(amber)Red signal lights, red for RGBA white lights
630nm-640nm(red)Blood oximetry
660nm(deep red)Skin therapy
680nm(deep red)Night vision illuminators and beacons for use with night vision goggles or CCD’S
800nm-850nm(near IR)Photo electric controls
940nm(near IR)Convert illumination CCD based systems

Reference  : http://www.goldwynled.com/knowledge-bank/leds-basics


GLOW LEDs

LEDs ON

LEDs OFF

LEDs Blink

Application

  • Status Indicator
  • WiFi Router Status Indicator (Blink LEDs-Internet Status)
  • Charge level Indication in mobile power-bank [Blink LEDs – Single RGB LEDs or Multiple Color LEDs)
  • Bike Automation
    • Bike Turn Indicator (LED Blink – while turned)
    • Bike Side stand indicator (LED Glow -if Side stand is not took)
  • Car Automation
    • Car Turn Indicator (LED Blink – while turned)
    • Car Door Status indicator(LED Glow -if Door is not close or opened)

LED Examples

  • ON/OFF
  • Blink using the Delay Function
  • Blink using the Timer Function
  • Status Indicator(Using condition Check)Button

ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice

What is Cayenne MyDevice?

myDevices Cayenne allows you to quickly design, prototype, and visualize IoT solutions. You can use Cayenne as a tool to visualize real-time and historical data, sent over to The Things Network. Let’s discuss “ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice

Cayenne is a platform for building IoT (Internet of Things) projects that provides tools for creating dashboards, monitoring devices, and controlling connected devices remotely. The Cayenne platform supports various microcontrollers and single-board computers, including the ESP8266, through the use of Cayenne MQTT or Cayenne MQTT API.

Read more… →

ESP32 ArduinoCore Project – WiFi Web Server LED Blink

This article is a continuation of the series on the ESP32 ArduinoCore Project using the ESP32 Dev board and carries the discussion on WiFi Web Server LED Blink. This series aims to provide easy and practical examples that anyone can understand. In our previous tutorial, we saw how to use the inbuilt code to toggle the onboard LED. This is the ESP32 LED Blinky in Wifi Webserver In this tutorial

A simple web server that lets you blink an LED via the web.

Wifi Web Server Info

  • This code will print the IP address of your WiFi Module (ESP32) (once connected) to the Serial monitor.
  • From that IP Address, you can open that address in a web browser to turn on and off the LED on pin-5.
  • If the IP address of your ESP32 is 192.168.1.143:
    • http://192.168.1.143/H turns the LED on
    • http://192.168.1.143/L turns it off
  • This example is written for a network using WPA encryption.
  • For WEP or WPA, change the Wifi.begin() call accordingly.

Read more… →