Interfacing of Arduino with 74HC595 & 74HC165

Hello friends, I hope you all are doing great. In today's tutorial, I am going to show you How to Interface Arduino with 74HC595 & 74HC165. I have already interfaced these shift registers separately with Arduino. In the first tutorial we have seen Arduino 74HC595 Interfacing in which I have discussed How to increase the output pins of Arduino using 74HC595. After that in second tutorial we have seen Arduino 74HC165 Interfacing where we have increased the input pins of Arduino. So, now we are gonna interface both of these shift registers with Arduino UNO and will increase both input and output pins of Arduino. I have also given the Proteus simulations for download at the end of this tutorial along with Arduino code. So, lets get started with Interfacing of Arduino with 74HC595 & 74HC165:

Interfacing of Arduino with 74HC595 & 74HC165

  • As you can see in above figure, I have used 74HC165 & 74HC595 and interfaced its pins with Arduino UNO.
  • I could use same clock for these shift registers but it would have made the code quite complex.
  • That's why I have used separate clock pins and I have used the below code to reflect the input on output.
#define NUMBER_OF_SHIFT_CHIPS   1
#define DATA_WIDTH   NUMBER_OF_SHIFT_CHIPS * 8
#define TotalIC 2
#define TotalICPins TotalIC * 8

int LoadPin    = 8;
int EnablePin  = 9;
int DataPin    = 11;
int ClockPin   = 12;

int RCLK = 5;
int SER = 6;
int SRCLK = 7;

unsigned long pinValues;
unsigned long oldPinValues;
boolean Data[TotalICPins];

void setup()
{
    Serial.begin(9600);

    pinMode(LoadPin, OUTPUT);
    pinMode(EnablePin, OUTPUT);
    pinMode(ClockPin, OUTPUT);
    pinMode(DataPin, INPUT);

    digitalWrite(ClockPin, LOW);
    digitalWrite(LoadPin, HIGH);
    Serial.println("Visit us at www.TheEngineeringProjects.com");
    Serial.println();
    pinMode(SER, OUTPUT);
    pinMode(RCLK, OUTPUT);
    pinMode(SRCLK, OUTPUT);

    ClearBuffer();
    
    pinValues = read_shift_regs();
    print_byte();
    oldPinValues = pinValues;
}

void loop()
{
    pinValues = read_shift_regs();

    if(pinValues != oldPinValues)
    {
        print_byte();
        oldPinValues = pinValues;
    }

}

unsigned long read_shift_regs()
{
    long bitVal;
    unsigned long bytesVal = 0;

    digitalWrite(EnablePin, HIGH);
    digitalWrite(LoadPin, LOW);
    delayMicroseconds(5);
    digitalWrite(LoadPin, HIGH);
    digitalWrite(EnablePin, LOW);

    for(int i = 0; i < DATA_WIDTH; i++)
    {
        bitVal = digitalRead(DataPin);
        bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));

        digitalWrite(ClockPin, HIGH);
        delayMicroseconds(5);
        digitalWrite(ClockPin, LOW);
    }

    return(bytesVal);
}

void print_byte() { 
  byte i; 

  Serial.println("*Shift Register Values:*\r\n");

  for(byte i=0; i<=DATA_WIDTH-1; i++) 
  { 
    Serial.print("P");
    Serial.print(i+1);
    Serial.print(" "); 
  }
  Serial.println();
  for(byte i=0; i<=DATA_WIDTH-1; i++) 
  { 
    
    Serial.print(pinValues >> i & 1, BIN); 
    Data[i] = pinValues >> i & 1, BIN;
    //if(BinaryValue == 1){Data[i] = HIGH;}
    //if(BinaryValue == 0){Data[i] = LOW;}
    UpdateData();
    if(i>8){Serial.print(" ");}
    Serial.print("  "); 
    
  } 
  
  Serial.print("\n"); 
  Serial.println();Serial.println();

}

void ClearBuffer()
{
    for(int i = TotalICPins - 1; i >=  0; i--)
    {
       Data[i] = LOW;
    }
    UpdateData();
} 

void UpdateData()
{
   digitalWrite(RCLK, LOW);
   for(int i = TotalICPins - 1; i >=  0; i--)
   {
        digitalWrite(SRCLK, LOW);   
        digitalWrite(SER, Data[i]);
        digitalWrite(SRCLK, HIGH);

  }
  digitalWrite(RCLK, HIGH);
}
  • In the above code, I have used Number_of_Shift_Chips 1 and it means I am using 1 chip each, so in total 2 chips.
  • Now get hex file from Arduino software and upload it in your Proteus software.
  • Run your simulation and if everything goes fine then you will get something as shown in below figure:
  • You can see in above figure that all those LED outputs are ON which has HIGH inputs.
  • I have also attached a Virtual Terminal with Arduino to have a look at the input bits.
  • Now let's add 2 chips of 74HC165 and 74HC959, so design a simple simulation as shown in below figure:
  • Now in your above code change the Number of Shift chips from 1 to 2, as now we are using 2 chips each.
  • Upload your hex file and if everything goes fine then you will get similar results:
  • So, that's how you can easily increase input and output pins of Arduino UNO.
  • I have just designed a simple code but you can work on it and can control these inputs separately as well.
  • You can interface different digital sensors on these input pins and can control motors, relays, solenoids etc. at output pins.
  • You can download both of these Proteus Simulations along with Arduino code by clicking the below button, but I would suggest you to dwsign it on yoru own so that you could learn from mistakes.

[dt_default_button link="https://theengineeringprojects.com/ArduinoProjects/Interfacing%20of%20Arduino%20with%2074HC595%20&%2074HC165.zip" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download Proteus Simulation & Arduino Code [/dt_default_button]

So, that was all about Interfacing of Arduino with 74HC595 & 74HC165. I hope you can now easily simulate it. If you have any questions then ask in comments and I will try my best to resolve them. Thanks for reading. Take care !!! :)

How to use analogWrite in Arduino?

Hey Fellas! Hope you are getting along with life pretty well. This post is another addition in this Arduino Tutorial for Beginners series. Today, I'll discuss How to use analogWrite in Arduino? The analogWrite is mainly used to update the status of analog pins and is also used to map the analog values on the PWM (Pulse Width Modulation) pins. You can check the article that I have posted previously on How to use analogRead in the Arduino - this command addresses the analog pins on the board and reads its status, while today's one does the exact opposite. In this post, I'll try to break down each and everything related to analogWrite in simple steps, so you can grab the main idea pretty well. Let's jump right in.

How to use analogWrite in Arduino?

  • The analogWrite Arduino command is used to update the status of analog pins and also used to address the PWM pins on the board.
  • The PWM pins are 8-bit pins, terming that you can set the duty cycle somewhere between 0 -255.
  • The duty cycle is described as the amount time the signal switches between ON and OFF condition. It is mainly written in percentage.
  • If the signal remains turned ON half of the total duty cycle and OFF in another half, then the duty cycle will be 50%.
  • The analogWrite comes handy when you plan to control the motor speed or the intensity of any LED.
  • The value you write on the PWM pins will control the speed.
  • For example, if you intend to run the motor at full speed, you will set the value 255 i.e. the maximum value it can handle that will ultimately run the motor at full speed.
  • Similarly, setting value as "0" will be sending no signal and motor won't start.
  • And if the motor requires to be run at half speed, then you will set the value 127 or 128 -  half of the maximum value that will cause the motor to be running at half speed.
  • Arduino Uno comes with PWM pins available on digital pin number 3,5,6 and 9,10,11. You can put any number, out of these pins.
  • Now let's have a look at How to use analogWrite Arduino command:
Syntax

analogWrite(int pin, int value);

where:
  • "pin" is the pin number you are targeting.
  • "value" is the duty cycle that can be set anywhere between 0  to 255 where former indicates the OFF condition and later indicates the system is running at full speed.
Example

analogWrite(10, 175);

Note: The analogWrite command doesn't return or store any value, unlike analogRead that returns value anywhere between 0 to 1023 depending on the voltage it gets in return from the connected sensor or device. The Arduino IDE is an official software used to program the Arduino Boards. It is an open source software, giving you the flexibility to program the Arduino Board as per your technical needs and requirements. It is free of cost and help is readily available on the Arduino site in case you feel any difficulty in shaping the desired code on the board. That’s all for now. I'll be writing more articles on how to code Arduino. If you are feeling skeptical about anything, making it difficult for you to grab the basic idea, you can approach me in the comment section below. I’d love to help you the best way I can. In the coming tutorial, we will have a look at How to use Arduino PWM Pins. Thanks for reading the article.

Introduction to CR1220

Hi Fellas! Hope you are getting along with life pretty well. I am back to give you a daily dose of useful information. Today, I'll unlock the details on the Introduction to CR1220.  It is known as a lithium coin battery that comes with a high voltage around 3V and encompasses an ultra-compact design, helping you gid rid of the hassle of buying two or three extra traditional batteries, saving both cost and space required to adjust these cells in the relevant devices. In this post, I'll try to cover each and everything related to CR1220, breaking down its details in simple steps you can get a hold what is this about and how it is used for. Let's dive in and explore everything you need to know about this battery.

Introduction to CR1220

  • CR1220 is a button cell, also known as lithium coin battery, that is mainly used in high power devices such as keyless entry devices, glucose monitors, heart-rate monitors, and toys & games.
  • It comes in cylindrical shape and can retain power for a maximum period of time. If it is spared alone for one year, it will discharge only 1% of the total battery capacity.
  • This battery is slightly different from CR2032 in terms of battery capacity, weight and lithium content as former comes with 35mAh capacity with 0.8g weight and 0.006 grams lithium content while later contains 285mAh capacity, 3gram weight, and 0.109gram lithium content.
  • It features small and compact shape, making it an ideal choice for hard to reach places.
  • Prior precautions are required to keep this device safe and away from the kids. If swallowed, this device can cause a severe health damage or death in some cases due to the chemical composition it incorporates.
  • The output voltage it can deliver is around 3V, enough to drive some small devices like wristwatches and glucose monitors.
  • Both positive and negative electrodes are stainless steel SUS430 and Nickel plated.
  • It is important to note that, no coatings or other foreign objects are required on the surface of terminals that can severely affect the real use or performance of this coin cell.
  • Battery compartments work best to encapsulate this battery, making it safe and away from the kids. They can be designed using two methods: an extra mechanical tool like a screwdriver is required to unlock the battery compartment or you can apply two independent movements of the securing mechanism by a single hand.
  • These battery compartments come with an ability to retain different cells where capacities will vary by size.
CR1220 Features
Features of any device can help you better understand major functions associated with it, helping you make a final decision before picking the device for your relevant project. Following are the main features of CR1220.
Classification Coin Cell Battery or Lithium Energizer
Product Name CR1220
Output Voltage 3V
Chemical System Lithium / Manganese Dioxide (Li/MnO2)
Capacity 35 mAh
Energy Density 153 milliwatt hr/g
Weight 0.8 gram
Lithium Content 0.006 grams
Self Discharge 1% / year
Type Non-Rechargeable
Maximum Operating Temperature 70 °C
Minimum Operating Temperature -30 °C
 
  • Some cells are made from different chemical compositions, making them mechanically interchangeable which may directly service life voltage stability of the cell.
CR1220 Dimensions
Following figure shows the dimensions of CR1220.
  • The dimensions are given in mm vs inches.
  • Pay special heed while selecting the coin cell for a required device, the wrong pick can intensively affect the device performance, resulting in a sheer hindrance in the operating process.
CR1220 Applications
CR1220 comes with a wide range of applications that require temporary power on the fly. Following are some major applications of this coin cell.
  • Keyless entry devices
  • Glucose monitors
  • Implantable cardiac defibrillators
  • Heart-rate monitors
  • Artificial cardiac pacemakers
  • Toys & games
That's all for today. I hope you have found this read useful. If you are feeling skeptical or have any question you can approach me in the comment section below. I'd love to help you according to the best of my expertise. Feel free to keep us updated with your valuable feedback and suggestion, so we keep providing quality work and you keep visiting us for what we have to offer. Thanks for reading the article.

Arduino 74HC165 Interfacing: Increase Input Pins

Hello friends, I hope you all are doing great. In today's tutorial, I am going to do an Arduino 74HC165 Interfacing and we will have a look at How to increase Input Pins of Arduino. 74HC165 is a shift register and works on the principal of Parallel In Serial Out. In my previous tutorial Arduino 74HC595 Interfacing: Increase Output Pins, we have seen How to increase the output pins of Arduino and today we are gonna do exact the opposite and we will increase the input pins. 74HC165 will take 8 parallel inputs from different sensors or buttons etc and will send them to serial OUT Pin, which will be connected to Arduino. So, if you are working on a project where you want to get data of 15 or 20 digital sensors then you can use this shift register and just using a single pin of Arduino you can read data of all those sensors. We can only get digital inputs, we can't get analog input through this shift register. So, let's get started with Arduino 74HC165 Interfacing:

Arduino 74HC165 Interfacing

  • I will design a Proteus Simulation of Arduino 74HC165 Interfacing, I have given the files for download at the end of this tutorial, but I would recommend you to design it so that you could learn.
  • I will connect simple Logic buttons with this shift register and will read their status on the Serial Port.
  • So, first of all design a simple Proteus Simulation as shown in below figure.
  • I have used Arduino UNO and have connected Virtual Terminal so that we could have a look at Serial data.
  • As you can see in the above figure that I have connected four pins between Arduino and 74HC165, which are:
    • Pin # 8 of Arduino  ==> Shift (SH) of shift register.
    • Pin # 9 of Arduino  ==> Clock Enable (CE) of shift register.
    • Pin # 11 of Arduino ==> Serial OUT (SO) of shift register.
    • Pin # 12 of Arduino ==> Clock (CLK) of shift register.
  • Now open you Arduino software and copy paste the below code in it:
#define NUMBER_OF_SHIFT_CHIPS   1
#define DATA_WIDTH   NUMBER_OF_SHIFT_CHIPS * 8

int LoadPin    = 8;
int EnablePin  = 9;
int DataPin    = 11;
int ClockPin   = 12;

unsigned long pinValues;
unsigned long oldPinValues;

void setup()
{
    Serial.begin(9600);

    pinMode(LoadPin, OUTPUT);
    pinMode(EnablePin, OUTPUT);
    pinMode(ClockPin, OUTPUT);
    pinMode(DataPin, INPUT);

    digitalWrite(ClockPin, LOW);
    digitalWrite(LoadPin, HIGH);

    pinValues = read_shift_regs();
    print_byte();
    oldPinValues = pinValues;
}

void loop()
{
    pinValues = read_shift_regs();

    if(pinValues != oldPinValues)
    {
        print_byte();
        oldPinValues = pinValues;
    }

}

unsigned long read_shift_regs()
{
    long bitVal;
    unsigned long bytesVal = 0;

    digitalWrite(EnablePin, HIGH);
    digitalWrite(LoadPin, LOW);
    delayMicroseconds(5);
    digitalWrite(LoadPin, HIGH);
    digitalWrite(EnablePin, LOW);

    for(int i = 0; i < DATA_WIDTH; i++)
    {
        bitVal = digitalRead(DataPin);
        bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));

        digitalWrite(ClockPin, HIGH);
        delayMicroseconds(5);
        digitalWrite(ClockPin, LOW);
    }

    return(bytesVal);
}

void print_byte() { 
  byte i; 

  Serial.println("*Shift Register Values:*\r\n");

  for(byte i=0; i<=DATA_WIDTH-1; i++) 
  { 
    Serial.print("P");
    Serial.print(i+1);
    Serial.print(" "); 
  }
  Serial.println();
  for(byte i=0; i<=DATA_WIDTH-1; i++) 
  { 
    Serial.print(pinValues >> i & 1, BIN); 
    
    if(i>8){Serial.print(" ");}
    Serial.print("  "); 
    
  } 
  
  Serial.print("\n"); 
  Serial.println();Serial.println();

}
  • The code is quite simple but let me give you a quick explanation of  it.
  • First of all, I have assigned names to all 4 pins of 74HC165 connected with Arduino.
  • Function read_shift_regs() is used to read the eight input pins of 74HC165 and print_byte() function is used to display that data on Serial Monitor.
  • So get your hex file from Arduino software and upload it in Proteus software.
  • Run your Proteus simulation and if everything goes fine then you will get results as shown in below figure:
  • If you change any input of your shift register then you will get the new value on your Virtual Terminal.
  • Now let's add another 74HC165 and increase our input pins by 16.
  • So, design a simple circuit as shown in below figure:
  • Now, in the above code, simply change the first line and make #define NUMBER_OF_SHIFT_CHIPS 2.
  • Simply changes 1 to 2, as we are using 2 shift registers now.
  • Now get your hex file and run the Proteus simulation.
  • Here's the output of our 16 increased inputs:
  • That's how you can easily interface multiple 74HC165 chips with your Arduino board and can increase the input options.
  • You can download these Proteus simulations and code for Arduino 74HC165 Interfacing by clicking the below button:

[dt_default_button link="https://www.theengineeringprojects.com/ArduinoProjects/Arduino 74HC165 Interfacing.rar" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download Proteus Simulation & Code[/dt_default_button]

  • You should also have a look at this video in which I have shown How to run these simulations:
So, that was all for today. In my coming tutorial, I will interface both 74HC165 and 74HC595 with Arduino UNO and will show you How to increase both input and output pins at the same time. Thanks for reading. Take care!!! :)

Arduino 74HC595 Interfacing: Increase Output Pins

Hello friends, I hope you all are doing great. In today's tutorial, I am going to show you Arduino 74HC595 Interfacing and we will have a loook at How to Increase Arduino Output Pins with 74HC595. Suppose you are working on some project where you need to control 20 LEDs with Arduino UNO and you know we will 12 digital Pins so we can't control all of these 20 LEDs with Arduino UNO. We can use Arduino Mega as well but if we wanna stick to Arduino UNO then we need to increase its Output Pins and we will use 74HC595 for that purpose. You should read this basic Introduction to 74HC595, it will help you to better understand this shift register. It's a Serial In Parallel Out Shift register and we will give it value serially from single Pin of Arduino and it will output that data to 8 output pins. Moreover, we can also connect these registers in parallel to increase the output pins even further. So, let's have a look at Arduino 74HC595 Interfacing:

Arduino 74HC595 Interfacing

  • As I told earlier 74HC595 is a serial In Parallel Out Shift Register and is used to increase the output pins of Arduino.
  • I am gonna use Proteus software and we will design its simulation and then will check out How it works.
  • So, design a simple circuit as shown in below figure:
  • As you can see in above figure, I have done the following connections between Arduino and HC595:
    • Pin # 5 of Arduino ==> ST_CP
    • Pin # 6 of Arduino ==> DS
    • Pin # 7 of Arduino ==> SH_CP
    • All output pins of 74HC595 are connected to LEDs.
  • Now upload the below Arduino code and get your hex file.
int RCLK = 5;
int SER = 6;
int SRCLK = 7;

#define TotalIC 1
#define TotalICPins TotalIC * 8

boolean Data[TotalICPins];

void setup()
{
  pinMode(SER, OUTPUT);
  pinMode(RCLK, OUTPUT);
  pinMode(SRCLK, OUTPUT);

  ClearBuffer();
}              


void loop()
{
   for(int i = TotalICPins - 1; i >=  0; i--)
   {
      Data[i] = HIGH;
      UpdateData();
      delay(300);
      ClearBuffer();
   }

   for(int i = 1;i < TotalICPins - 1;  i++)
   {
      Data[i] = HIGH;
      UpdateData();
      delay(300);
      ClearBuffer();
   }
   
}

void ClearBuffer()
{
    for(int i = TotalICPins - 1; i >=  0; i--)
    {
       Data[i] = LOW;
    }
    UpdateData();
} 

void UpdateData()
{
   digitalWrite(RCLK, LOW);
   for(int i = TotalICPins - 1; i >=  0; i--)
   {
        digitalWrite(SRCLK, LOW);   
        digitalWrite(SER, Data[i]);
        digitalWrite(SRCLK, HIGH);

  }
  digitalWrite(RCLK, HIGH);
}
  • The code is quite simple but let me explain it a bit.
  • First of all we have given names to our 3 Pins connected to Arduino UNO.
  • After that we have made all those 3 Pins as OUTPUT as we are gonna send the data.
  • We are using single chip of 74HC595 that's why I have made it 1.
  • In the UpdateData function, you can see we have to make RCLK Low and after that we have sent our data.
  • But for sending each bit of Data we have to make SRCLK from LOW to High.
  • SER is our Serial IN from Arduino to 74HC595.
  • So, in loop section, I am simply sending HIGH from first Pin to Last and then from last Pin to first and we are getting below results:
  • Now let's have a look at How to connect two 74HC595 chips in parallel to increase the output pins to 16.
  • I have also given these Proteus simulations for download at the end of this tutorial but I would recommend you to design them on your own so that you got better understanding of this shift register.
Arduino 74HC595 Interfacing: 2 Chips in Parallel
  • Now we are gonna place two shift registers in parallel and we will be able to control 16 outputs from single Arduino Pin.
  • Although we are using 3 Arduino Pins but the data is sent through Pin # 6 of Arduino and Pin # 5 and 7 are CLK Pins.
  • Now design a circuit as shown in below figure:
  • Now in Arduino Code, you just need to change the TotalIC to 2 and as you have seen we have already multiplied it with 8 so now our for loop will move from 0 to 15.
  • Pin # 5 and 7 will simply connected to same pins of second shift register but DS will be connected to Q7' of first shift register.
  • Now get your hex file from Arduino software and if everything goes fine then you will get something as shown in below figure:
  • Now let's make it a bit more complex by adding 4 shift registers in parallel.
  • So, design a Proteus Simulation as shown in below figure:
  • We have followed the same principal, Q7' of second chip is connected to DS to 3rd chip and goes on.
  • I have placed these default Pins instead of connecting the wires, it works the same.
  • If this image is not clear then open it in new tab and zoom out to check the connections.
  • Now in your Arduino code, you need to change the TotalIC to 4, as now we are using four chips.
  • Get your Hex File and run Proteus simulation and if everything goes fine then you will get similar results:
  • So, that's How you can quite easily do the Arduino 74HC595 Interfacing and can increase Arduino outputs as much as you want.
  • You can download these Proteus Simulations along with code by clicking the below button:

[dt_default_button link="https://www.theengineeringprojects.com/ArduinoProjects/Arduino 74HC595 Interfacing.rar" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download Proteus Simulation & Arduino Code[/dt_default_button]

  • I have also designed this YouTube video to give you a better understanding of Arduino 74HC595 Interfacing:
So, that was all for today. I hope you have enjoyed this Arduino 74Hc595 Interfacing. If you have any questions, then ask in comments and I will try my best to resolve them. In my coming tutorial, I will show you How to increase the Arduino Input Pins. So stay tuned and have fun. :)

How to use analogRead in Arduino?

Hi Friends! Welcome you onboard. I have been writing these Arduino tutorial for beginners for quite a while now and today we are having the next episode. Today, I'll discuss How to use analogRead in Arduino. The analogRead is mainly used to program and address analog pins on the board. In our previous tutorial, we have seen How to use digitalWrite Arduino Command, which deals with digital pins of Arduino but today's one deals with analog pins. There are many types of boards available in the market ranging from Arduino UNO, Arduino Mega2560, Arduino Micro and many more, which you can use based on your technical requirements. Arduino Programming is made simple by the Arduino.cc - the manufacturer of Arduino Boards, providing an open source software and hardware features and give you the flexibility to modify and tweak the boards as per your requirements. In this post, I'll discuss how you can easily program the Arduino Board using analogRead if you intend to target the analog pins on the board. Let's dive in.

How to use analogRead in Arduino

The analogRead is a command mainly used to program the analog pins on the board. If you are using analogRead functions, it indicates you are making the pins as input i.e. you can connect the Arduino analog pins with any sensor and read its value by making the analog pins as input. Following figure shows the placement of analog pins on the Arduino Uno Board.
  • If you have already got a hold of some features of Arduino Board, you must have known that analog pins are 10-bit pins. It means each pin can store 0 - 1023 values.
Analog pins are different than digital pins as the later can store only two values: HIGH and LOW while the former comes with an ability to store any random value ranging from 0 - 1023 where 0 will indicate the ground signal or zero volts while 1023 will be representing 5 volts. The voltage values are directly proportional to the values stored in the Arduino Pins. For example, if the sensor voltage is around 2.5 V then the value we get on an analog pin will be half the total value it can store in the pin i.e. 512. Syntax:
  • The syntax of analogRead is given as follows:

int data = analogRead(int pin);

where:
  • Pin defines the number of a pin you are targeting. Most of the Arduino Boards come with 6 analog pins and marked as A0 to A5 while Arduino Pro Mini and Arduino Nano come with 8 pins, marked from A0 to A7 and Arduino Mega stands out in terms of having the most number of analog pins, around 16, marking from A0 to A15 on the Mega.
Return:
  • analogRead returns value anywhere between 0 to 1023 depending on the voltage it gets in return.
Example:

data = analogRead (4);

Note: 
  • If you are aiming to read analog pins from digitalRead, you must write A4, instead of simply pointing the required pin number i.e. analogRead(A4).
Here's a sample code for testing the analogRead Arduino command:
int sensorPin = A0;
int sensorValue = 0;  

void setup() {
 
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() 
{
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);
}
I have written an Article on Introduction to Arduino IDE - An Official Software used to program the variety of Arduino Boards. In this Article, I have broken down everything in simple steps, detailing how to select the relevant board you are working on and make it compatible with the software. That’s all for today. I hope you have got valuable information out of this read. However, if you are unsure or have any question you can approach me in the comment section below. I’d love to help you according to the best of my knowledge. In the coming tutorial, we will have a look at How to use analogWrite in Arduino, which is used to update the status of analog pins. Thanks for reading the article.

Introduction to S8050

Hey Guys! Hope you are doing well. I always strive to keep your technical needs and requirements quite in line with valuable information that helps you excel and thrive in engineering and technology. Today, I'll unlock the detailed Introduction to S8050 that is an NPN Epitaxial Silicon Transistor mainly used for push-pull amplification and general purpose switching applications. It is a low voltage and high current transistor, featuring collector current up to 700 mA and Collector-Emitter voltage around 25 V. I'll try to cover each and everything related to S8050, so you don't have to scratch your head browsing the whole internet and find all the information in one place. Let's dive in and kick off the nitty-gritty of this transistor.

Introduction to S8050

S8050 is an NPN Epitaxial Silicon Transistor that comes with low voltage and high current capabilities. It proves to be a bright spot for push-pull amplification and general purpose switching applications.
  • This transistor mainly contains three terminals known as an emitter, base, and collector that are used for the external connection with the electronic circuits.
These terminals are different in terms of doping concentration where emitter terminal is highly doped as compared to base and collector terminals.
  • The base terminal is lightly doped and the collector terminal is moderately doped where former controls the number of electrons and later collects the number of electrons from the base terminal. The small current at one terminal at one terminal is used to control large current at other terminals.
This transistor incorporates three layers where one P-doped semiconductor layer is encapsulated between the other two N-doped layers. The P-doped layer represents the base terminal while other two layers represent emitter and collector respectively.
  • There are two types of transistors known as Unipolar Transistor and Bipolar Junction Transistors. The S8050 falls under the category of Bipolar Junction Transistor - as the name suggests it comes with two charge carriers: electrons and holes, however, electrons are the major charge carriers.
This transistor features two PN junctions: emitter-base junction that is forward biased and the collector-base junction that is reverse biased.
  • It is important to note that, S8050 must be operating in a forward biased mode for a better performance. If a transistor is not forward biased, there will be no collector current, no matter how much voltage is applied at the base terminal.
The amplification is carried out a simple way when a voltage is applied at the base terminal, transistor draws small current which is then used to control large current at other terminals.
S8050 Pinout
S8050 mainly consists of three terminals. 1. Emitter 2. Base 3. Collector  Following shows the pinout of this transistor. The electron movement is mainly triggered by the voltage applied at the base terminal, resulting in the diffusion of electrons from the base to collector terminal.
  • As the voltage is applied the electron from emitter terminal triggers and enters the base terminal, combining with the hole already present in the base terminal and the resulting pair disappears.
The number of electrons entering the base terminal from the emitter is greater than the number of holes diffusing into the emitter region that's why electrons are major charge carriers in case of NPN transistor.
  • The base terminal is unable to handle all electrons entering it, subsequently, electrons move from the base to collector terminal.
S8050 Circuit Diagram
Following figure shows the circuit diagram of the S8050. In this NPN transistor, electrons are main charge carriers, unlike  PNP transistor where holes are major charge carriers.
  • The base is more positive with respect to the emitter and the voltage on the collector must also be more positive than the base.
The collector is made physically larger than the base for two reasons: allowing a collector to deal with more heat without damage and increasing the chance of carriers that enter the collector terminal.
  • Two current gain factors: common-emitter current gain and common-base current gain play a vital role to determine the characteristic of the transistor.
The common-emitter current gain is a ratio between collector current and base current. This is called Beta, denoted by ß, and more often than not ranges between 20 to 1000, however, the standard value is taken as 200.
  • Similarly common-base current gain is a ratio between collector current and emitter current. It is called alpha, denoted by a, and its value mainly ranges between 0.95 to 0.99, however, most of the time its value is taken as unity.
S8050 Absolute Maximum Ratings
Following figure shows the absolute maximum ratings of S8050.  
  • These are the stress ratings which if exceed from the absolute maximum ratings, can damage the device at large, which ultimately affect the project performance.
These ratings are determined on the basis of the maximum junction temperature of 150 °C.
  • Additionally, if ratings are applied for a maximum period of time above normal operating conditions, they can affect the device reliability.
Applications
  • This NPN transistor is mainly used for push-pull amplification.
  • Some general purpose switching applications feature this transistor, aiming to control large current with a small current.
That’s all for now. I hope I have given you everything you needed to know about S8050. If you are unsure or have any question, you can ask me in the comment section below. I’d love to help you the best way I can. You are most welcome to keep us updated with your valuable suggestions, they help us provide you quality work. Thanks for reading the article.

Introduction to USB

Hey Everyone! Hope you are getting along with life pretty well. I always strive to keep your technical appetite filled with the recent and valuable development in engineering and technology. Today, I'll unravel the detailed Introduction to USB. The USB stands for Universal Serial Bus which is an industry standard mainly developed for laying out the communication between a computer and peripheral devices. The first USB was developed in 1996 by the collaborative effort of seven companies - DEC, Microsoft, Compaq, Nortel, IBM, Intel, and NEC
  • The USB device not only helps in establishing a flawless communication but also assists to power up the connected peripheral devices, setting you free from the parallel ports and the external power chargers that turn out to be costly and cover more space.
The lastest USB 3.2 is introduced in 2017 with the maximum speed capability for communication - around 20 GBits/s which is quite adequate to transfer the data from the peripheral device to the computer with some remarkable pace. In this post, I'll cover each and everything related to USB, its main features, need of use, advantages and main applications. Let's dive right in.

Introduction to USB

The USB is an industry standard mainly developed for laying out the communication between a computer and peripheral devices.
  • Additionally, unlike some traditional connector, USB doesn't require any user adjustable interface setting, it serves more like a plug and play device. You just need to connect the one end of the USB cable with a peripheral device and another end to the computer and start playing and controlling the peripheral device.
Communication between the devices is an essential part of the electronics. More often than not, the computer serves as a host with which the peripheral devices are connected. It is important to note that, it is impossible to connect the two peripheral devices using USB unless there is a separate host available that controls the communication and serves as the main handling device in the whole arrangement of communication between the peripheral devices.
  • The USB is unable to handle multi-master arrangement and can support one host per bus. However, the "USB on the GO" is designed with the purpose, if there is no host available, two devices collaborate with each other to define, which one is appropriate to serve as a host in the whole protocol.
USB Pinout
Following figure shows the pinout of the Universal Serial Bus.   A number of USB connectors are available. The connector attached with the host (computer) or device is called male port or receptacle, and the connector coupled with the cable is called female jack or plug. There are 7 USB connectors introduced until now
  • Standard-A Type
  • Standard-B Type
  • Mini-A
  • Mini-B
  • Micro-A
  • Micro-B,
  • Type-C
Standard A and B type come with 4 pins while Mini and Micro-USB interface is incorporated with total five pins where four pins work similar to the standard USB connectors and the additional pin is nothing but a device indicator. Following figure shows the pinout of USB Type C connector.   Type C connector is a new connector that stands out in terms of power capabilities as it comes with an ability to deliver 100 W which far larger than its standard predecessors that can deliver in a range between 2.5 to 5 W.
  • It comes very handy in a variety of fast charging applications, as it features power delivery, video, audio, and data capability in a single package.
Pin Description
As mentioned above USB is a serial bus that is housed with 4 shielded wires where two are reserved for power (+5v & GND) while the other two are used for carrying differential data signals. They are marked as D+ and D- on the pinout given above and are transmitted on a twisted pair.
  • The NRZI (Non-Return to Zero Invert) encoding scheme is mainly employed to send data with a sync field while ultimately helps in synchronizing the host and receiver clocks.
Note: The half-duplex differential signaling is used to brush off the effects of electromagnetic noise where long lines are a major concern.
Capability
A single USB bus can handle around 127 devices at a time. If you plan to connect more devices, you need to add another host to the arrangement.
  • The earlier USB hosts came with two ports that were enough to control the peripherals devices at that time. However, with the invention of new devices and as all workload was shifted to computer technology, it ultimately put the burden and erupted the need for more ports incorporated into the USB hosts.
Recently the USB host comes with 4 or ports on a single interface, giving you the flexibility to connect more devices on the fly. At the start, the hosts were featured with only one USB controller, where both ports sharing the same bandwidth. However, as there came a surge in the requirement of bandwidth, multiple port cards were coupled with two controllers, giving you the ease of handling individual channels.
  • The USB 1.1 comes with a maximum cable length of 5 meters that can easily support peripheral devices running at speed around 12 Mbit/s, however, it varies as the cable length differs i.e. cable length of around 3 meters is a good fit for devices running at a low speed of around 1.5 Mbit/s.
Similarly, USB 2.0 is an improvised version of the USB 1.1, supporting a maximum cable length of 5 meters with devices running at high speed 480 Mbit/s.
  • The USB 3.0 is not reserved for specific cable length, however, the cables used under this standard must meet some electrical specifications i.e. the maximum practical length is 3 meters for copper cabling with AWG 26 wires.
USB Versions
A number of USB versions have been released until now with every new version disguising the features of its predecessors with some added speed and connection capability. Following table shows the list of USB versions introduced till date. You can see from the table, how USB speed capability has been modified over the years ranging from 1.5 Mbits/s to 20 Gbits/s. This is a huge shift indeed.
Architecture
The USB architecture is mainly based on tiered star topology that is identical to 10BASE-T Ethernet. The topology interface supports the need of hub as per requirements. Recently, some devices like Keyboard come with a USB hub and instead of directly connecting the mouse or any digital camera with a computer, you can connect them with the hub incorporated on the keyboard and use them similar as you connect them with the computer, as eventually the keyboard will be connected to the computer at the other end.   The tiered star topology comes with a number of advantages that put it ahead of using a daisy-chaining connection for the peripheral devices.
  • It is incorporated with built-in protection interface that disconnects the connected device immediately in case it comes under the radar of sheer current - more than it can handle. You can use other devices as usual with the disconnection as it won't be affecting other devices in the whole arrangement.
The USB hub comes with an ability to support both low speed and high-speed devices. As the low-speed device is connected with the hub, it will automatically block the full speed transactions, making sure low-speed device doesn't come under the influence of the high-speed signals.
How does it Work
As the peripheral device is connected to a USB host, the enumeration process is activated which is nothing but the process of detecting, identifying and loading drivers for a USB device.
  • It all gets triggered by sending a reset signal to the USB device. Once the connected device is reset, it is assigned a unique 7-bit address by the host.
The reset signaling plays a vital role in determining the data rate of the connected device. No or minimal operator action is involved during this whole process as the configuration starts immediately as you connect the peripheral device, automatically loading the required drivers for the communication between USB host and device.
Advantages
The USB comes with a number of advantages that make it an ideal choice for communication purpose. Yes, parallel and serial ports come handy in some PLC programming and computational purpose, but where communication is required with a decent pace that involves no human interference, USB grooves its way brilliantly. Following are some major advantages of USB over other means of communication.
  • It is a user-friendly and common person with no technical skills can easily get benefit from the sheer advantages of USB protocol. And the flexible interface of USB sets you free from the hassle of using a plethora of connector and wires at the back of your PC, that may turn your working space into a lot of mess.
As you connect the USB peripheral device with the USB hub on the computer, it starts configuration automatically and strives to keep the device quite in line with the working environment of the host, giving you the prompt signal your connected device is ready to use for the required operation. ----- For example, when you connect your phone with the computer, it gets configured automatically. And some phones which don't get connected will give you the option, indicating you need to install the specific driver in order to control the cell phone from your computer.
  • Recent computers come with USB hubs that can easily support 4,5 ports as per your needs. In case your requirements surpass the given ports, you can add external USB hubs to incorporate more ports into the computer.
Low cost and power consumption are remarkable features that make USB stay ahead of its counterparts. It mainly works on 5V with little power consumption around 500 mA for USB 2.0 and 2.5 mA for USB 3.0.
  • As mentioned earlier, the USB comes with a built-in current protection interface that saves the host from going over current that can ultimately put the host in a total stall. The current protection feature blocks the current that gets beyond the recommended ratings.
Limitations
There are some limitations involving the use of USB in terms of bigger perspective. The USB cables are limited in length, making them vulnerable for their use in distant areas.
  • You can benefit USB protocol on the same surface, covering less distance where whole arrangement for communication between the peripheral devices and computer is laid out in a single tabletop surface.
Similarly, the USB converters may not be working as expected with they are connected with some external devices for the transformation of bi-directional data.
  • For example, the USB to parallel port converter supports connection with a printer, but it doesn't work properly with the scanner due to the absence of bi-directional data pins.
That's all for now. I hope I have given you everything you needed to know about USB. If you are unsure or have any question, you can comment me in the section below. I'd love to help you the best way I can. You are most welcome to keep us updated with your valuable suggestions, we shape our content strategy based on them, so keep them coming. Thanks for reading the article.

Introduction to CD4046

Hey Guys! Hope you are doing well. Welcome you onboard. Today, I'll discuss the detailed Introduction to CD4046 which is a Micropower Phase-Locked Loop (PLL) that comes with a common comparator input and a common signal input amplifier between a low-power linear voltage-controlled oscillator (VCO) and two different phase comparators. The phase locked loop, as the name suggests, is a loop where the phase of the output signal is compared with the phase of the input signal using a phase detector between two signals.
  • Phase detector operates with the aim to adjust the two signal and make them quite in line with each other so they generate signals with the same magnitude.
In this tutorial, I'll walk you through the main details related to CD4046 by breaking down the whole nitty-gritty in simple steps, making it easy for you to grab the main concept. Let's jump right in.

Introduction to CD4046

CD4046 is a Micropower Phase-Locked Loop (PLL) that comes with a phase detector for comparing the phase of the output signal with the input signal and adjust them in order to make the matching signals from both ends.
  • It comes with a common comparator input and a common signal input amplifier between a low-power linear voltage-controlled oscillator (VCO) and two different phase comparators.
The input signal can be operated in two ways: capacitively layered with a self-biasing amplifier for creating a small voltage signal or directly coupled for a large voltage signal.
  • The VCO (Voltage Controlled Oscillator) is an integral part of the IC that mainly generates oscillated frequency based on the applied input. The generated frequency is then used for phase modulation.
The chip features two phase comparators i.e. Phase Comparator I and Phase Comparator II. They are also known as Phase Detectors. Phase comparator I is nothing but an exclusive OR gate that produces a digital, maintaining 90° phase shifts at the VCO.
  • It is important to note that both signal input and comparator input are set at 50% duty cycle where Phase Comparator I can lock the input frequencies that match with the magnitude of the VCO center frequency.
Similarly, Phase comparator II is known as an edge-controlled digital memory network and maintains a 0° phase shift between signal input and comparator input, providing a lock-in and digital error signal.
CD4046 Features
Following table shows the main features of CD4046.
Number of Pins 16
Min Supply Voltage 3 V
Max Supply Voltage 18 V
Number of Phase Comparators 2
VCO linearity 1%
Power consumption 70 µW at VCO Frequency= 10 kHz and VDD = 5 V
Technology CMOS Phase Locked Loop
Operating Temperature Range -55 to 125 ºC
  • These ratings will help you make a final decision before you intend to incorporate this device into the relevant project.
CD4046 Pinout
Following figure shows the pinout of CD4046.
  • VSS represents the ground voltage while VDD represents the supply voltage.
  • A 5.2-V Zener diode is added with the aim to supply regulation if required.
CD4046 Pin Configuration
Following table shows the pin configuration of each pin.
Pin# Pin Name Pin Description
1 Phase Pulse Phase pulse applied to the IC
2 Phase Comp I Out An output of Phase Comparator I
3 Comparator IN Input at the Comparator
4 VCO OUT Output Signal at VCO
5 INHIBIT  Allows to electronically turn on or off the output voltage power supply
6 C1A Capacitor 1 connected to VCO
7 C1B Capacitor 2 connected to VCO
8 VSS Ground Pin
9 VCO IN Input Signal at VCO
10 Demodulator OUT Extracting the original signal
11 R1 Resistor 1 connected between VCO and Supply Voltage
12 R2 Resistor 2 connected between VCO and Supply Voltage
13 Phase Comp II OUT Generated oscillated output at Phase II Comparator
14 Signal IN Input Signal applied to the Phase Comparator I
15 Zener 5.2 V Zener diode for voltage regulation
16 VDD Voltage supply pin
 
  • I hope this configuration will help you understand the major functions associated with each pin on the chip.
Absolute Maximum Ratings
Following figure shows the absolute maximum ratings of CD4046.
  • These are the stress ratings above which the device may stop working. Before you start your project, make sure your technical requirements match with the ratings of the device otherwise it may cause more damage than good.
  • As mentioned above DC supply voltage ranges between -0.5 to 18, however it is advised to keep the DC supply between 3 to 15 V for better results, similarly recommended operating temperature range lies from -55 to 125 ºC.
  • The ground voltage is zero unless specifically recommended by the manufacturer.
CD4046 Dimensions
Following figure shows the dimension of CD4046.
  • The dimensions in the numerator are given in inches and dimensions appearing in the denominator are given in millimeters.
  • It is a low weight tiny chip that can easily stand fit in the hard to reach places.
Applications
CD4046 comes with a variety of applications aiming to compare the output signals with the input signals and produce them with the same frequencies. Following are the major applications of CD4047.
  • FSK modulation
  • Voltage-to-frequency conversion
  • Motor speed control
  • FM demodulator and modulator
  • Frequency discrimination
  • Frequency synthesis and multiplication
  • Tone decoding
  • Data synchronization and conditioning
That's all for now. I'll be writing more tutorials on some basic components mainly used in engineering and technology. If you are unsure or have any question, you are most welcome to approach me in the section below. I'd love to help you the best way I can. Feel free to feed us with your valuable feedback and suggestion, so we keep producing quality content and you keep coming back for what we have to offer. Thanks for reading the article.

Introduction to 2n5415

Hi Friends! Hope you are getting along with life pretty well. Today, I'll uncover the detailed Introduction to 2n5415 which is a PNP transistor mainly used for general purpose low-power amplifying and switching applications. It comes with three layers: two P semiconductor layers and one doped N-layer where later is encapsulated between other two P-layers. There are two major types of transistor: Bipolar Junction Transistor and Unipolar Transistor. This transistor falls under the category of Bipolar Junction Transistor as it comes with two charge carriers i.e. electrons and holes where later are the major charge carriers in PNP transistors. In this post, I'll try to nail down everything related to 2n5415: its main features, working, and applications. Let's dive in and explore the nitty-gritty of this electronic component.

Introduction to 2n5415

2n5415 is a PNP transistor that is mainly used for general purpose low-power amplifying and switching applications.
  • It operates on a general amplification principle where small current at one terminal is used to control large current at other two terminals.
The 2n5415 is incorporated with three terminals known as an emitter, base, and collector which are used for external connection with the electronic circuits.
  • These terminals are different in terms of doping concentration and size where a base is lightly doped and is responsible for the transistor action as it controls the number of holes flowing from emitter to collector.
The emitter is highly doped and contains 100% transistor current which then distributes between base and collector.
  • The collector terminal is moderately doped and comes in a bigger size as compared to the other two terminals. It is mainly used to collect the holes emitted from the base terminal.
As the voltage is applied at the base terminal, it gets biased and starts drawing little current which plays a vital role to control large current at the emitter and collector terminals.
  • The base terminal voltage has a large influence on the output current obtained at the collector terminal. This process is used for amplification purpose.
The PNP transistor is a current controlled device, also known as sinking device, where it sinks current into its base terminal and current flows out of the collector.
2n5415 Pinout
Following figure shows the pinout of 2n5415. There are three main parts of the component 1. Emitter 2. Base 3. Collector
  • Holes control the conductivity in this PNP transistor similar to electrons that control the conductivity in NPN transistors.
  • In PNP transistor base is more negative as compared to emitter and collector.
2n5415 Circuit Diagram
Following figure shows the circuit diagram of 2n5415.
  • As mentioned earlier, the emitter terminal is highly doped and comes with 100% transistor current i.e. emitter current is a sum of current at collector and base terminals.
  • When the voltage is applied, holes are diffused through the base from the emitter in this PNP transistor which eventually collected by the collector.
  • Most of the professionals prefer NPN transistor over PNP transistor for amplification purpose because they consider conduction carried out by the movement of electrons is more effective and suitable than conduction carried out by the movement of holes.
2n5415 Absolute Maximum Ratings
Following figure shows the absolute maximum ratings of 2n5415.
  • These are the stress ratings which directly affect the execution of electronic circuit. If these stress ratings are exceeded from absolute maximum ratings, they can damage the device at large, ultimately affecting the overall nature and performance of the project.
Similarly, if these ratings are applied for the maximum period of time above normal operating conditions they can affect the reliability of the device.
  • It is preferred to examine these ratings before placing the device in the circuit and make sure the device follows the same stress ratings as defined by the manufacturer.
Applications
  • It is widely used in general purpose low-power amplifying circuits.
  • Many switching applications are incorporated with this transistor.
That’s all for now. I hope I have given you valuable information regarding this PNP transistor. If you are unsure or have any question, you can ask me in the comment section below. I’d love to help you in any way I can. You are most welcome to keep us updated with your valuable feedback and suggestions, so we keep producing quality content and you keep coming back for what we have to offer. Thanks for reading the article.
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir