echo '' ;

IOT Dashboard – Grafana

 

 

 

 


FAQ

How Install the grafana in windows

Notes : We tested and installed on 2018 April 17th

 

Download Grafana

Configure Grafana

  • Go to conf  directory and copy the defaults.ini  file and rename the defaults – Copy.ini  file as custom.ini .
  • Edit the custom.ini  file and change the default grafana port is 3000  instead of 8080 . (Note:- Mostly at line 35)

Install Grafana using NSSM

  • Download the latest release of NSSM software and extract anywhere in your machine. Copy the nssm.exe  file and paste in c:\  Directory (Installed : nssm 2.24)
  • Run the command  c:\>nssm install Grafana  from Administrator command prompt.
  • It will Pop-Up the NSSM Service Installer

  • Choose the Grafana path in the application tab (Ex: C:\grafana-5.0.4\bin\grafana-server.exe )
  • The Startup directory automatically added when selscted the correct path (Ex: C:\grafana-5.0.4\bin )
  • Set the Display Name as Grafana in Details tab (Ex : Grafana )
  • Set startup type: as Automatic (Delayed Start)  in Details tab
  • Log on tab choose Local System account  if you don’t have grafana credentials. else you have then choose This account  and enter the mail id  and set password  then confirm  again.
  • Everything Well now click the Install service button then you can see the status of installation in Command prompt like below
c:\>nssm install Grafana
Failed to look up the SID for username info@aruneworld.com!
LsaLookupNames(): No mapping between account names and security IDs was done.

Failed to look up the SID for username info@aruneworld.com!
LsaLookupNames(): No mapping between account names and security IDs was done.

Failed to look up the SID for username info@aruneworld.com!
LsaLookupNames(): No mapping between account names and security IDs was done.

Failed to look up the SID for username info@aruneworld.com!
LsaLookupNames(): No mapping between account names and security IDs was done.

Failed to look up the SID for username aruneworld!
LsaLookupNames(): No mapping between account names and security IDs was done.

Failed to look up the SID for username aruneworld!
LsaLookupNames(): No mapping between account names and security IDs was done.

Service "Grafana" installed successfully!

 

Run the Grafana

  • Open windows services in command prompt :- c:\>services.msc
  • RUn the Service Grafana .(Right Click and start Service)
  • Go to any browser and hit the details http://localhost:8080/  .
  • You can see the Grafana login page, enter the credentials username : admin  and password : admin

  • Done

Reference

 


Grafana We host It

Note : This free service only for single user and up-to 5 dashboards with SSL. Tested on 2018 April 17 using Mozilla Firefox Browser.

  • Go to https://grafana.com/get
  • Pop up windows shows if your not login or sign up
  • Log in after select Plan as free
  • Choose your preferred URL and make sure its available Ex : https://adalurarun.grafana.net
  • Select I agree to the terms of service & MSA
  • Click Create Hosted Instance
  • Then Go to your URL then wait a minutes (Ex: https://adalurarun.grafana.net ), It will redirect to login page.
  • Once you logged on you can see the dashboard

 


FAQ

  • How to upload the data into grafana?

 

Embedded Sensor – Smoke Sensor

A smoke sensor is a device that senses smoke, typically as an indicator of fire. Commercial and residential security devices issue a signal to a fire alarm control panel as part of a fire alarm system , while household detectors, known as alarms, generally issue a local audible or visual alarm from the detector itself. The Analog Smoke/LPG/CO  G as Sensor (MQ2) module utilizes an MQ  -2 as the sensitive component and has a protection resistor and an adjustable resistor on board. The MQ-2 gas sensor is sensitive to LPG, i-butane, propane, methane, alcohol,Hydrogen and . It could be used in gas leakage detecting equipments in family and industry. The resistance of the sensitive component changes as the concentration of the target gas changes.

About

Smoke sensors, also known as smoke detectors or smoke alarms, are devices designed to detect the presence of smoke or combustion products in the air. These sensors are crucial components of fire detection and safety systems, alerting occupants of potential fire hazards in residential, commercial, and industrial settings.

There are several types of smoke sensors, including ionization smoke detectors, photoelectric smoke detectors, and combination smoke detectors. Ionization smoke detectors use a small amount of radioactive material to ionize the air between two electrically charged plates. When smoke enters the chamber, it disrupts the ionization process, triggering the alarm. Photoelectric smoke detectors, on the other hand, use a light source and a photosensitive receiver. When smoke particles enter the chamber, they scatter the light, which triggers the alarm. Combination smoke detectors combine ionization and photoelectric technologies for enhanced fire detection capabilities.

Overall, smoke sensors play a critical role in fire prevention and safety, providing early detection of smoke and potentially saving lives and property.

Read more… →

Embedded Sensor – Proximity

A proximity sensor is a type of sensor that detects the presence or absence of an object or obstacle in close proximity to it without physical contact. It works by emitting an electromagnetic field or beam of electromagnetic radiation, and then detecting changes in the field or radiation caused by the presence or absence of an object. Proximity sensors are commonly used in various applications such as automatic door openers, touchless faucets, mobile devices for screen activation, and industrial automation for object detection.

Read more: Embedded Sensor – Proximity

Real-Time Usage

On Mobile

           This sensor installed on the front of an iPhone 5 next to the earpiece automatically turns off the touchscreen when the sensor comes within a predefined range of an object (such as a human ear) when using the handset.

On Parking Sensor

Ultrasonic parking sensor: Source

Parking sensor on a fender

Type of Proximity

  • Capacitive Proximity Sensors
  • Inductive Proximity Sensors
  • Magnetic Proximity Sensors
  • Optical Type
    • Photoelectric
    • PhotoCell
    • Infrared Proximity Sensor (Passive Thermal)
  • Ultrasonic Type
  • Hall Effect Type

Proximity Sensor Application

  • Parking sensors, systems mounted on car bumpers that sense distance to nearby cars for parking
  • Ground proximity warning system for aviation safety
  • Vibration measurements of rotating shafts in machinery
  • Top dead centre (TDC)/camshaft sensor in reciprocating engines.
  • Sheet break sensing in paper machine.
  • Anti-aircraft warfare
  • Roller coasters
  • Conveyor systems
  • Beverage and food can making lines
  • Improvised Explosive Devices or IEDs
  • Mobile devices
    • Touch screens that come in close proximity to the face
    • Attenuating radio power in close proximity to the body, in order to reduce radiation exposure
  • Automatic faucets

Other Proximity Sensor

PRD-12-8DP Inductive Type

LJ12A3-4-Z-BY-Inductive-Proximity-Senso

  • Types NPN
  • Type : PNP
    • Data Sheet : Inductive Proximity Sensor Detection Switch PNP Model: LJ12A3-4-Z/BY
    • Specification :
      • A component widely used in automatic control industry for detecting, controlling, and non-contact switching When proximity switch is close to some target object, it will send out control signal.
      • Model: LJ12A3-4-Z/AY
      • Output Type: PNP NC(Normally Close)
      • Detecting Distance: 4mm±10%
      • Theory: Inductive Sensor
      • Wire Type: 3 Wire Type (Brown, Blue, Black)
      • Switch Appearance Type: Cylinder Type, Aluminum Shell
      • Supply Voltage: DC 6-36V
      • Current: 200A
      • Detect Object: Iron
      • Diameter: 12mm
      • Cable Length: 1M/3.3Ft
      • 1 x Inductive Proximity Sensor Switch
    • Price Approximately :340rs (India)

Embedded Sensor – NTC Temperature

This tutorial is about NTC Temperature sensor. Thermistors are temperature-sensing elements made of semiconductor material that have been sintered to display large changes in resistance in proportion to small changes in temperature. This resistance can be measured by using a small and measured direct current, or dc, passed through the thermistor in order to measure the voltage drop produced. These solid state temperature sensors actually act like electrical resistors that are temperature sensitive. That is where the name, a clear combination of the words thermal and resistor, comes from. Ametherm specializes in NTC, or negative temperature coefficient, thermistors.

NTC Temparature sensor

NTC (Negative Temperature Coefficient) thermistors, also known as NTC temperature sensors, measure temperature. They consist of semiconductor materials with a resistance that decreases as temperature increases. NTC thermistors exhibit a nonlinear resistance-temperature relationship, with resistance decreasing rapidly as temperature rises and vice versa.

These sensors are widely used in various applications due to their simplicity, accuracy, and low cost. Some common applications of NTC temperature sensors include:

  1. Temperature Sensing: NTC thermistors commonly measure temperature in electronic circuits, appliances, automotive systems, and industrial processes.
  2. Temperature Compensation: They stabilize the performance of electronic devices and components over a wide temperature range in temperature compensation circuits.
  3. HVAC (Heating, Ventilation, and Air Conditioning): NTC thermistors sense and control temperature in HVAC systems, aiding in regulating heating and cooling for optimal comfort and energy efficiency.
  4. Food and Beverage Industry: NTC temperature sensors monitor and control temperature during cooking, refrigeration, and transportation in food processing and storage applications.
Read more… →

ESP32 Mongoose OS Interface -MQTT

 

Mongoose OS Credentials configure

Two way to configure the MQTT Credentials  in Mongoose OS file. This Example tested with mongoose os , demo-js app, windows 10, 64bit, mos tool, ESP32 DevKitC from ESPressif.

  • First one is using mos tool  UI
    • GO to 127.0.0.1:1992/  –> Device Config  –> Change the MQTT Credential in MQTT Setting  and Save with Reboot
    • Afterwards its generate the new file name is conf9.json
  • Second methods is change the mqtt Credential in conf0.json  file

 

Required

  • ESP32 Any kind of boards
  • Mongoose OS firmware
  • Mos Tool
  • MQTT Server Credentials
  • WiFi Crendentials

Note : This ESP32 Mongoose OS interface – MQTT is tested with Windows 10 64bit machine, mos tool(Web Browser based IDE for Mongoose OS), ESp32 DevkitC board from ESPressif.

 

Follow

  • Make sure already set your WiFi Credentials (otherwise MQTT is not work, also check the MQTT Connected status in Terminal windows)

 

Code : init.js  file

load('api_config.js');
load('api_events.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');

let button = Cfg.get('pins.button');
let topic = '/devices/' + Cfg.get('device.id') + '/events';

print('button GPIO:', button);

let getInfo = function() {
  return JSON.stringify({
    total_ram: Sys.total_ram(),
    free_ram: Sys.free_ram()
  });
};

// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(button, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 20, function() {
  let message = getInfo();
  let ok = MQTT.pub(topic, message, 1);
  print('Published:', ok, topic, '->', message);
}, null);

// Monitor network connectivity.
Event.addGroupHandler(Net.EVENT_GRP, function(ev, evdata, arg) {
  let evs = '???';
  if (ev === Net.STATUS_DISCONNECTED) {
    evs = 'DISCONNECTED';
  } else if (ev === Net.STATUS_CONNECTING) {
    evs = 'CONNECTING';
  } else if (ev === Net.STATUS_CONNECTED) {
    evs = 'CONNECTED';
  } else if (ev === Net.STATUS_GOT_IP) {
    evs = 'GOT_IP';
  }
  print('== Net event:', ev, evs);
}, null);

 

Output

  • Results : {“free_ram”:148676,”total_ram”:229296}
  • Topic : /device/esp32_0255EC/events

 


 

 

Embedded Protocol – Bluetooth

Bluetooth is a wireless personal area network(WAN). BLE acronym for Bluetooth Low Energy. One of the most popular short-range wireless communication standards. Known as IEEE 802.15.1, it is now maintained by SIG (Special Interest Group). this is everywhere. How many this devices are there in the room? Cellphones, wireless mouse/keyboard, smart watch/bracelet, earphone, ibeacon.

Read more… →

Embedded Protocol – WiFi

WiFi, short for “Wireless Fidelity,” is a technology that allows devices to connect to the internet or communicate with each other wirelessly using radio waves. It’s widely used in homes, businesses, and public spaces to provide internet access without the need for physical wired connections. WiFi operates within the unlicensed radio frequency bands, typically 2.4 GHz and 5 GHz, and it’s governed by the IEEE 802.11 family of standards. These standards define different WiFi versions, such as 802.11n, 802.11ac, and the latest, 802.11ax (Wi-Fi 6), each offering various speeds, range, and features. WiFi routers and access points transmit signals that devices like smartphones, laptops, tablets, and smart home gadgets can receive, enabling them to access the internet or network resources.

Read more… →

ESP8266 NodeMCU Interface – DSB1820

Code

local ow_pin =   1 -- gpio-02
ds18b20.setup(ow_pin)

-- read all sensors and print all measurement results
ds18b20.read(
    function(ind,rom,res,temp,tdec,par)
        print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par)
        print("Temp : "..temp)
    end,{});

 

Embedded Sensor – Passive Infrared Sensor (PIR)

  • PIRPassive InfraRed Sensor
  • PIR consists of a Pyroelectric sensor which generates energy when exposed to heat.
  • The module covered with Fresnel Lense Cover.
  • BISS0001 micro Power PIR Motion Detector IC.

Infrared Application

  • Passive Infrared Detector for Anti Theft security alarm system.
  • Passive Infrared Detector based Light On/OFF.
  • Automatic Light  ON/OFF.
  • Many other motion Detection Application.

Different PIR Modules

The HC-SR501 PIR Sensor Module

  • Working voltage : 5v to 20V DC
  • Range : 3 to 7 meters
  • Induction Lens size: 23mm.
  • PCB Size: 32mm x24mm.
  • Pins Details
    • Ground pin
    • VCC pin
    • The output pin detects an object when it is at a high logic level.
  • Two potentiometers.
    • One for adjusting the sensitivity of the sensor
    • Adjust the time for the output signal to stay high when an object is detected from 0.3 seconds up to 5 minutes.
  • Jumper Settings (Selecting the trigger modes)
    • non-repeatable trigger – when the sensor output is high and the delay time is over, the output will automatically change from high to low level.
    • Repeatable trigger –  will keep the output high all the time until the detected object is present in sensor’s range

Arduino Example code :

Circuit

Code

/* Arduino PIR Motion Sensor Tutorial */
/* www.ArunEworld.com */

int pirSensor = 8;
int relayInput = 7;

void setup() {
  pinMode(pirSensor, INPUT);
  pinMode(relayInput, OUTPUT);
}

void loop() {
  int sensorValue = digitalRead(pirSensor);
  if (sensorValue == HIGH) {
    digitalWrite(relayInput, LOW); // The Relay Input works Inversely
  }
}

Code Explanation

This Arduino code is for a PIR (Passive Infrared) motion sensor setup, where a relay is controlled based on motion detection. Here’s an explanation of each part:

SectionExplanation
CommentsThe code includes comments providing information about the purpose of the code and its source.
Variable DeclarationpirSensor = 8;: Declares a variable pirSensor and assigns pin 8 to it for reading the PIR sensor’s output. – relayInput = 7;: Declares a variable relayInput and assigns pin 7 to it for controlling the relay.
Setup FunctionInitializes the pins: – Sets pirSensor pin as INPUT to receive data from the PIR sensor. – Sets relayInput pin as OUTPUT to control the relay.
Loop Function– Reads the digital state from the pirSensor pin to check for motion detection. – If motion is detected (sensor value is HIGH), it turns on the relay by setting the relayInput pin LOW.

Electronics Circuits – Multivibrator

A multivibrator is an electronic circuit that generates continuous square wave or rectangular wave oscillations. It is a type of waveform generator. It is commonly used in electronic circuits for various purposes. (Signal generation, timing, and pulse generation).

There are two main types of multivibrators: astable and monostable.

Astable Multivibrator:

  • An astable multivibrator is a free-running oscillator circuit that continuously switches between two states without any external input.
  • It has two distinct voltage levels, typically high and low.
  • The circuit consists of two cross-coupled amplifying devices (such as transistors or op-amps) and a feedback network.
  • The output waveform is a square wave. It’s an equal amount of time spent with each state.

Monostable Multivibrator:

  • A monostable multivibrator, also known as a one-shot multivibrator.
  • It has only one stable state.
  • Once triggered, it remains in the unstable state for a predetermined period before returning to the stable state.
  • Common applications include pulse generators, time delay circuits, and pulse-width modulation.
Read more… →

8051 Protocol – UART Bit Banging Method

The “8051 Protocol UART Bit Banging Method” is a technique used to implement UART communication on 8051 microcontrollers without relying solely on dedicated hardware UART modules.

Instead, it involves manually toggling GPIO (General Purpose Input/Output) pins to transmit and receive serial data in accordance with the UART protocol. This approach provides flexibility and enables the implementation of UART communication on microcontrollers lacking dedicated UART hardware.

Uses

ApplicationDescription
Low-Cost ProjectsCost-effective solution for implementing UART communication without additional hardware components.
Prototyping and DevelopmentFacilitates quick implementation of UART functionality during the prototyping and development phase, enabling rapid iteration and testing.
Embedded SystemsProvides a compact and resource-efficient solution for adding UART communication capabilities to 8051-based devices in space-constrained environments.
Education and LearningOffers hands-on experience with microcontroller programming and UART implementation, suitable for educational settings to teach serial communication protocols.
Custom Communication ProtocolsEnables the implementation of custom or non-standard communication protocols tailored to specific project requirements, providing flexibility and customization options.
Legacy Systems IntegrationAllows integration with modern communication interfaces and protocols for legacy systems using 8051 microcontrollers lacking dedicated UART hardware support.

Advantages

  • Cost-effective solution, especially for projects with budget constraints.
  • Enables quick implementation of UART functionality during prototyping and development phases, facilitating rapid iteration.
  • Offers versatility and adaptability, suitable for various applications and scenarios.
  • Provides hands-on learning experience with microcontroller programming and UART implementation in educational settings.
  • Allows integration with modern communication interfaces and protocols for legacy systems using 8051 microcontrollers lacking dedicated UART hardware support.

Disadvantages

  • Requires precise timing control for reliable operation, which may be challenging to achieve, especially at higher baud rates.
  • Less efficient compared to hardware-based UART solutions, resulting in potentially slower communication speeds and increased CPU utilization.
  • Consumes more CPU resources and may limit the microcontroller’s ability to perform other tasks concurrently, especially in multitasking applications.
  • Developers with limited experience in low-level hardware interaction may encounter higher implementation complexity when compared to using dedicated hardware UART modules.

Code

code of 8051 Protocol UART Bit Banging Method

#define crystal_freq 11.0592
#include <reg51.h>
#include <intrins.h>

#define uart_ch1 0
#define uart_ch2 2

sbit tx = P2^0;
sbit rx = P2^1;

void delay() {
    int i;
    for(i = 6; i; i--);
    _nop_();
    _nop_();
}

void delay_ms(int i) {
    int j;
    for(; i; i--)
        for(j = 122; j; j--);
}

void tx_data(char data_, char val) {
    char i;
    P2 |= 0x03;
    tx = 0; // send start bit
    P2 &= ~(1 << val);
    delay();

    for(i = 0; i < 8; i++) {
        if(((data_ >> i) & (0x01)) == 0x01) {
            P2 |= (1 << val);
        } else {
            P2 &= ~(1 << val);
        }
        delay();
    }

    P2 |= (1 << val);
    delay();

    // delay_ms(1);
}

void init_uart() {
    tx = 1;
}

void str(char *ch, char uart0_tx) {
    while(*ch) {
        tx_data(*ch++, uart0_tx);
    }
}

void init() {
    SCON = 0x50;
    TMOD = 0x20;
    TH1 = TL1 = 253;
    TR1 = 1;
}

void tx1(char ch) {
    SBUF = ch;
    while(!TI);
    TI = 0;
}

void str1(char *ch) {
    while(*ch) {
        tx1(*ch++);
    }
}

void main() {
    init_uart(); 
    init();
    while(1) {
        str(".........P2^0 IO PIN UART....\n\r", uart_ch1);
        str(".........P2^1 IO PIN UART.....\n\r", uart_ch2);
        str1(".........INBUILT UART ....\n\r");
    }
}

The explanation for 8051 Protocol UART Bit Banging Method Code

#define crystal_freq 11.0592
#include <reg51.h>
#include <intrins.h>

#define uart_ch1 0
#define uart_ch2 2

sbit tx = P2^0;
sbit rx = P2^1;
  • Header Files: The code begins by including necessary header files. reg51.h is specific to the 8051 microcontroller, while intrins.h provides intrinsic functions.
  • Constants: The crystal frequency is defined as 11.0592 MHz. uart_ch1 and uart_ch2 represent UART channels 0 and 2, respectively.
  • Global Variables: Two SFR (Special Function Register) bits tx and rx are declared to represent the transmit and receive pins of the UART.
void delay() {
    int i;
    for(i = 6; i; i--);
    _nop_();
    _nop_();
}

void delay_ms(int i) {
    int j;
    for(; i; i--)
        for(j = 122; j; j--);
}
  • Delay Functions: delay() and delay_ms() are defined to create timing delays. delay() produces a small delay, and delay_ms() generates a delay in milliseconds.
void tx_data(char data_, char val) {
    char i;
    P2 |= 0x03;
    tx = 0; // send start bit
    P2 &= ~(1 << val);
    delay();

    for(i = 0; i < 8; i++) {
        if(((data_ >> i) & (0x01)) == 0x01) {
            P2 |= (1 << val);
        } else {
            P2 &= ~(1 << val);
        }
        delay();
    }

    P2 |= (1 << val);
    delay();

    // delay_ms(1);
}
  • UART Functions: tx_data() is defined to transmit a byte of data (data_) using the specified UART channel (val). It sends start and stop bits and transmits each data bit, waiting for appropriate delays between each bit.
void init_uart() {
    tx = 1;
}
  • UART Initialization: init_uart() initializes the UART communication by setting the transmit pin (tx) to logic high.
void str(char *ch, char uart0_tx) {
    while(*ch) {
        tx_data(*ch++, uart0_tx);
    }
}

void str1(char *ch) {
    while(*ch) {
        tx1(*ch++);
    }
}
  • String Transmission Functions: str() and str1() transmit strings over UART channels 0 and the inbuilt UART, respectively. They iterate over each character in the string and transmit it using the appropriate function (tx_data() or tx1()).
void init() {
    SCON = 0x50;
    TMOD = 0x20;
    TH1 = TL1 = 253;
    TR1 = 1;
}
  • Initialization: init() initializes the UART and timer modes. It sets the serial control register (SCON), timer mode register (TMOD), and timer 1 high and low bytes (TH1 and TL1). Finally, it starts timer 1 (TR1).
void main() {
    init_uart(); 
    init();
    while(1) {
        str(".........P2^0 IO PIN UART....\n\r", uart_ch1);
        str(".........P2^1 IO PIN UART.....\n\r", uart_ch2);
        str1(".........INBUILT UART ....\n\r");
    }
}
  • Main Function: The program’s entry point is the main() function. It first initializes UART communication and timer modes.

Need of Bit Banging

ReasonDescription
Hardware LimitationsIn scenarios where dedicated hardware modules for certain functionalities like UART communication are not available due to cost constraints or limited chip resources, bit banging offers a software-based alternative for implementing these functionalities.
FlexibilityBit banging provides flexibility in implementing custom communication protocols or interfaces that may not be supported by hardware peripherals. This allows developers to tailor the implementation to specific project requirements and integrate with various systems.
Legacy SystemsIn legacy systems or devices using older microcontrollers, hardware support for modern communication protocols may be lacking. Bit banging enables integration with modern communication interfaces without requiring hardware upgrades, extending the lifespan of existing systems.
Educational PurposesBit banging is frequently utilized in education to offer students practical experience with low-level hardware interaction and communication protocols, aiding in their comprehension of digital communication principles.
Debugging and TestingBit banging aids in debugging and testing by enabling manual control of communication signals, facilitating issue diagnosis and system functionality verification, particularly in the absence of hardware-based debugging tools.

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

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

8051 Interface – 7 Segment Display

This tutorial will discuss about 8051 Interface – 7 Segment Display. 7-Seg display is the most basic electronic display. It consists of eight LEDs which are associated in a sequence manner to display digits from 0 to 9 when proper combinations of LEDs are switched on. A 7-segment display uses seven LEDs to display digits from 0 to 9 and the 8th LED is used for dot. A typical seven-segment look likes as shown in the figure below. The 7-segment displays are used in several systems to display the numeric information. They can display one digit at a time. Thus the number of segments used depends on the number of digits to display. Here the digits 0 to 9 are displayed continuously at a predefined time delay.

Read more: 8051 Interface – 7 Segment Display
7-Segment Display

The 7-segment displays are available in two configurations which are common anode (V+) and common cathode (GND). Here, we use the common anode configuration because the output current of the microcontroller is not sufficient to drive the LEDs. The 7-segment display works on negative logic, we have to provide logic 0 to the corresponding pin to make on LED glow. In this tutorial, you can learn 8051 interfaces 7 segment display with 8051 controller. I chose the AT89S51 micro controller(You can select any other Keil support microcontroller) and demonstrated, that this is very simple and follow this below.

The following table shows the hex values used to display the different digits.

Use of 7 Segment Display

  • Numeric Display: Shows numbers (0-9) and some letters (A-F).
  • Segment Control: Each segment can individually controlled.
  • Connection: Requires connection to microcontroller GPIO pins.
  • Display Logic: Determine which segments to illuminate for each digit.
  • Multiplexing: Can display multiple digits by rapidly switching between them.
  • Example Usage: Digital clocks, timers, counters, and temperature displays.

Required software

Required components and Programmer

  • 1x AT89S51 Controller
  • 1x 4Mhz Crystal
  • 2x 22pf capacitor
  • ISP AVR USB programmer
  • 7 Seg Display

Circuit Diagram

C code

#include<reg51.h>

void delay(int k) //delay function
{
int i,j;
for(i=0;i<k;i++)
  for(j=0;j<1275;j++);
}
void main()
{
    unsigned char i;
    unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
    P2=0x00;    
    while(1)
    {
        for(i=0;i<10;i++)
        {
            P2=arr[i];
            delay(100);
        }
        
    }
}

Assembly Code (ASM)

//See more on : http://www.ArunEworld.com

ORG 000H //initial starting address
START: MOV A,#00001001B // initial value of accumulator
MOV B,A
MOV R0,#0AH //Register R0 initialized as counter which counts from 10 to 0
LABEL: MOV A,B
INC A
MOV B,A
MOVC A,@A+PC // adds the byte in A to the program counters address
MOV P1,A
ACALL DELAY // calls the delay of the timer
DEC R0//Counter R0 decremented by 1
MOV A,R0 // R0 moved to accumulator to check if it is zero in next instruction.
JZ START //Checks accumulator for zero and jumps to START. Done to check if counting has been finished.
SJMP LABEL
DB 3FH // digit drive pattern for 0
DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9
DELAY: MOV R4,#05H // subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END

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

8051 Tutorials – 10hz Square wave generator using Timer

In this tutorial, you can learn how to generate a 10Hz square wave using a timer in an 8051 microcontroller. I chose the AT89S51 microcontroller (You can select any other Keil-supported microcontroller) and demonstrated it. Generating a 10Hz square wave using a timer in an 8051 microcontroller is a common task. Here’s a basic tutorial on how to do it:

 

Generating a square wave is a fundamental task in electronics, often required for various purposes such as clock signals, digital communication, and waveform testing. One common way to generate a square wave is by using an astable multivibrator circuit, which typically consists of two transistors or integrated circuits like the 555 timer.

Read more… →

8051 – Programming Technique

Programming for the 8051 microcontroller involves understanding its architecture, instruction set, and specific features. In this “8051 – Programming Technique” Tutorial are some key techniques and considerations for programming the 8051:

Read more: 8051 – Programming Technique

Key Technique and Considerations

Certainly! Here’s the information presented as a table:

Technique or ConsiderationDescription
Understanding the ArchitectureFamiliarize yourself with the basic architecture of the 8051 microcontroller, including its CPU, memory organization, I/O ports, timers/counters, and serial communication ports.
Instruction SetLearn the 8051’s instruction set, including data movement, arithmetic, logical, branching, and control instructions, to perform specific tasks and manipulate data.
Peripheral ProgrammingUtilize the 8051’s built-in peripherals, such as GPIO ports, timers/counters, and serial communication ports, to interface with external devices and perform specific functions.
Interrupt HandlingUnderstand interrupt handling in the 8051, including enabling/disabling interrupts, defining interrupt service routines (ISRs), and prioritizing interrupts based on application requirements.
Memory ManagementEfficiently manage memory resources, including RAM and ROM, to store program code, data variables, and constants, optimizing memory usage while ensuring efficient execution.
Timer ProgrammingUtilize the timers/counters available in the 8051 to generate precise timing delays, measure time intervals, and trigger events at specific intervals, configuring timer modes and parameters as needed.
Serial CommunicationImplement serial communication protocols, such as UART or SPI, using the 8051’s built-in serial ports, configuring communication parameters like baud rate, data format, and parity settings.
Optimization TechniquesEmploy optimization techniques to improve code efficiency and performance, such as loop unrolling, code reordering, and minimizing unnecessary memory accesses.
Testing and DebuggingThoroughly test 8051 programs using simulation tools or hardware debuggers, debug issues by analyzing program behavior, inspecting register values, and resolving errors.
Documentation and CommentsDocument code comprehensively with comments, especially for complex algorithms, interrupt service routines, and peripheral configurations, providing clear explanations for understanding and maintenance purposes.

By mastering these programming techniques and principles, you can develop efficient and reliable applications for the 8051 microcontroller, catering to a wide range of embedded system requirements.

C programming technique

  • How to Declare a Special Function Register(SFR)
    •  Definitions for P1 (8 bits), P1.0, and P1.1.  sfr P1 = 0x90; /* SFR for P1 */
  • How to Declare a Bit in Bit Addressable Spacial Function Register(SFR)
    • sbit P1_0 = P1^0; /* SFR for P1.0 */ 
    • sbit P1_1 = P1^1; /* SFR for P1.1 */
  • How to configure an I/O Port pin as an INPUT
    • P1_0 = 1; //configure as InPut
  • How to configure an I/O Port pin as an OUTPUT
    • P1_0 = 0; //configure as OutPut
  • How to read INPUT pin
  • How to read OUTPUT pin

8051 on ASM programming Technique

  • (file_name.asm) Assembly language is human programming language
  • (file_name.obj) Object file
  • (file_name.lst) List files
  • (file_name.abs) Absolute Object file
  • (file_name.hex) Hexadecimal file

Difference Between C code and equivalent Assembly code

  •  Empty Project code for 8051
  • LED define and initialize  Project code for 8051

8051 Hex Code Visualizer

Introducing the 8051 Hex Code Visualizer, brought to you by SpiceLogic Inc. This is a very simple tool targeted to solve only one problem. And that is visualizing the INTEL Hex Code that is generated targeting 8051 8 bit Micro-controllers. This tool will give you the complete understanding on how the Hex Code resides in the Memory of 8051 Micro-controllers. It is completely FREE and made for educational purpose. Get the app from

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

8051 – USB ISP Programmer

Using a USB In-System Programmer (ISP) for the 8051 microcontroller involves connecting the ISP programmer to your computer and the target 8051 microcontroller to load or program the HEX file into the microcontroller’s memory. Here’s a general guide about a USB ISP programmer with an 8051 microcontroller

Read more… →

8051 – Simulators

Simulators for the 8051 microcontroller are essential tools for embedded systems development and education. They allow programmers to test and debug their code without needing physical hardware, which can save time and resources. Some popular 8051 simulators include:

These simulators offer varying levels of features and complexity, catering to different needs and skill levels. Whether you’re a beginner learning 8051 programming or an experienced developer debugging complex embedded systems, there’s likely a simulator that fits your requirements.

Read more… →

8051- Loading a HEX file into the Microcontroller

           In this tutorial you can learn How to 8051 Loading a HEX file into the Microcontroller.  I chosen AT89S51 microcontroller (You can select any other Keil support microcontroller) and demonstrated, this is very simple, and follow the below steps,

  • 8051 Tutorials – How to load a HEX file into the AT89S51 MicroController?

Loading a HEX file into an 8051 microcontroller involves using a programmer to transfer the compiled HEX file into the microcontroller’s memory. Here are the general steps to load a HEX file into an 8051 microcontroller:

Read more… →