Regulated Power Supply Using LM317

Hello geeks, welcome to our new project. We are going to make an important project which will be very useful for us in our daily life which is a variable DC power supply. As engineers who work with electronics need different voltage ranges of DC power supply for different electronic projects and components. It becomes very clumsy and hard to manage different power supplies because of wires which are connected to it and each power supply consumes an extra power socket as well.

So in this project, we will overcome this issue and learn to make an adjustable DC power supply, in which we will get a wide range of voltages.

Software to install

We will make this project in the simulation, as it is a good practice to make any project in the simulation first so that if we do any mistakes or errors in the circuit, which can be corrected without making any physical damage to actual components.

To make this project we will be using the Proteus simulation tool. A brief about the Proteus, it is a simulation software for electronics, here we can make different types of electronic circuits and run the simulation and it will give us the real-time working model of our circuit. Also, we can easily debug in case of a wrong connection.

It has a very large database of pre-installed components which has basically all types of different electronic components and in case, if it is not pre-installed, then we can install a library for those.

Components Required

  • One Step down transformer
  • Five 1N4007 Diodes
  • One 4700 microFarad Polarised capacitor
  • One 100 microFarad Polarised capacitor
  • Three 0.1 microFarad non-polar capacitors
  • One 5 kOhms potentiometer
  • One 220 Ohms resistor
  • One LM317 IC

Components details

1. LM317

  • It is a voltage regulator IC which has a wide range of applications in various voltage limiting circuits.
  • It has three terminals as Vin, Vout, Adjust.
  • Using these three pins only we can regulate the output voltage.
  • As the name suggests, the Vin pin is used for the input power supply, the Vout pin is used to take the output voltage, and Adjust pin is used to control the output voltage.
  • It is a very easy-to-use IC, it requires only two resistors for the circuit and it will be ready to use.
  • It uses one resistor for the RC filter and one as a potentiometer to adjust the output voltage.
  • As per the datasheet, it has a formula for calculating output voltage, and using that we can adjust our resistor value as per our requirement of output voltage.
 
  • For more details about this IC prefer the following datasheet:

2. Step down Transformer

  • Step down transformer is used to convert the high input voltage to low voltage.
  • It takes high voltage and low current as an input and it will give low voltage and high current as an output.
  • Here we will not go in-depth about the working of transformers but in brief, it has two windings as primary and secondary.
  • It is the exact opposite of the Step-up transformer as per the use case and windings.
  • In this type of transformer, there are more turns on the primary side winding and lesser turns on the secondary side winding.
  • It is mostly used in power supplies.

3. Diodes

  • Diodes are two-terminal simple electronics components.
  • It works as a valve which allows the flow of current in only one direction and limits the flow of current in another direction.
  • They are used mostly in every electronic device such as in power supply or as regulators or used in construction ICs for logic gates.
  • It has two terminals as Anode and Cathode and current is allowed to flow from Anode to Cathode side only.
  • As per the construction, it has two sides P side and N side.
  • The P side terminal is also known as Anode and the N side terminal is known as Cathode.
  • A simple PN type diode is made using the P-type and N-type semiconductors.
  • In N-type semiconductors, free electrons are in majority, and in P-type semiconductors, holes are in majority.
  • There are various types of diodes available but as per our use case, we will use a simple PN junction type diode.
  • We are using the diodes as rectifiers in this project.

4. Capacitors

  • Capacitors are electronic components that have the ability to store energy.
  • It has two terminals that are connected with two parallel conductor plates and they are separated from each other with an insulating material called dielectric material.
  • When we apply voltages across the terminals then due to generated electric field, it stores energy in the form of electric charges.
  • We have used capacitors in this project for filtering purposes.
  • There are various types of capacitors as per the use case in this project we have used the non-polarized and polarized capacitors.

5. Potentiometer

  • It is a passive electronic component using which we can vary the output voltage by changing the resistance.
  • Basically, it is a variable resistor in which we change the resistance by moving a nob.
  • It has three terminals as Vcc, Ground, and Vout.
  • There are two types of potentiometers. First is the Rotary potentiometer and the second is the Linear potentiometer.
  • In this project, we have used a rotary potentiometer.
  • The main application of a potentiometer is a voltage divider. And using this characteristic, it is used in various types of applications such as speed controlling of motors, volume control in audio systems, etc.

Project Overview

In this project, we will use the following components-

  • LM317 - We will be using this IC as the main controller of our project, using this we will regulate the voltage of the power supply.
  • Diodes - These are very important components for any DC power supply as they will change the AC supply to DC supply.
  • Step down Transformer - This will be used as an isolator and it will lower the input voltage.
  • Capacitors - These are used for smoothening the pulses and making the noise-free power supply.
  • Potentiometer - It is used as a regulator to set the output DC voltage.

Now we know the basic role of each component, so let's talk about how actually our power supply will work. In brief, the flow of our power supply will be as mentioned further.

We connect it with AC power then we will lower down the AC supply to 12-24 AC because most of the electronic component has this working voltage range, thereafter we will change the AC to DC and do the smoothening of that DC supply, and then we will regulate that using a potentiometer and LM317 IC.

  • To step down the AC voltage we have used the Step-down transformer and it will also isolate the AC circuit with the DC circuit although there are ways to step down the power without using the transformer also.
  • After that, using the diodes we will make a full-wave bridge rectifier. It will change the AC power to DC but still, it will have some ripple from the AC supply.
  • To smoothen the ripples from the AC supply we will use the RC filters, where we will connect some capacitors.
  • Now we will have the smooth DC supply that we will use as input power for LM317 IC and a potentiometer will be connected to it.
  • Using that potentiometer, we will change the output voltage.

Circuit Diagram and Working

Now we know all the components which we will use in this project and their use cases also. Let's start connecting them.

  • Start the new project in the Proteus software and import all the required components to the workplace.
  • Now, we have all the listed components in the workplace.
  • First, connect the AC power supply with the Step-down transformer primary winding.
  • On the secondary winding of the transformer, we will connect the full-wave bridge rectifier which we will make using the diodes. They are simple 1N4007 diodes.
  • First, we will make two pairs of diodes by connecting two with each other.
  • In the first pair, we will connect the Anode of two diodes with each other and leave the other two terminals free.
  • Then in the second pair, we will connect the Cathode of two diodes with each other and leave the other two terminals.
  • Now we have two free terminals in each pair, and we will connect them with each pair.
  • If you are working with real components, just remember there will be a grey color stripe on the diode so that side will be Cathode and another side will be Anode.
  • In simple words just take two diodes, connect the grey strip side of them with each other, then take another two diodes and connect the black side with each other, and after that connect them with each other.
  • It is very important to connect the diodes very carefully otherwise our power supply will not work.
  • And in case of wrong connections, it will flow the AC current in our circuit and that would be very dangerous.
  • Now we have completed our full-wave bridge rectifier so now connect the input side of that with the secondary side of the step-down transformer.
  • And connect two capacitors parallel to the output side of the rectifier. That is used for smoothening the output power.
  • One 4700 microFarad capacitor and a 0.1 microFarad capacitor.
  • While connecting the polar capacitor keep the terminals in mind.
  • Connect the positive terminal of the capacitor with the positive side of the rectifier and the negative side with the negative side of the rectifier.
  • In the polar capacitor, the longer terminal is positive and the shorter side is negative.
  • Now let's connect the LM317 IC with the circuit.
  • As we know LM317 has three pins so connect the Vin pin of IC with the positive terminal output of the rectifier.
  • Now connect the Adj pin of IC with the potentiometer and Vout of IC will be the output of the power supply.
  • We will use some more resistors and capacitors for filtering purposes.
  • Connect two capacitors parallel with the output of LM317 and one RC filter also with it.
  • At last, connect a diode from the output of LM317 with the input side of LM317 that will prevent the flow of reverse voltage. It is for simple protection.
  • Now we have completed the connection of our circuit. For debug purposes, connect a voltmeter at the end so that it will be easy to check the working of the power supply and we can monitor the change in the output voltage by changing the value using the potentiometer.

Results and Working

  • Now run this project.
  • At first, AC high voltage will be converted to low voltage AC.
  • As we know AC power is a sine wave and DC power is a straight line. It does not travel as a sine wave.
  • That will be converted by the full-wave bridge rectifier. We know that diodes allow the flow of current only in the forward bias. This means only half of the cycle of the sine wave will pass through it, that is when the sine wave is in a positive direction.
  • So to overcome this problem, we have used the diodes as full-wave bridge rectifiers.
  • When the AC sine wave will be in the positive half cycle, the diodes D2 and D3 will be in forward bias, thus they will let the current flow. But D4 and D5 will be in reversed bias so they will not allow the current to flow.
  • And when the AC sine wave will be in the negative half cycle, the diodes D2 and D3 will be in reversed bias, and diodes D4 and D5 will be in forward bias and that is how current will flow here. Thus, we will get the current in a full sine wave.
  • So the output of the full-wave bridge rectifier will be like the following image:
  • But still, this wave is not a DC current, so to make it a smooth DC current we have used the capacitors.
  • When the wave goes upward, at that time, the capacitors store the charge but when the wave goes downward, then the capacitors start discharging, and while discharging they maintain the output voltage and let the current flow.
  • But this will make some ripples and to neutralize that, we have used another capacitor that will do the same charging-discharging process and after that, we will have a straight line of pure DC power.
  • Now DC power will go into the LM317 regulator IC. Thereafter when we change the value from the potentiometer, we can see the output voltage will change on the voltmeter which is connected to the output side.
  • We can see in the following image when the value of the potentiometer is 4% then the output voltage is 2.40 volts
  • Let’s change the value of the potentiometer.
  • After changing the value of the potentiometer to 52%, we can see that output voltage is also changed to 14 volts.
  • As we can see that output voltage changes by changing the value of the potentiometer which means our regulated power supply is working well.

Conclusion

I hope we have explained all the points related to this project. And I hope this will be a very useful project for your daily use as a power supply.

Please let us know if you face any issues while making this project in the comment section below.

We will be happy to know if you will make this project and how you are going to use it in your daily life.

Thanks for reading this article and All the best for this project, see you in the next one.

Motion Detection with ESP32 & PIR Sensor

Hello readers, we hope you all are doing great. Welcome to the 4th lecture of Section 5(ESP32 Sensor) in the ESP32 Programming Series. So far, we have discussed the ESP32 built-in sensors in this section. Today, we are going to interface an external embedded sensor(i.e. PIR Sensor) with the ESP32 Microcontroller board. At the start, we will discuss the basics of a PIR Sensor(HC-SR501) i.e. its pinout and working. After that, we will design a simple project to detect the motion with a PIR sensor and ESP32. Finally, we will display the motion detection results on the ESP32 WebServer.

We will use ESP32 interrupts to detect the motion. Interrupts are used when a microcontroller needs to continuously monitor an event while executing other tasks at the same time. We have already posted a tutorial on ESP32 Interrupts, which includes both software and hardware interrupts. In this tutorial, we are implementing the hardware interrupt(Hardware interrupts are the external interrupts that are caused by an external event). In our project, the hardware interrupt will be generated by the PIR sensor.

PIR motion sensor is mostly used in home automation & security projects, used to enable the system to respond automatically over human presence. Appliances connected to ESP32 will respond automatically(as per the instructions provided) whenever an interrupt is triggered by the PIR motion sensor. Let's first have a look at the working of PIR Sensor:

Where To Buy?
No.ComponentsDistributorLink To Buy
1ESP32AmazonBuy Now

What is a PIR Motion Sensor?

In today's project, we will use the HC-SR501 PIR Sensor to detect the motion. PIR stands for Passive Infrared sensors. It uses a pair of pyroelectric sensors to detect heat energy in the surrounding environment. Both the sensors sit beside each other, and when a motion is detected or the signal differential between the two sensors changes the PIR motion sensor will return a LOW result (logic zero volts). It means that you must wait for the pin to go low in the code. When the pin goes low, the desired function can be called.

PIR Sensor Calibration

PIR Sensor has two variable resistors on its back side, used to adjust the Sensitivity and Detection Range, explained below:

  • Low sensitivity ignores the small motions i.e. a moving leaf or a small mouse. The sensitivity can be adjusted based on the installation location and project requirements.
  • The second resistor is used to specify how long the detection output should be active. It can be set to turn on for as little as a few seconds or as long as a few minutes.

PIR Sensor Applications

Thermal sensing applications, such as security and motion detection, make use of PIR sensors. They're frequently used in security alarms, motion detection alarms, and automatic lighting applications.

Now let's interface the PIR Sensor with ESP32:

Interfacing PIR Sensor with ESP32

As I mentioned earlier, in today's project, we will design a motion detection project with ESP32 and PIR Sensor. In the first example, we will turn "ON" the LED on motion detection, while in the second project, we will display the results in the ESP32 WebServer.

Here's the list of the components for today's project:

Components Required

  • ESP32 Development Board
  • PIR motion sensor (HC-SR501)
  • LED
  • 1k Ohm resistor
  • Jumper Wires
  • Breadboard

Circuit Diagram

Here's the circuit diagram for motion detection with ESP32 and PIR Sensor:

Now let's design the programming code for motion detection:

ESP32 Motion Detection Code

We are using Arduino IDE to compile and upload code into the ESP32 module. You need to first Install ESP32 in Arduino IDE to get started. Here's the code for motion detection:

//----Set GPIOs for LED and PIR Motion Sensor
const int led = 23;
const int PIRSensor = 4;

// -----Timer: Auxiliary variables
#define timeSeconds 10
unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

//---Checks if motion was detected, sets LED HIGH and starts a timer
void IRAM_ATTR detectsMovement()
{
    Serial.println( " MOTION DETECTED " );
    Serial.println("Turning ON the LED");
    digitalWrite(led, HIGH);
    startTimer = true;
    lastTrigger = millis();
}

void setup()
{
    Serial.begin( 115200 ); // Serial port for debugging purposes
    pinMode( PIRSensor, INPUT_PULLUP ); // PIR Motion Sensor mode INPUT_PULLUP
    pinMode( led, OUTPUT );
    digitalWrite( led, LOW );
    attachInterrupt( digitalPinToInterrupt( PIRSensor ), detectsMovement, FALLING ); // Set PIRSensor pin as interrupt, assign interrupt function and set RISING mode
}

void loop()
{
    now = millis();
    if( startTimer && (now - lastTrigger > ( timeSeconds*500)))
    {
        Serial.println(" Turning OFF the LED " );
        digitalWrite( led, LOW );
        startTimer = false;
    }
}

Variables Declaration

  • The first step is to set up the GPIO pins for the LED and motion sensor(PIR).
  • LED is connected to GPIO23 and PIR sensor to GPIO4, as shown in the below code:
//----Set GPIOs for LED and PIR Motion Sensor
const int led = 23;
const int PIRSensor = 4;
  • Next, we need variables to set the timer to count the time, after the interrupt is detected.
  • The variable "now" defines the current time
  • The variable "lastTrigger" defines the time when the interrupt is detected.
  • The variable "startTimer" is used to start the time when an interrupt is detected.
//-----Timer: Auxiliary variables
#define timeSeconds 10
unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

ESP32 Interrupt Function "IRAM_ATTR"

  • The Function with the attribute "IRAM_ATTR" is executed inside the internal RAM.
  • We are assigning this attribute to our interrupt function because RAM (random access memory) operates faster than flash memory.
  • After the execution of the interrupt code or ISR, the normal code will be executed inside the flash memory.
  • It is recommended that the interrupt service routine should have the minimum possible execution time because it halts or blocks the normal program execution.
//---Checks if motion was detected, sets LED HIGH and starts a timer
void IRAM_ATTR detectsMovement()
{
    Serial.println( " MOTION DETECTED " );
    Serial.println("Turning ON the LED");
    digitalWrite(led, HIGH);
    startTimer = true;
    lastTrigger = millis();
}

Setup() Function

  • Inside the setup() function we are initializing the serial communication with a baud rate of 115200.
  • Set the mode of pin GPIO23 (LED) as output.
  • Set the initial state of the LED as LOW.
  • Assigned the digital pin(connected to the PIR Sensor) to hardware interrupt using the attachInterrupt function.
  • The detectMovement function is passed as an argument inside this function.
void setup()
{
    Serial.begin( 115200 ); // Serial port for debugging purposes
    pinMode( PIRSensor, INPUT_PULLUP ); // PIR Motion Sensor mode INPUT_PULLUP
    pinMode( led, OUTPUT );
    digitalWrite( led, LOW );
    attachInterrupt( digitalPinToInterrupt( PIRSensor ), detectsMovement, FALLING ); // Set PIRSensor pin as interrupt, assign interrupt function and set RISING mode
}

Loop() Function

We have activated the interrupt in the Setup Function, so when the PIR Sensor detects the motion, it will automatically execute the interrupt function, which will turn the LED ON and start the timer.

  • In the loop function, we are comparing the current time with the last triggered time.
  • LED will turn off after a delay of 5sec (once an interrupt is detected).
  • The variable “now” will be updated with the current time in each iteration.
void loop()
{
    now = millis();
    if( startTimer && (now - lastTrigger > ( timeSeconds*500)))
    {
        Serial.println(" Turning OFF the LED " );
        digitalWrite( led, LOW );
        startTimer = false;
    }
}

Motion Detection Results/Testing

  • Select the right development board from Tools >> Boards >> DOIT ESP32 DevKit V1 in Arduino IDE.
  • Compile and upload the code into ESP32 using Arduino IDE.
  • Open the serial monitor with a 115200 baud rate as defined in the Arduino code.
  • Press the EN button on the ESP32 development board.

This concludes the tutorial. I hope you find this tutorial helpful. Thanks for reading. See you soon with a new tutorial on ESP32. Take care !!!

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