Analog Flex Sensor Library for Proteus

Hi Friends! Happy to see you here. Thank you for viewing this read. Hope you’re well today. In this post, I’m going to discuss the Analog Flex Sensor Library for Proteus. You should also have a look at Digital Flex Sensor Library for Proteus. I’ve been adding them over the last few days intending to design and share brand new libraries that are not a part of the proteus library database already. I’m adding both simple simulation and simulation with the Arduino board to help you better understand these libraries with microcontrollers and Arduino devices. Before I go further and walk you through on how to download and simulate Analog Flex Sensor Library for Proteus, let’s get to know what’s Flex sensor first. Simply put, a flex sensor is used to monitor the value of bend. It is also known as a bend sensor that is mainly used in robot whisker sensors, door sensors, stuffed animal toys, and Nintendo power glove. The flex sensor is coupled with the exterior where the rotation of this exterior is directly related to the change in the sensor resistance. Carbon or plastic material is used for the construction of these sensors where deflection value is sensitive to varying resistance. In terms of varying resistance and size, these sensors are categorized into two main types i.e. 4.5-inch bend sensor and 2.2-inch bend sensor. I hope you’ve got a brief insight into what is flex sensor and why it is used for. You can also sneak into the Analog PIR Sensor Library for Proteus that I’ve shared previously. And if you don’t have proteus software installed in your system, check this post on how to download and install proteus software. Without further ado, let’s jump right into the Analog Flex Sensor Library for Proteus. Continue reading.

Analog Flex Sensor Library for Proteus

First of all, click the link given below to download the analog flex library for proteus. Analog Flex Sensor Library for Proteus As you download this file, it contains two folders named Proteus Library and Proteus Simulation. Click the Proteus Library, it will open up four files that read:
  • FlexSensorAnalogTEP.HEX
  • FlexSensorTEP.HEX
  • FlexSensorTEP.IDX
  • FlexSensorTEP
Copy and place these four files into the proteus library folder. Now, click the ‘P’ button as below and write ‘Flex sensor analog’ in the search bar. As you do this, it will return the file as mentioned below.
  • Select this file and click “OK” As you click OK, your cursor will start blinking with the flex sensor, indicating you can place this sensor anywhere you want on the proteus workspace.
When you place this sensor on the proteus workspace, it will appear as follows: This is how flex sensor appears on proteus workspace.

Flex Sensor Pinout

Flex sensor contains four pins as follow:
  • G = first is the ground pin that you’ll connect to the ground voltage.
  • O = second is the OUT pin that gives the Flex sensor value demonstrating if the sensor has identified the value of bend.
  • V = third is the voltage supply pin that receives 5V to power the sensor.
  • TestPin = forth is TestPin that we require in Proteus simulation only. This pin is not included in the sensor in real. We need to add this pin for identifying the value of bend. When this Pin is HIGH it gives the value of bend and when it turns LOW it gives no value of bend.

Adding HEX File

Now we’ll add the HEX file in the Flex sensor to run our simulation. You can find FlexSensorAnalogTEP.HEX file in the library folder of your Proteus library folder. Recall, we’ve already placed this file in the library folder of proteus.
  • To add this file, right-click on the sensor and look for ‘edit properties.’
  • You can also double click the flex sensor to reach the ‘edit properties’ panel.
Now search for the HEX file that you have placed in the proteus library folder. Add this file and click ‘OK’ … Before you run this simulation we need to design and connect the LC circuit with the Flex sensor. We’ll add this circuit purposely. Why? You’ll get to know later in this post. Connect the Output ‘O’ pin with the LC circuit through voltmeter where we get the output voltage following the variable resistor attached with the test pin.
  • Both output voltage across voltmeter and variable resistance are inversely proportional to each other. When resistance is maximum, the voltage on the voltmeter is zero, thus indicating no amount of bend.
And when resistance is zero the voltage appearing across a voltmeter will be 4.98V, confirming the value of bend as an output voltage on the flex sensor. You may be wondering why we add this LC circuit with the flex sensor? We need to include this circuit because proteus gives a peak to peak value that we have to convert into the Vrms value. That LC circuit serves this purpose. You’ve done it. You have designed a simple simulation of a flex sensor library for proteus. We have added this library the very first time, as you won’t find this library in the proteus library database before. I’ve mentioned at the start of the article, I’ll share both simple simulation and simulation with Arduino Board.

Analog Flex Sensor With Arduino UNO

Now we attach the Arduino board with the flex sensor. To do this, we connect the voltage appearing across the voltmeter with the analog input pin of the Arduino board. As you run this simulation it will return the result below. Again, when resistance is maximum, the voltage is zero, that gives equivalent analog value on the LCD connected with the Arduino board, that value is 0019. And when resistance is zero, the voltage will be 4.98V and its equivalent analog value on the LCD will appear 1019. That’s all for today. Hope you find this read helpful. If you face any difficulty in the simulation of Analog Flex Library for Proteus, you can leave your query in the section below, I’ll help you the best way I can. Feel free to leave your suggestions of the libraries that are not available in the proteus library database, I’ll design and share respective libraries with both simple simulation and simulation with Arduino boards. Thank you for reading this post.

Soil Moisture Sensor Library For Proteus

Update: We have created a new version of this library, which you can check here: Soil Moisture Sensor Library for Proteus V2.0.

Hi Friends! Hope you’re well today. I welcome you on board. In this tutorial, I’ll be discussing the Soil Moisture Sensor Library for Proteus. You won't find Soil Moisture Sensor Library in Proteus and we’re going to share its Proteus Library very first time. I have previously shared many Proteus Libraries for digital and analog sensors and today I’m discussing something new. Excited to get a hold of the Soil Moisture Sensor Library? Me too. In the upcoming days, I’ll keep sharing different libraries related to sensors. If you’re curious to sneak into the nitty-gritty of sensors not available in the Proteus library already, pop your suggestion in the comment section below. I’ll try my best to comply with your suggestions and walk you through something brand new.

Soil moisture sensors are used to measure the water content in the soil. They use capacitance to measure the dielectric permittivity of the soil which defines the function of the water content. Before further ado, let’s dive in and have a look at How to download and simulate Soil Moisture Sensor Library for Proteus:

Where To Buy?
No.ComponentsDistributorLink To Buy
1LCD 20x4AmazonBuy Now
2Arduino UnoAmazonBuy Now

Soil Moisture Sensor Library For Proteus

  • You can download the Proteus Library zip file of Soil Moisture Sensor Library by clicking the button below.
Download Proteus Library Files
  • It’s a .zip file that contains two folders inside i.e. Proteus Library & Proteus Simulations.
  • The real fun starts right here right away.
  • Open proteus library folder that contains three files named:
    • SoilMoistureSensorTEP.IDX
    • SoilMoistureSensorTEP.LIB
    • SoilMoistureSensorTEP.HEX
  • Copy and paste these three files in the Library folder of your Proteus software:
  • Now, we need to run the Proteus ISIS software and don't forget to restart, if it's already open.
  • Look for the Soil Moisture in the component’s search box as shown below.
  • After installing the Library successfully, you’ll get similar results as below:
  • You can see in the figure above we have one Soil Moisture Sensor.
  • Now simply place this Soil Moisture Sensor in your Proteus workspace, as mentioned below:
  • You can see in the figure above, I have placed one Soil Moisture Sensor inside the Proteus workspace.
  • This sensor carries 4 pins in total, named:
  • V (Vcc): We’ll provide +5V here.
  • G (GND): We’ll provide ground here.
  • Ao (Out): It’s an analog output signal from the sensor.
  • TestPin: It is used for simulation purposes only. Soil Moisture Sensor doesn’t contain this pin in real.

Adding Sensor’s Hex File

  • After this drill, we’ll add the Sensor’s Hex File, which we have downloaded and placed in the Library folder.
  • To do that, right-click on your Soil Moisture Sensor and then click on “Edit Properties” as below:
  • Or you can double click the Soil Moisture Sensor, it will pop the window below:
  • Click on the Browse button and add SoilMoistureSensorTEP.HEX file available in the Proteus Library section as shown in the figure below:
  • After adding the Sensor’s Hex File, click on the ‘OK’ button to close the ‘Edit Properties’ Panel.
  • Our Soil Moisture Sensor is now ready to simulate in our Proteus ISIS.
  • We’ll design a small circuit to thoroughly understand the working of this Soil Moisture Sensor.

Proteus Simulation of Soil Moisture Sensor

  • Here, I’m designing a simple circuit. I’ve attached a variable resistor with the Test Pin & added a Voltmeter at the Output pin, as shown in the figure below:
  • This resister defines the soil water content in the proteus simulation.
  • When the resistance is maximum at the test pin, the circuit shows zero volts across the voltmeter, which means the sensor is either in the dry ground or taken out of the ground i.e. giving zero moisture value of the water content.
  • And when resistance is zero, the circuit will show the maximum voltage across the voltmeter which indicates the sensor is inserted in a wet ground i.e. water contents in the soil are too high.
  • This is important. We have attached the output pin with an LC filter. This filter is not required in real hardware implementation.
  • We are using it in Proteus Simulation only as Proteus gives the peak-to-peak value and we have to convert that PP value into Vrms.
  • If you are working on a real sensor then you don’t need to add this LC circuit.
  • Now, let’s run this Proteus Simulation and if you have done everything as mentioned, it will show the result mentioned in the figure above.

Simulation of Soil Moisture Sensor with Arduino

Now, let's interface this sensor with a microcontroller.
  • We have attached the output of the sensor appearing across the voltmeter with the A0 pin of the microcontroller as below.

You can see we get the analog value 1019 when the voltage across the voltmeter is 4.98V

This is it. I hope you find this tutorial helpful. This will help engineering students in simulating their semester projects in proteus. In the next tutorials, I’ll be sharing and adding more libraries of sensors. You’re most welcome to share your suggestions with the sensors you want me to libraries of. If you’re unsure or have any questions, you can ask me in the section below. I’ll help the best way I can. Thank you for reading this article.

IR Proximity Sensor Library for Proteus

Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new IR Proximity Sensor Library for Proteus. Proximity Sensors are not available in Proteus and we are sharing its Proteus library for the first time. So far, I have only shared Proteus Libraries of digital sensors but today I am sharing an analog sensor, so too excited about it. In the next few days, I will keep on sharing Proteus Libraries of different analog sensors, so if you want any sensor in Proteus, then let me know in the comments. IR Proximity Sensors are used to detect hurdles/obstacles placed in their path. They are normally used on robots for path navigation and obstacle avoidance. So, let's have a look at How to download and simulate IR Proximity Sensor Library for Proteus: Note:

IR Proximity Sensor Library for Proteus

  • First of all, download this IR Proximity Sensor Library for Proteus, by clicking the below button:
IR Proximity Sensor Library for Proteus
  • It's a .zip file, which will have two folders in it i.e. Proteus Library & Proteus Simulation.
  • Open Proteus Library Folder, it will have 3 files, named as:
    • IRProximitySensorTEP.IDX
    • IRProximitySensorTEP.LIB
    • IRProximitySensorTEP.HEX
  • Place these three files in the Library folder of your Proteus software.
Note:
  • After adding these library files, open your Proteus ISIS software, or restart it if it's already open.
  • In the component's search box, make a search for IR Proximity.
  • If you have installed the Library successfully, then you will get similar results, as shown in the below figure:
  • As you can see in the above figure that we have two IR Proximity sensors.
  • When it comes to functionality, both sensors are exactly the same, they just have different colors.
  • Now simply place these IR Proximity Sensors in your Proteus workspace, as shown in the below figure:
  • As you can see in the above figure, I have placed both of these IR Proximity sensors in my Proteus workspace.
  • This sensor has 4 pins in total, which are:
    • V ( Vcc ): We need to provide +5V here.
    • G ( Gnd ): We need to provide Ground here.
    • O ( Out ): It's an analog output signal from the sensor.
    • TestPin: It's solely for simulation purposes, we don't have this pin in a real IR sensor.
  • As we can't actually place an obstacle in front of this sensor in Proteus simulation, that's why I have used this TestPin.
  • If we change the value of TestPin from 0V to 5V then that means the obstacle is coming close.

Adding Sensor's Hex File

  • Lastly, we need to add the Sensor's Hex File, which we have downloaded and placed in the Library folder.
  • So, in order to do that, right-click on your IR sensor and then click on Edit Properties.
  • You can also open the Properties Panel by double-clicking on the sensor.
  • Here, in the Properties Panel, you will find Sensor's Hex File Section.
  • Click on the Browse button and add IRProximitySensorTEP.HEX file here, as shown in the below figure:
  • After adding the Sensor's Hex File, click on the OK button to close the Properties Panel.
  • Our IR Proximity Sensor is now ready to simulate in Proteus ISIS.
  • Let's design a small circuit, in order to understand the working of this IR Proximity Sensor.

Proteus Simulation of IR Proximity Sensor

  • First of all, let's design a simple circuit, where I am attaching a variable resistor with the Test Pin & I am adding a Voltmeter at the Output pin, as shown in the below figure:
  • Using this variable resistance, we can change the voltage on Test Pin.
    • If TestPin has 0V, means we don't have any obstacle in front of the sensor.
    • If TestPin has 5V, implies that something's placed right in front of the sensor.
  • So, let's have a look at How the output value will change when we change the voltage on TestPin.
  • At the Output Pin, I have placed an LC filter, which is also not required in real hardware implementation.
  • But I have to use this filter in Proteus Simulation, as Proteus provides the Peak to Peak value and we need to convert that value into Vrms.
  • So, if you are working on a real sensor then you don't need to add this inductor or capacitor.
  • Now, let's run this Proteus Simulation and if you have done everything correctly, then you will get similar results:
  • I have shown three different scenarios in the above figure:
    • In the first image, the variable resistor is at 100%, thus providing 0V at TestPin. That's why we got 0V at Output and hence no obstacle detected.
    • In the second image, the variable resistor is around 50%, thus providing around 2.5V at TestPin. So, we are getting around 2.5V at Output and hence obstacle detected in close range.
    • In the third image, the variable resistor is around 0%, thus providing around 5V at TestPin. So, we are getting around 5V at Output and hence obstacle's just in front of the sensor.
  • I have placed this simulation in the above zip file, so play with it and don't forget to add the Sensor's Hex File.
So, that was all for today. I hope this IR Proximity Sensor Library will help engineering students in simulating their course projects. I will interface this IR sensor with Arduino and other Microcontrollers and will share their simulations. If you have any issues, then ask in the comments and I will help you out.

Introduction to Arduino Zero

Hello friends, I hope you are all fine will be doing something interesting in your life. In today's tutorial, we are gonna have a look at detailed Introduction to Arduino Zero. Arduino Zero is a Microcontroller device. It is a 32-bit extension of UNO series. Its main features are Atmel Embedded Debugger (EDBG), it provides a full debug interface without additional hardware. This board provides a platform of new inventory projects in smart IoT devices, high technology automation, robotics and much more. As, Electronic devices coming in our life, they have become cheaper and performing more functions then there predecessor. The microcontroller was introduced in the industry to make our task easy in electronic devices and projects. Arduino Zero is a valuable addition in the electronics industry. It providing the improvement in Arduino role in our projects. In today's I will explain about Its pinout, projects, working, protocol, etc. So let's started with Introduction to Arduino Zero.

Introduction to Arduino Zero

  • Arduino Zero is a microcontroller board, based on Atmel SAMD21G18U ARM CORTEX MO+CPU. It is simply a 32 bit extension of Arduino UNO series.
  • It has 20 input-output pins (10 can be used PWM output), it also has six analog inputs, 2 UARTs, 48 MHZ clocks, 1 digital to analog converter (DAC), one SPI reader, one TWI and reset button.
  • One of the most important functions of it is that (EDGB), Which provide full debugging without any external hardware. EDGB also support a virtual com port that can be used for boat loader programming.
  • It allows the designer to control electronic devices in a comprehensive way. AC to DC adopter can also be used to power the board.
  • Arduino Zero boards are quite similar to other boards in the Arduino family in terms of use and functionality.
  • It can operate on external supply 6 to 20 volts. But if we supply below six volts it becomes unstable and if the voltage is greater then 12, the voltage regulator is overheating and may damage the board.
Now, let's discuss the pinout of Arduino Zero PINOUT:

Arduino Zero PINOUT & Description

There are main twenty pinouts of Arduino Zero, let's discuss which are most important and mostly used.
No.  Pin Name  Description
01 SCL SCL is a clock line. It uses to synchronized data on a protocol which it uses. It works on the I2C protocol.
02 SDA SDA is a line at which data is transferred by the serial way.
03 AREF AREF stand for Analogue reference. It used to supply Arduino reference voltage.
04 GND This pin is used for ground purposes.
05 TX/D1 This pin used for transmission of data.
06 RX/D0 This pin is used for receiving data
07 AD0 It used for analog to digital conversion.
08  IOREF This pin is used for input, output voltage reference purpose. For example, an Arduino would supply 5 v to this pin, but a due would supply 3.3 v. Sending a signal to this pin does nothing.
09 3.3 V  This pin is used for 3.3 v supply to Arduino.
10 REST This pin is used for resting of Arduino.
11 VUSB This is a USB port.
12 VIN At this pin, we supply input voltage to Arduino.
13 AO/DAC This is used for analog to digital conversion of the signal.
14 GND This is two ground in Arduino Zero, this one is second
15 PROGRAMMING PORT This pin is used for the feeding of programming to Arduino.
16 SUPPLY CONNECTOR This pin is used for 2.1 mm supply connector.
17  MCU  This pin is used to interface other microcontrollers with Arduino.
  [otw_is sidebar=otw-sidebar-5] Now, Let's discuss the specifications of Arduino Zero.

Features & Specifications of Arduino Zero

These are some specification of Arduino Zero:
  • Arduino Zero is a SAMD 21 Cortex M0+ 32bit low power ARM microcontroller.
  • Its board Power Supply (usb.in) is 5 volts.
  • DC current we can apply at the 3.3v pin is 600 mA.
  • DC current for the 5-volt pin is 600mA.
  • Its circuit operating Voltage is 3.3V.
  • Total digital input and output pins are 22.
  • Its PWM Pins  are 12 (0, 1, 2, 3, 4, 5, 6, 7, 8, 10, A3 - or 18 -, A4 -or 19).
  • It's flash memory is 256 KB.
  • It has flash memory for boot-loader is 8 kb.
  • It has SRAM of  32 KB.
  • Its Clock Speed is 32.768 kHz (RTC), 48 MHz.
  • Its supported battery is Li-Po single cell, 3.7 V, 700 mAh minimum.
  • It's Analog Input Pins are  6, 12-bit ADC channels
  • It's Analog Output Pins are 1 to 10-bit DAC.
  • There is no use of EEPROM.
  •  Its LED BUILTIN is at pin no 13.
For a better understanding of Arduino Zero, we discuss its use in project By an example.

Zero Drive

Lets discuss project of Arduino Zero.
  • Zero Driver is basically an Arduino Zero compatible dual motor driver board for mechatronics engineering projects and different types of industrial robots.
  • In robotic projects required two board, one is a microcontroller and other is a separate driver for a motor. Zero Driver combines both in one for our convenience.
  • Zero drivers come with the same microcontroller as an Arduino Zero 48 MHZ ARM cortex M0+ chip, which is better than any other an entry-level Arduino Uno.
  • For better understand how this work lets see a picture of zero drive.

Application of Arduino  Zero

These are some applications of Arduino Zero. We can use it as a parking Lot Counter.
  • It can be used in security and Defense System.
  • It is used in Digital Electronics and Robotics.
  • It is used in Weighing Machines.
  • It is used in Traffic Light Count Down Timer.
  • we can also use it in Medical Instrument.
  • It is also used in Emergency Light for Railways.
  • It is also used in Home Automation.
So, friends, this was all about Arduino Zero. If you any question regards it, you ask in comment box. I will resolve your queries. Thanks for reading. Take care until next post...

PC817 Library for Proteus

Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new PC817 Library for Proteus. PC817 is an optocoupler / optoisolator, which is used for electrical isolation between components or modules. It's normally used after Microcontroller Pins so that back emf doesn't burn them. You should also have a look at Introduction to PC817, I have shared its complete details there. PC817 is used a lot in Embedded projects but is not available in Proteus, so our team has designed it for the first time. Using this Library, now you can easily simulate this optocoupler in your Proteus simulations. So, let's get started with How to download & install PC817 Library for Proteus:

PC817 Library for Proteus

  • First of all, download this PC817 Library for Proteus by clicking the below button:

[dt_default_button link="https://www.theengineeringprojects.com/ArduinoProjects/PC817 Library for Proteus.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 Library[/dt_default_button]

  • It's a zip file, which will have a Proteus Library folder.
  • Open this folder, and you will find these 2 Library files in it:
    • OptocouplersTEP.IDX
    • OptocouplersTEP.LIB
  • Place these Library Files in the Library folder of your Proteus software.
Note:
  • Now open your Proteus ISIS software or restart it if its already open.
  • In the components search box, make a search for PC817.
  • If everything goes fine, then you will get results as shown in below figure:
  • Now place this PC817 in your workspace.
  • Default optocoupler available in Proteus contains 5 Pins but this PC817 has 4 Pins, as shown in below figure:
  • I have shown both optocouplers in above figure.
  • Now let's design a simple circuit to have a look at How it works:
  • So, connect three LogicState and one LED with PC817, as shown in below figure:
  • Now run your Proteus Simulation and change the states of your buttons.
  • Both On & Off states of PC817 are shown in below figure:
  • So, that's How you can easily simulate PC817 in Proteus.
I hope this PC817 Library will help you in your Engineering Projects. If you got into any trouble, then ask in comments and we will help you out. Thanks for reading, take care and have fun !!! :)

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.

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.
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