The Kynix Blog
Stay Ahead with Expert Electronics Insights,
Industry Trends, and Innovative Tips
- Electronic Components
- News Room
- General electronic semiconductor
- Components Guide
- Sort by
- Robots
- Transmitters
- Capacitors
- IC Chips
- PCBs
- Connectors
- Amplifiers
- Memory
- LED
- Diodes
- Transistors
- Battery
- Oscillators
- Resistors
- Transceiver
- RFID
- FPGA
- Mosfets
- Sensor
- Motors, Solenoids, Driver Boards/Modules
- Relays
- Optoelectronics
- Power
- Transformer
- Fuse
- Thyristor
- potentiometer
- Development Boards
- RF/IF
- Semiconductor Information
- PCB
- transistor
Overview of switchesMain parameter of switchesSwitch SymbolSwitch DiagramWhat is a toggle switch?How does toggle switches work?Video related to toggle switchesFive ways toggle switch wiringCircuit diagram of toggle switchTypes of Toggle SwitchDPDT Toggle SwitchDPST Toggle SwitchSPDT Toggle SwitchSPST Toggle SwitchLED Toggle SwitchAdvantages and Disadvantages of toggle switchesRocker Switches vs Toggle SwitchesToggle Switch ApplicationsToggle Switch FAQ Overview of switchesA switch is a piece of equipment used to stop current flow in a circuit. Simply put, a switch has the power to complete or disrupt an electrical circuit. To turn a device ON and OFF, every electrical and electronic application makes use of at least one switch.Switches are therefore a component of the control system, and control action is impossible without them. A switch has two possible states: completely ON (by shutting its contacts) and completely OFF (by opening its contacts).A switch establishes a closed conduit for the current to flow when its contacts are closed, which causes the load to draw power from the source. As demonstrated in the figure below, no power is used by the load when a switch's contacts are open. Main parameter of switchesSwitches ParametersVoltage ratingThe insulation materials, contact separation, rate of separation, and general safety considerations are some of the variables that affect voltage rating.Current carrying ratingThe electronics switches' current specifications are crucial since they will only be able to transport a particular amount of current through their contacts.Current switching ratingAn electromechanical switch's current switching rating is typically lower than its current carrying rating. The problem is that forming and breaking contacts creates arcing, and the contacts can only handle so much of it before the wear on the contacts significantly limits the operational life.Switch formatFor every electronics circuit design, choosing the appropriate switch format is essential. Toggle switches, slider switches, rotary switches, DIPs, thumbwheels, and many more are among the many various switch formats. Any switch's selection process includes the format.Number of operationsThere is always a tiny degree of wear as the contacts of a switch move across one another to ensure the best resistance is obtained.Contact resistanceThere is a higher contact resistance than there would be if the conductor were continuous because a switch's contacts are not a continuous conductor but can be broken and rebuilt.Power ratingThe maximum power that the switch can manage while working is indicated by its power rating. Overriding this rating may result in an excessive buildup of heat inside the device, which could lead to the switch failing and create a safety issue.Inductive ratingIf not handled properly, any inductance in a circuit will raise the intensity of arcing at the contacts and shorten the life of the switch. This means that once current is flowing, it is challenging to stop since the inductance will produce significant back EMFs when the current is stopped. This is because any inductance in the circuit will oppose the change taking place.Contact typeThere are two different types of contacts used in change-over type electromechanical: Break before make and Make before break. Switch SymbolSwitch Symbol Switch DiagramSwitch Diagram What is a toggle switch?Toggle switches are electrical switches that be opened or closed using a lever or handle that is moved forward and backward. Toggle power switches and joystick switches are other names for these switches. These switches can be used in any electrical application because they are flexible devices.Since switches are typically manipulated manually, the toggle switch, which functions as a straightforward ON/OFF switch in many electrical circuits, is essential. The toggle switch controls the flow of current from the power source to a device or within a device by use of a lever.Toggle Switch How does toggle switches work?The armature switches the contact into position to start or halt an electrical flow when the switch operator pulls the toggle (the actuator). To put it simply, pushing the toggle can turn a gadget on or off. There are two functions that can be used; a momentary function means that the switch is only engaged when the force is applied. An internal spring mechanism forces the armature to return to its initial position in order to accomplish this. A latching toggle switch, in contrast, keeps the state after being depressed until the toggle is depressed once again to release the switch.The basic toggle switch design is as follows, although being available in various forms and configurations. When the toggle is pulled, an armature (a component conducting electrical current) attached to it moves, adding or removing an electrical contact from a circuit and activating or deactivating the circuit.Even though momentary switches also have an associated spring that will draw the actuator back to its starting point if released, the switch will typically stay in place unless manually pushed again. Video related to toggle switchesVideo Description: Add a switch easily to any household electronics item or automotive project easily by watching this short video. Five ways toggle switch wiringStep One: Look at the instruction about the toggle switchesElectrical setups for the many types of equipment that you might wish to install toggle switches on vary substantially. As a result, no single guide is likely to offer a universally applicable solution. The procedures in this section are intended to serve as general guidance for a straightforward on-off (also known as SPST) toggle switch. They should never take precedence over any installation instructions that came with your toggle switch or the appliance you're placing it into.You can look at the below instruction about the toggle switches:Toggle Switches Instruction Step Two: Your device's supply wire should be cutYou must link your toggle switch to the device's power source in order for it to act as an on-off switch. Cut the supply wire for your device with wire cutters at a spot that will make it easiest to route one or both ends of the cable to the switch. Using a wire stripper, remove about 12 inch (1.3 cm) of insulation from each end of the wire.Cut the supply wire Step Three: If the cable does not reach the switch from either end, add a pigtail.A pigtail is a brief wire piece with both ends stripped, often measuring under 6 inches (15 cm). It can be used as a form of "extender" by being attached to cables that aren't quite long enough to reach your toggle switch.Pigtail connetced to switches Step Four: Connect the supply wire to the toggle switchNow that the device's supply wire has been severed, you must insert your toggle switch so that it can control the circuit's current flow in the middle of the break. The kind of toggle switch you have will determine how you should proceed. Step Five: Test your switchWhen your toggle switch is properly wired, carefully reattach the power to the device and check the toggle switch's operation. You can swap out the panel or housing if everything functions as it should. Congratulations! A toggle switch has been fitted successfully. Circuit diagram of toggle switchThe SPDT toggle switch's circuit schematic is displayed below. A 6V battery, two resistors R1 & R3, two LEDs D1 & D3, and a 21236N switch can be used to construct this circuit.Three terminals, including one input and two outputs, make up this switch. Thus, we can acquire two outputs, the first of which comes from pins 2 (COM) and 1 and the second of which comes from pins COM and 3. In three-way circuits, this switch is mostly used to control electrical appliances from two places.The pins 1 and 3 are connected to D1 (an LED) and D2 (an LED), respectively, in the circuit shown above. When pin 1 is toggled, the D1 LED turns on and the D2 LED turns off. In a same manner, when pin 3 is toggled, D2 LED will turn ON and D1 LED will turn OFF. Consequently, we are able to manage two loads using a single SPDT toggle switch.Toggle Switch Circuit Diagram Types of Toggle SwitchThere are four main versions of these switch designs, each of which has a different combination of throws and poles, such as SPDT, SPST, DPDT, and DPST. Poles of these switches are often the distinct power supply controlled by each switch, whereas throws are the various areas the switch can be used, such as ON & OFF.DPDT Toggle SwitchDPST Toggle SwitchSPDT Toggle SwitchSPST Toggle SwitchLED Toggle Switch DPDT Toggle SwitchDouble pole, double throw (DPDT) toggle switches are used to establish or terminate connections between two conductors and two different circuits. There are six terminals on these switches, and terminals 3 and 4 get the necessary power to drive the loads on the other terminals, which are 1, 5, 2, and 6. Four-way or four-position switches are the names given to these switches.DPDT Switches The six terminals of a DPDT toggle switch are. The toggle switch is represented by terminals 3 and 4. The electricity required to drive the loads on terminals 1 and 5, as well as 2 and 6, is supplied to these terminals. Between terminals 1 and 5, terminal 3 can switch. Therefore, terminal 3, which represents the toggle switch, can switch between operating the fan and operating the motor if a fan is connected to terminal 1 and a motor is connected to terminal 5. The same is true for terminal 4, too. Between terminals 2 and 6, terminal 4 can switch. In this case, terminal 4, which acts as the toggle switch, can switch between the heater and the blower if a heater is connected to terminal 2 and a blower is connected to terminal 6.Two input switches on a DPDT switch can each be connected to one of two terminals. It can therefore use two switches to control four distinct circuits or devices.The circuit for a DPDT toggle switch is illustrated below:DPDT Toggle Switch Circuit Diagram DPST Toggle SwitchThe name "DPST" refers to a double-pile single throw switch, which is used to establish or terminate the connection between two circuit conductors inside a single branch circuit. These switches typically have four terminals that can be used to simultaneously connect and disconnect two pairs of terminals.DPST Switches A 30A DPST switch is used in this wiring layout to connect a 240V AC load appliance (such as a dryer or water heater). The hot wires for 240V are immediately linked to the two pole, single throw switch and the load point as it is illustrated because there is no need to wire the neutral wire. The dryer is directly linked to the ground wire. When turned OFF, the DPST switch will cut both hot wires. Similar to that, while in the ON position, it will join both Hot wires.DPST Toggle Switch Circuit Diagram SPDT Toggle SwitchA single conductor connection with any of two additional single conductors can be made or broken using a toggle switch known as an SPDT, or single pole, double throw. These switches typically have three terminals, which are typically utilized in pairs. Any load must be connected to the first terminal in order to power a specific gadget. To power the loads on Terminals 1 and 3, Terminal 2 receives the necessary power, while Terminal 3 is utilized to connect to any load and turn on any device. This switch can therefore power any of two circuits. Three-way switches are another name for these kinds of switches.SPDT Switches Three terminals make up an SPDT toggle switch. Any load can be connected to Terminal 1 in order to power a specific appliance. Furthermore, any load can be connected to terminal 3 to power any device. The power required to power the loads on terminals 1 and 3 is delivered to terminal 2 at this point. A SPDT switch can therefore operate any of two circuits. It can switch between the two circuits so that various gadgets or circuits can be powered with just a flick of the switch. The circuit for an SPDT toggle switch is illustrated below:SPDT Toggle Switch Circuit DiagramWe link our 9-volt DC power source to terminal 2 in this circuit. The toggle switch at terminal 2 allows us to switch between terminals 1 and 3. A fan is attached to Terminal 1. The DC motor does not operate when the switch is flipped to the left (terminal 1). The DC motor turns on when the switch is flipped to the right (terminal 3), but the fan does not. You can see how we can control two distinct circuits or devices with an SPDT switch in this manner. A double throw switch offers two possibilities. SPST Toggle SwitchSPST, which stands for "Single Pole Single Throw," refers to a device with two terminals, such as input and output. These switches function just like an ON/OFF switch. This switch's primary job is to establish or terminate a connection between a single conductor and a single branch circuit. Once this switch is opened, the circuit will be cut off, stopping any current flow through the load. When the switch is closed, current flows through the load in a similar manner.SPST Switches A SPST toggle switch only has 2 terminals, as you can see. The input is on terminal 1. The output will be at the other terminal. Simple ON-OFF switches are what SPST toggle switches do. They interrupt the circuit when open, preventing current from reaching the load. Current can move across a closed circuit and drive the load. You can see that the DC motor may be started or stopped using this circuit simply as an ON/OFF switch. The circuit for an SPST toggle switch is illustrated below:SPST Toggle Switch Circuit Diagram LED Toggle SwitchToggle switches with illumination operate at 12 volts DC and light up to show the status of your circuit. Add some flair to your switch and control panels by using these lit toggle switches. Our assortment is completed by toggle switches with LED tips, duck bills, and longer handles. Red, blue, green, and amber are the available illumination colors. Toggle switches with illumination are available in an ON-OFF, single pole, single throw design. The switches' connections, which consist primarily of power in, power out, and a ground for the indicator light, are 1/4 inch push-on terminals. The fundamentals of how to wire an illuminated toggle switch are demonstrated in our video.You shouldn't have any trouble wiring an LED rocker switch if you pay close attention to where your ground, power, and acc pins are placed, follow the diagram below (which uses Oznium's LED Round Rocker Switch with a recommended mounting hole diameter of 3/4 inch) :LED Toggle Switch Circuit Diagram Advantages and Disadvantages of toggle switchesAdvantagesDisadvantagesUse of these switches with circuit boards is optimal.While using these switches, a clicking sound will be heard.These switches often have a small footprint, are incredibly sturdy, and are very easy to seal.When compared to rocker switches, these are bigger and bulkier.These switches are effective in controlling electricity.It requires a toggle lock washer.There are small and regular sizes of these switches available.Only low voltage circuits can use it.A lever can be used to extend and operate them.-These switches are energy efficient since they utilize less -These switches are very strong.- Rocker Switches vs Toggle SwitchesRocker switches and toggle switches are the two primary categories of maintained switches. The advantage of having a rocker switch is that you can typically add images, symbols, or even writing to the switch's face to make it more personalized. It therefore especially helpful in situations where function communication is required. Switches that can be sealed easily are perfect for usage with circuit boards. indicating increased resilience against water and dust. enhancing the switch's suitability for hostile conditions.Which switch is best for your project will ultimately depend on its design and environmental factors. From a design standpoint, some people favor the toggle switch's appearance, while others like the rocker switch's more common appearance. Your choice will be influenced by the circumstances. A toggle switch, for instance, may be preferable if the product is for the marine industry because of its IP rating. Toggle Switch ApplicationsThese switches give drivers of cars easy access to headlights, comparable controls, and indicator lights.Conveyor belts, residual current devices, and other industrial and electrical equipment employ these (RCDs).These switches are present in home, commercial, and industrial power outlets.It can serve as the primary switch for industrial machinery like conveyors and packaging machines as well as AC equipment.These switches are employed in switching headlights, logic-level programs, automobiles, and aviation control panels, among other things.Toggle switches are utilized as switching circuits in communications, commercial, and industrial equipment. Toggle Switch FAQOverview and Applications of toggle switchAn electronic on/off switch is a toggle switch. The best purpose for toggle switches is to change the status of system settings and functionalities. To allow users to select between two opposed states, toggles may be used in place of two radio buttons or a single checkbox. What are the 4 types of switches?Single pole single throw, single pole double throw, double pole single throw, and double pole double throw are the four primary categories of switches. The differences between toggle and switchSince they both manage states but not in the same way, we must first distinguish between a toggle button and a toggle switch: Toggle button: Represents an action that changes a state. Two (or more) mutually incompatible states or possibilities that can be switched are represented by a toggle switch. Should a toggle switch be on the positive or negative?Never switch the ground return side; always switch the supply side. You can flip both lines if you're using a twin pole switch, but you must keep the ground line to the chassis intact. More corrosion is likely to occur on the negative terminal. What is a toggle switch?In order to switch an electrical circuit, toggle switches include an operating lever that can be moved up and down or left and right. A "toggle" is a little wooden rod that is used in place of buttons to fasten garments.
kynix On 2022-11-15
IntroductionWhat is RS485?MaterialsMAX485 pinoutHalf duplex operationHere is how the program worksFull duplex operationHalf duplex operation codeFull duplex codeIntroductionIn digital computer communication between two computers can be made using either parallel or serial method. In parallel communication separate line is dedicated for a one-bit information to transfer. This communication is fast and easy, but it requires a lot of wires at least as many as the number of bits need to be sent in parallel. For example, to transfer a 64-bit data from one device to another, 64 data lines will be required which is impractical in embedded systems. The alternative method to transfer data is to use serial communication. In serial communication one bit at a time is transferred from one device to another one. While this method solves the wiring problem it has a lot of other problems such as bandwidth, data lagging, complex protocol, and electrical standards. There are lot of different methods to do serial communication while one method is good in one situation another one is better in another situation. In this article we will discuss RS485 communication protocol which is one of the many available serial communication methods.Materials1MAX485 module2STM32 F401CDU6What is RS485?An industry specification called RS-485 outlines the physical layer and electrical interface for point-to-point electrical device communication. RS485 is the industrial standard for communication that defines the electrical interface and physical layer for point-to-point communication. RS485 is a robust communication system it can support multiple devices on a single bus, works in a noisy environment as well and requires a maximum of 4 lines.RS485 was first developed in 1983 and has since been used in many industrial applications because of its robustness and simplicity. It has the ability to transmit data over long distances while at the same time it is cheap, thus engineers are using it in all sorts of applications such as automotive, manufacturing, and theater spaces. Nowadays almost all motor controllers, VFDs and manufacturing machines will have a port available for RS485.RS485 is actually a standard that defines the electrical characteristics of the transmitters and receivers for communication protocols. RS482 uses two lines usually called A and B which must be balanced and differential. It means that the two lines must have same impedance, nearly same length and must be differential. The key features of RS485 communication are given belowMultipoint operation10 Mbps data transfer rate at 40 feet lengthMaximum cable length is 4000 feetRS485 works both in half duplex as well full duplex mode. In half duplex mode one device can either transmit or receive data at a time. While in full duplex mode, a device can transmit and receive data at the same time. Having more than one device on a bus can cause problem when two or more devices transmit data at the same time. Therefore, software control is necessary to ensure only one device transmit data at a time.RS485 is the physical layer of communication in the OSI model. It means this layer can be used as a base for other protocols such as UART which in most application people use because UART is an asynchronous communication protocol that does not require any clock signal which make it very easy to use. In this article we will demonstrate how RS485 can be used between two STM32 microcontrollers to communicate and exchange data. We will be using MAX485 module which is an easily available RS485 module. MAX485 pinoutRO → Receiver outputRE → Receiver enableDE → Data enableDI → Data inputVCC → Input voltageGND → GroundA, B → RS485 differential linesHalf duplex operationIn half duplex operation either data can be received or transmitted at a time. Both operations cannot be done at the same time. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. Making them low puts the module in receiving mode while making them high puts the device in transmitter mode.In CubeMX the microcontroller of our choice is selected which in our case is STM32 F401CDU6. In connectivity UART1 should be enabled with 115200 bps baud rate. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSEGPIO A7 is set as outputHere is how the program worksThe setup has two microcontrollers. We will call one side as A and the other side as B. When a user presses the user key on A STM32 microcontroller it will send the information to the B microcontroller via RS485. The receiving B microcontroller will switch on the onboard LED and will responds with an OK message. The OK message will blink the led on A microcontroller twice. Similarly, when the user presses key on B microcontroller it will transmit a message to A microcontroller and turns on the onboard LED and will responds with an OK message. The OK message will blink LED on B microcontroller twice. Similarly pressing the button again will do the same except this time it will turn off the LED.Full duplex operationIn full duplex operation data can be received or transmitted at the same time. Both operations can be done at the same time. In this mode two MAX485 modules will be required at each end and overall, 4 MAX485 modules will be used. It means that the two MAX485 modules will be constantly in receiving mode while the other two will constantly in transmission mode. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. We will put the data control pins of two module as high while put the data control pins of other two module low. The configuration is shown below.The program works the same way as it was working in the half duplex mode however, this time the transmitted and received by MCUs at the same time.Half duplex operation code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in receiving mode HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); //Turn Off LED pin while (1) { HAL_UART_Receive(&huart1, R_Data, 1, 10); // If button is pressed on the other MCU if(R_Data[0] == 83) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle LED pin HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); //Put RS485 module in transmission mode HAL_UART_Transmit(&huart1, T_Data, 1, 10); //Send acknowledgment HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in transmission mode R_Data[0] = 0; } // If OK message is receive if(R_Data[0] == 69) { if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); } R_Data[0] = 0; } // Button is pressed if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); //Put RS485 module in transmission mode T_Data[0] = 83; HAL_UART_Transmit(&huart1, T_Data, 1, 10); T_Data[0] = 69; HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in Receiving mode } } /* USER CODE END 3 */}Full duplex code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); //Turn Off LED pin while (1) { HAL_UART_Receive(&huart1, R_Data, 1, 10); // If button is pressed on the other MCU if(R_Data[0] == 83) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle LED pin HAL_UART_Transmit(&huart1, T_Data, 1, 10); //Send acknowledgment R_Data[0] = 0; } // If OK message is receive if(R_Data[0] == 69) { if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); } R_Data[0] = 0; } // Button is pressed if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) { T_Data[0] = 83; HAL_UART_Transmit(&huart1, T_Data, 1, 10); T_Data[0] = 69; } } /* USER CODE END 3 */}
Victoria On 2022-10-26
What is a LED?Video related to LEDLED Colours and materialsHow do LEDs work?Types of LedsCalculating LEDs resistor valueHow to Test LED LightsThe warning of LEDs useLEDs FAQWhat is a LED?LED = Light Emitting Diode. An LED must be prevented against transferring too much current because its electrical behavior differs significantly from that of a light. Typically, this is done by connecting a resistor in series with the LED. Never attach an LED directly to a power source or battery.LEDs must be wired in the proper direction; the diagram may be labeled with the letters an or + for the anode and k or - for the cathode (yes, it really is k, not c, for cathode). In the case of spherical LEDs, the cathode is the short lead and there may be a slight flat on the body. Although the cathode is the larger electrode within the LED if you can see it, this is not a recognized method of identification.LEDs Video related to LEDVideo Description: This video is mainly talk about how to design LED circuits, how to calculate resistor size, how to protect LED, how long will a battery power a circuit, how to calculate resistor power rating, how to connect LED and much more. LED Colours and materialsThe semiconductor material, not the coloring of the "package," determines the color of an LED (the plastic body). All colors of LEDs are available in uncolored, diffused (milky), or clear (commonly referred to as "water clear") packaging. The colored packaging is also offered in diffused (the typical type) and clear forms. White and blue LEDs could cost more than the other colors.ColorWavelength (nm)Voltage Drop (V)Semiconductor MaterialInfrared> 760< 1.9Gallium ArsenideInfrared> 760< 1.9Aluminium Gallium ArsenideRed610 - 7601.6 -2.0Aluminium Gallium ArsenideRed610 - 7601.6 -2.0Gallium Arsenide PhosphideRed610 - 7601.6 -2.0Aluminium Gallium Indium PhosphideRed610 - 7601.6 -2.0Gallium PhosphideOrange590 - 6102.0 -2.1Gallium Arsenide PhosphideOrange590 - 6102.0 -2.1Aluminium Gallium Indium PhosphideOrange590 - 6102.0 -2.1Gallium PhosphideYellow570 - 5902.1 -2.2Gallium Arsenide PhosphideYellow570 - 5902.1 -2.2Aluminium Gallium Indium PhosphideYellow570 - 5902.1 -2.2Gallium PhosphideGreen500 - 5701.9 -4.0Gallium Indium PhosphideGreen500 - 5701.9 -4.0Aluminium Gallium Indium PhosphideGreen500 - 5701.9 -4.0Aluminium Gallium PhosphideGreen500 - 5701.9 -4.0Indium Gallium NitrideBlue450 - 5002.5 -3.7Zinc SelenideBlue450 - 5002.5 -3.7Indium Gallium NitrideBlue450 - 5002.5 -3.7Silicon CarbideBlue450 - 5002.5 -3.7SiliconViolet400 - 4502.8 -4.0Indium gallium NitridePurplemultiple types2.4 -3.7Dual Blue/Red LEDsPurplemultiple types2.4 -3.7Blue with Red PhosphorPurplemultiple types2.4 -3.7White with Purple Plasticultraviolet< 4003.1 -4.4Diamondultraviolet< 4003.1 -4.4Boron Nitrideultraviolet< 4003.1 -4.4Aluminium Nitrideultraviolet< 4003.1 -4.4Aluminium Gallium Nitrideultraviolet< 4003.1 -4.4Aluminium gallium Indium NitridePinkmultiple types3.3Blue with phosphorPinkmultiple types3.3Yellow with Red, Orange or Pink phosporPinkmultiple types3.3White with Pink pigmentWhiteBroad spectrum3.5Blue/UV diode with Yellow Phosphor How do LEDs work?A P-type semiconductor (which has a higher hole concentration) and an N-type semiconductor are combined to create LEDs, which are semiconductor light sources (larger electron concentration). The P-N junction's electrons and holes will join once more when a strong enough forward voltage is applied, releasing energy in the form of light.LEDs (Light Emitting Diodes) transform electrical energy directly into light as opposed to conventional light sources, which first convert electrical energy into heat before turning it into light. This results in efficient light creation with minimal electricity waste.LEDs Emit Light Types of LedsDual In-Line Package (DIP) LEDs:The first LED chips were DIP ones, which are what most people think of when considering LED lights. Despite being more established than its more recent counterparts, DIP LED chips are still in use and are more frequently seen integrated into electronics because of their small size. However, they are not very strong and can only provide a small amount of brightness.DIP LEDs Surface Mounted Diode (SMD) LEDs:These are likely the most popular sort of LED chip available; they are installed and soldered onto the circuit board. They are more adaptable when it comes to encasing them within smaller electronics or across other forms of lighting, such as strip lighting, because they are brighter than their DIP counterparts and are also smaller. Three diodes can fit on a single SMD chip, allowing you to produce a variety of colors and provide customers more options. The LED market has undergone this significant progress. SMD 3528 and SMD 5050, both of which measure 5mm in width, are the two most used SMD chip sizes.SMD LEDs Chip on Board (COB) LEDs:The most recent advancement in LED technology is represented by these chips. Out of the three, COB LED chips are the brightest since they can frequently fit nine or more diodes onto a single chip. In what ways does this affect LED lighting? First off, it increases lighting efficiency by improving brightness-to-energy output. They can therefore be utilized with a variety of various lighting types. However, it's important to keep in mind that a COB LED chip's circuitry prevents it from emitting a wide variety of colors.COB LEDs Calculating LEDs resistor valueTo limit the current flowing through an LED, a resistor must be connected in series with the LED; otherwise, the LED will burn out fairly immediately. R, the resistor's value, is determined by:R = (VS - VL) / IR = resistor value in ohms (ohm).VS = supply voltage.VL = LED voltage (2V, or 4V for blue and white LEDs).I = LED current in amps (A) The LED current needs to be lower than what your LED is capable of handling. Since the The maximum current for typical 5mm diameter LEDs is frequently 20mA; however, many circuits can work with 10mA or 15mA. Divide the mA current by 1000 to convert it to amps (A) for the calculation.If the projected value is unavailable, pick the nearest larger standard resistor value so that the current will be a little less than what you chose. If you choose a higher resistor value to reduce the current, the LED will be less bright (for example, to extend the battery life).The color of the LED affects the voltage VL of the LED. The voltage of red LEDs is the lowest; yellow and green have a somewhat higher value. The highest voltages are used in blue and white LEDs. You can use 2V for red, yellow, and green LEDs and 4V for blue and white LEDs for the majority of applications where the precise value is not crucial. According to Ohm's law, the resistor's resistance, R = V/I, is determined by:V = voltage across the resistor (= VS - VL in this case) I = the current through the resistorSo R = (VS - VL) / IResistor Value How to Test LED LightsStep One: Use a MultimeterGet a digital multimeter with a diode reading capability. Simple multimeters only measure voltages, amps, and ohms. A multimeter with a diode setting is required to test LED lighting. Mid-range to high-range multimeters, which are more likely to offer this capability than affordable versions, can be found online or at your neighborhood hardware store.Multimeter Step Two: Connect the black and red test leadsTo the outlets on the front of the multimeter, attach the red and black test leads. The positive charge is in the red lead. The input marked "COM" should be connected in with the black lead, which is the negative.Multimeter Connect Step Three: Select the diode setting on the multimeter's dialTo move your multimeter's front dial from the "off" position, turn it clockwise. Up till you reach the diode setting, keep twisting it. The diode setting may be represented by the diode circuit symbol if it is not labeled explicitly. The cathode and the anode of a diode are both visually represented by the diode symbol. In this digital multimeter dial picture, we need to set the multimeter’s dial on 14 to test diode.Multimeter dial Step Four: The red probe should be connected to the anode and the black probe to the cathodeThe cathode end of the LED, which is typically the shorter prong, should be touched with the black probe. The red probe should then be pressed against the anode, which is the longer prong. Ensure that the black probe is connected before the red probe because doing so can result in inaccurate readings. During this test, be sure the cathode and anode are not in contact with one another since this could prevent electricity from flowing through the LED light and affect your results. Throughout the test, the red and black probes must not come into contact. After making the connections, the LED ought should turn on.Diode test Step Five: Verify the reading on the digital multimeter displayA healthy LED light should show a voltage of about 1600 mV when the probes are in contact with the cathode and anode. If during the test there is no reading displayed on your screen, repeat the procedure to ensure that the connections were completed correctly. This can indicate that the LED light isn't functioning if the test was done correctly. The transformer needs to be changed if your supply does not provide any output voltage. LED lights need to be replaced if there is voltage present at the output. The warning of LEDs useIn general, it is not a good idea to connect multiple LEDs in parallel with just one resistor shared between them. Only the lowest voltage LED will light if the other LEDs require slightly different voltages, and the higher current running through it could damage the other LEDs. One resistor can be used to successfully link identical LEDs in parallel, but since resistors are so inexpensive and the current utilized is the same as connecting the LEDs separately, this rarely provides any significant benefit.LEDs in parallelInstead, we should do as follows: Connecting LEDs in seriesConnecting LEDs in series LEDs FAQWhat can the LEDs be applied to?LEDs (Light Emitting Diodes) are mostly used to illuminate items and even spaces. Due to its small size, low energy consumption, long lifespan, and versatility in terms of use in many applications, it is applied everywhere. LED usage and applications include TV backlighting. How many types that LEDs own?Fundamentally, LED lighting uses three major forms of LED technology: DIP, SMD, and COB. What is LED and how it works?When an electric current passes through a semiconductor device called a light-emitting diode (LED), the LED emits light. When current flows through an LED, the electrons and holes recombine and produce light. How long do LED lights last?The longer lifespan of LED lighting fixtures is one of its main benefits. The most durable LED light fixtures have been evaluated to survive as long as 100,000 hours, whereas incandescent light bulbs were designed to last roughly 1,000 hours. On average, LED light bulbs last at least 20 years before needing to be replaced. Which is not a benefit of LED?On a capital cost basis, LEDs are now more expensive (price per lumen) than the majority of conventional lighting solutions.
kynix On 2022-10-17
Keypads are input devices that are being widely used in many embedded system projects. It can be found in appliances, door locks, and industrial machines. Keypads are used to take input from the user in the form of numbers or characters which can further be used for processing such as password, menu selection and navigating among different options. One of the most common and low-cost keypads is the matrix keypad with 4×4 or 3×3 buttons. In this article we will discuss how a low cost 4×4 matrix keypad can be used in STM32. Before proceeding further, we will need to know few things.Materials14×4 matrix keypad2STM32 F401How a 4×4 keypad works? 4×4 keypadIn microcontrollers usually a pin is used to take input from the user. This input can be either 1 or 0. Multiple 1’s and 0’s can be combined to store more information. For this purpose, multiple input pins will be required. However, this becomes impractical when the input pins required exceed certain number such as 16 or 9 as the microcontrollers do not have this many pins available.The 4×4 matrix keypad solves this problem and reduced the required number of pins to 8 or 6. It is made of a thin and flexible membrane. The 16 keys of the 4 x 4 keypad module are arranged in a matrix of rows and columns. A copper trace connects each of these switches to the others. The rows and column are not connected to each other in normal condition. When we push a key, a column and a row come into contact with each other. In matrix keypads the buttons are divided among rows and columns. Four buttons lie on each row and each column. Thus, columns are connected to external input pins of microcontroller while the rows are connected to output pins of microcontroller. The output pins are high all the time. When a button is pressed the corresponding column goes high and the microcontroller detects it. Finding which column has been activated is easy as each column is connected to a separate pin, however, finding a row is difficult. Once both row and column are identified then the corresponding button can be identified. A clever method to identify the pressed key is to switch off all output pins except one, and then check which input pins is high. Doing this for all the output pins will identify the row. Once the row number is found out, the button can easily be traced out.matrix keypad in STM32STM32 F401 implementationSTM32 F401In CubeMX the relative microcontroller of our choice is selected which in our case is STM32 F401CDU6. The GPIOs that need to be selected as output or external interrupt input are given in the figure above. In the NVIC tab the interrupt should be enabled. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSE Once the CubeMX code is generated the following code should be added to the /* USER CODE BEGIN PV */ section./* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousM = 0; uint32_t currentM = 0; uint8_t key = 0; uint8_t InputData[5] = {0}; int i = 0;/* USER CODE END PV */This code section defines the necessary variables that will come handy later.In the main.c section in /* USER CODE BEGIN 2 */ the output configured pins should be set to 1. /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /* USER CODE END 2 */ While the interrupt callback function void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) should be added to /* USER CODE BEGIN 4 */ section.void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ currentM = HAL_GetTick(); if (currentM - previousM > 10) { /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/ GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT; GPIO_InitStructPrivate.Pull = GPIO_NOPULL; GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 68; //ASCII value of D } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 67; //ASCII value of C } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 66; //ASCII value of B } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 65; //ASCII value of A } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 35; //ASCII value of # } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 57; //ASCII value of 9 if (i == 4) { //Send Data } else { InputData[i] = 9; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 54; //ASCII value of 6 if (i == 4) { //Send Data } else { InputData[i] = 6; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 51; //ASCII value of 3 if (i == 4) { //Send Data } else { InputData[i] = 3; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 48; //ASCII value of 0 if (i == 4) { //Send Data } else { InputData[i] = 0; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 56; //ASCII value of 8 if (i == 4) { //Send Data } else { InputData[i] = 8; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 53; //ASCII value of 5 if (i == 4) { //Send Data } else { InputData[i] = 5; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 50; //ASCII value of 2 if (i == 4) { //Send Data } else { InputData[i] = 2; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 42; //ASCII value of * } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 55; //ASCII value of 7 if (i == 4) { //Send Data } else { InputData[i] = 7; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 52; //ASCII value of 4 if (i == 4) { //Send Data } else { InputData[i] = 4; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 49; //ASCII value of 1 if (i == 4) { //Send Data } else { InputData[i] = 1; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/ GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING; GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); previousM = currentM; }} In the callback function the two linescurrentM = HAL_GetTick(); if (currentM - previousM > 10)takes care of the debouncing of the buttons. In keypad it is a common problem that a but hits once is recorded twice or thrice. So, take of that, a little delay is added at the beginning of callback function.The complete code is given below.#include "main.h" /* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousM = 0; uint32_t currentM = 0; uint8_t key = 0; uint8_t InputData[5] = {0}; int i = 0;/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);/* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*//* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */int main(void){ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */} /* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ currentM = HAL_GetTick(); if (currentM - previousM > 10) { /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/ GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT; GPIO_InitStructPrivate.Pull = GPIO_NOPULL; GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 68; //ASCII value of D } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 67; //ASCII value of C } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 66; //ASCII value of B } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 65; //ASCII value of A } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 35; //ASCII value of # } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 57; //ASCII value of 9 if (i == 4) { //Send Data } else { InputData[i] = 9; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 54; //ASCII value of 6 if (i == 4) { //Send Data } else { InputData[i] = 6; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 51; //ASCII value of 3 if (i == 4) { //Send Data } else { InputData[i] = 3; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 48; //ASCII value of 0 if (i == 4) { //Send Data } else { InputData[i] = 0; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 56; //ASCII value of 8 if (i == 4) { //Send Data } else { InputData[i] = 8; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 53; //ASCII value of 5 if (i == 4) { //Send Data } else { InputData[i] = 5; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 50; //ASCII value of 2 if (i == 4) { //Send Data } else { InputData[i] = 2; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 42; //ASCII value of * } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 55; //ASCII value of 7 if (i == 4) { //Send Data } else { InputData[i] = 7; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 52; //ASCII value of 4 if (i == 4) { //Send Data } else { InputData[i] = 4; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 49; //ASCII value of 1 if (i == 4) { //Send Data } else { InputData[i] = 1; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/ GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING; GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); previousM = currentM; }}
Allen On 2022-10-17
Catalog Introduction How does an LDR work? How to setup ADC in STM32 Introduction The majority of streetlights and outdoor lights are typically operated manually. To manually turn on and off lights is not only risky, but it also wastes energy well as the timing of turning on and off is not optimized. Therefore, an optimized, efficient, and automatic light system is needed to efficiently control light brightness and turn on and off them automatically. In this article, a brief introduction to automatic control of light brightness is given as well as its practical implementation using an STM32 microcontroller and a cheap LDR sensor shown in Figure 1 is demonstrated. Figure 1 LDR breakout board In an automatic light control system, a light detection system is employed that senses the light intensity. If the application requires only to turn on and off a light system, then a threshold value of light intensity is set below which the light will turn on, and above it, the light will turn off. However, if the application is to control the light brightness based on the light intensity in the environment, then a PWM-controlled voltage is provided to the automatic light system. For light detection, a Light Dependent Resistor commonly known as LDR is used. LDR is a sensor whose resistance varies with the intensity of light. This property of an LDR can be used to sense darkness and brightness. Thus, it can be used to automatically control the turn on and off as well as the intensity of the light system. A typical LDR has a maximum resistance value in mega ohms and a minimum resistance value in several kilo ohms. Materials 1STM32 F401/F1032LDR sensor3Potentiometer4LED How does an LDR work? So, how exactly does an LDR operate? LDR works on the principle of photoconductivity. It is an optical phenomenon in which material conductivity increases when light falls upon it. When light or photon strikes the material, the electrons in the semiconductor material's valence band are stimulated to the conduction band. The incident photons must have energy larger than the bandgap of the semiconductor material to cause the electrons to move from the valence band to the conduction band. Hence as light intensity increases more and more electrons are excited to the conduction band which produces a large number of charge carriers. This means that more current will flow in the circuit, and as a result, the resistance will decrease. LDR resistance that changes with the intensity of light cannot be read in a microcontroller. To make it readable in a microcontroller the resistance is represented in terms of voltage. For this purpose, a circuit needs to be designed. Many circuits can be used for LDR. These can be based upon MOSFET, BJET, or an amplifier. However, the most commonly used circuit for LDR to convert its resistance into voltage is the voltage divider circuit. In this circuit, two resistors are installed in series. One side is attached to the positive terminal of the battery while the other is attached to the ground. The schematic of the voltage divider is shown in Figure 2. The output of the voltage divider can be fed to another circuit for other purposes such as a comparator i.e LM393. Usually, a comparator is used in on-off operations where the lights are needed to be turned on and off when a threshold value of light intensity is absorbed by the LDR. A typical circuit for the LM393 comparator is shown below. Figure 2 LM393 comparator usage with LDR The calculation for the voltage divider circuit is pretty easy. Referring to Figure 2, the following equation can be used to measure the output voltage. In this equation, it is assumed that there is no load on the output voltage because that load can affect the output voltage. The output of the circuit is shown in Figure 2 where the change in resistance changes the voltage at the IN1+ pin of the comparator. As we know the voltage changes with the intensity of light. The circuit gives maximum voltage in complete darkness while minimum voltage when placed in bright light. The ADC of the STM32 controller can be used to sense the change in the voltage while the results obtained via ADC can be used to generate PWM. It is the PWM that generates average voltage and hence controls the intensity of light. In this article, both the manual and automatic light intensity control is demonstrated using an LED light. The program and procedure for automatic and manual light brightness control is same, the only difference is that in automatic light brightness control and LDR is used while in manual mode simple potentiometer is used. How to setup ADC in STM32 In STM32, ADC can be configured in three different ways. 1) Polling 2) Interrupt 3) DMA. Polling: In the polling method when ADC conversion starts the CPU operation halts. It is only after the conversion is completed, the CPU resumes working. Interrupt: The second method is by using the interrupt service routine. When ADC conversion competes, it generates an interrupt during which required functions are executed which in our case is to update the PWM value. DMA: The third method is to use direct memory access (DMA). In this method, the ADC directly transfers the data to memory bypassing the CPU altogether. This is the most efficient method of all as it does not involve CPU in the ADC operations and keeps it available for other tasks. In this experiment, we will be using interrupt methods which are both simple and efficient. Required hardware STM32 F401/F103LDR sensor (breakout board will be better)PotentiometerLED Let's build the program step by step Open STM32CubeIDE and start a new projectSelect an MCU which in our case is STM32F401CDGo to SYS -> Debug and select Serial Wire. Select SystTick in TimeBase Source. Go to RCC-> High Speed Clock and select Crystal/Ceramic Resonator. Configure ADC1. Select IN1 and set it to be triggered by software. From the NVIC controller tab check the global interrupt box. Configure Timer 1 in PWM mode with output on CH1. Set the counter period register value to 839 and Prescaler register value to 100. This will ensure 1000 Hz frequency at the output. The following formula can be used to set PWM frequency Setting Prescaler value to 99 while the required frequency is 1000 Hz, the ARR value can be calculated as 839. Finally set the clock frequency to 84 MHz and select HSE as the clock source. And generate the code. The final code is given below #include "main.h"ADC_HandleTypeDef hadc1;TIM_HandleTypeDef htim1;void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_ADC1_Init(void);static void MX_TIM1_Init(void);uint16_t AD_Data = 0; uint16_t minimumADC = 1000; uint16_t maximumADC = 3000;int main(void){ HAL_Init() SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_TIM1_Init(); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); while (1) { HAL_ADC_Start_IT(&hadc1); TIM1->CCR1 = ((AD_Data-minimumADC)*840)/maximumADC; }}void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){ AD_Data = HAL_ADC_GetValue(&hadc1);} Figure 3 Duty Cycle in Bright Light Figure 4 Duty Cycle in Low Light Resources Automatics Light.zip
Victoria On 2022-10-06
What is the soldering?What is the PCB soldering?Video about the pcb solderingPCB Soldering MaterialTypes of SolderingTypes of PCB SolderingWhat is the Wave SolderingWave Soldering ProgressThe advantages and disadvantages of wave solderingWhat is the Reflow Soldering?Reflow Soldering ProgressThe advantages and disadvantages of Reflow SolderingWhat is the Selective Soldering?Selective Soldering ProgressThe advantages and disadvantages of Selective SolderingWave Soldering VS Reflow SolderingSelective Soldering VS Wave SolderingReflow Soldering VS Selective SolderingThe conclusion of Wave Soldering VS Reflow Soldering VS Selective SolderingPCB Soldering FAQ What is the soldering?Soldering is the process of putting metal parts together with melted solder, a metal having a lower melting point than other metals. It is a process that is essential to the electronics industry and the main way to connect electrical components. Soldering is utilized in the construction of printed circuit boards (PCBs), as well as in the manufacture of jewelry, pipes, and plumbing. When soldering, a soldering iron or gun is used with solder at a temperature of less than 840 degrees Fahrenheit. Solder typically appears as a thin wire or tube. A flux-like acidic mixture is present inside the tube to stop oxidation.Despite the fact that there are many various kinds of solder, it is often an alloy of lead or tin, brass, or silver that is made to have a low melting point. This metal is melted by the soldering iron and then used to adhere components together rather like glue. The solder metal will re-harden into a single, substantial form that joins the two pieces as it cools. There are currently various lead-free solder options available in an effort to reduce lead usage due to environmental and safety concerns. These substitutes frequently consist of brass, copper, tin, or silver. Lead-free solder can be less effective than conventional solder and has a greater melting point.SolderingWhat is the PCB soldering?Soldering electrical circuit boards is also referred to as PCB soldering. One of the most fundamental skills for everyone who wants to deal with electronics and electrical circuits is this kind of soldering. The most fundamental definition of the soldering process is that it is a technique of attaching two little components together on the surface of the PCB, which is an abbreviation for Printed Circuit Board. There are many various ways you can finish the soldering process. To join two or more separate electrical components on your circuit board, in other words, soldering is a technique.The soldering action itself is pretty straightforward at its heart. A soldering iron, some solder, and the materials you are joining together are all you need to execute the simplest soldering task. A soldering iron is a tool that melts solder and is used to connect two pieces together. It resembles a pen and gets quite hot.Despite the fact that there are many various kinds of solder, it is often an alloy of lead or tin, brass, or silver that is made to have a low melting point. This metal is melted by the soldering iron and then used to adhere components together rather like glue. As the solder metal cools, it will re-harden into one large shape that connects the two parts.Pcb Soldering Video about the pcb solderingVideo Description: How to solder a through hole connection on a printed circuit board (PCB). PCB Soldering MaterialChoosing the correct sort of solder can seem like a daunting chore for a rookie designer or assembler because there are so many different varieties on the market. By enabling the molten, soft alloy solder to produce a eutectic that fuses as it cools, solders are used to create electrical connections between metal contacts. A soldered PCB's mechanical strength after solidification, the needed melting temperature, and any fumes released during soldering will all depend on the combination of metals used to build it. By looking at the core material, metallic components, and soldering flux kinds, we can distinguish between various PCB soldering materials. Lead-based filler metals, such as lead patch, were originally used in patching, however because to regulations, lead-based filler metals are gradually being replaced with lead-free fastens. These may consist of the following metals:BrassCopperAntimonyTinIndiumSilver or bismuth Types of SolderingLead-free solderLead-based solderFlux-core soldersSilver alloy solder Types of PCB SolderingWave SolderingReflow SolderingSelective Soldering What is the Wave SolderingElectronic components are attached to a printed circuit board (PCB) using the large-scale soldering technique known as wave soldering. The name comes from the method of attaching metal components to the PCB by applying waves of hot solder. The components are inserted into or placed on the PCB, which is then passed over a pumped wave or cascade of solder. The technique employs a tank to contain an amount of molten solder. A reliable mechanical and electrical connection is made when the solder wets the exposed metallic portions of the board (those not covered by solder mask, a protective layer that stops the solder from bridging across connections). The process is much faster and can create a higher quality product than manual soldering of components.Surface mount and through-hole printed circuit assemblies both use wave soldering. In the latter instance, before being subjected to the molten solder wave, the components are first attached to the printed circuit board surface by the placement apparatus.Wave Soldering Wave Soldering ProgressIt is essential that an electronics printed circuit board be produced and designed correctly in order to process it properly using a wave soldering equipment. It contains two steps to wave soldering progress.Step One Solder resist layer: The first is now considered best practice for board design. The PCB design incorporates a solder resist or solder mask layer, which provides a layer of "varnish"-like material to the board and prevents solder from adhering to it. Only the necessary parts for soldering are left exposed. The color of this solder resist is most frequently green.Step Two Pad spacing: The second major precaution is to make sure there is enough space between the solder pads that need to be soldered. There is a chance that the solder may bridge the two pads if they are too close together, leading to a short circuit. The spacing requirements for wave soldering depend on the orientation of the board in relation to the solder flow because the solder wave is created by solder flowing out of the reservoir tank as the board passes over it. Pads that are separated from one another perpendicular to the solder flow should have a wider separation than those that are separated perpendicular to it. This is due to the fact that solder bridges are considerably more likely to form in the direction that solder flows. The advantages and disadvantages of wave solderingThe advantages of wave solderingNo glue is needed to secure components during reflow soldering.Board areas where no soldering is required do not have to be masked off.Soldering machines that conduct selective soldering are generally cheaper to operate.Parameters for each are variable and can be more finely controlled.Allows wave soldering to be applied to boards with SMDs and vias.Suited for PTH assemblyIs more time-saving than hand solderingMore affordableLess prone to PCB warpageProvides strong solder joint quality The disadvantages of wave solderingHigh solder consumptionHigh flux consumptionHigh power consumptionHigh nitrogen consumptionAn increase in post-wave solder reworkMasking of sensitive areas on PCB assembliesCleaning of wave solder aperture pallets or masksCleaning of soldered assemblies What is the Reflow Soldering?Although reflow soldering differs slightly from wave soldering, it is still the most used method for joining surface mount components to a circuit board. For soldering through-hole components, wave soldering is more frequently utilized. Reflow soldering can be used for this purpose, however it is rarely done because wave soldering is more affordable.Reflow soldering is the process of attaching components to contact pads by creating a solder paste from powdered solder and flux. The solder is then melted and the junction is connected by heating the entire assembly in a reflow oven or under an infrared lamp. If necessary, you might use a hot air pencil to solder each individual link.Reflow Soldering Reflow Soldering ProgressThere are numerous separate steps that make up the reflow process itself. These are necessary to make sure that the board is heated to the appropriate degree for reflow soldering without causing any excessive amounts of thermal shock. The greatest quality solder junctions are produced when the temperature of the reflow tunnel or chamber is properly profiled. These are the four steps that are typically employed:Preheat: The boards must gradually warm up to the necessary temperature. The board or the components could be harmed by the thermal stress if the rate is too high. Thermal soak: The board then enters what is frequently referred to as a thermal soak area after being brought up to temperature. For two reasons, the card in this case is kept at a certain temperature. One is to make sure that any spaces that aren't heated enough due to shadowing effects are brought up to the necessary temperature. The other is to eliminate the solvents or volatiles from the solder paste and to activate the flux. Reflow: The soldering process's reflow area is where the maximum temperature is reached. The solder is made to melt and form the necessary solder joints here. The real reflow procedure involves the flux lowering the surface tension at the metal-to-metal contact to achieve metallurgical bonding, which enables the melting of the individual solder powder spheres. Cooling: After reflow, the boards need to be cooled, but it needs to be done without stressing the components. Excess intermetallic development and thermal shock to the components are prevented by proper cooling. The cooling zone typically has temperatures between 30 and 100°C (86 and 212°F). The temperature in this zone causes a relatively quick cooling rate, which is selected to give the solder a fine grain structure for the structurally soundest union possible. The advantages and disadvantages of Reflow SolderingThe advantages of Reflow SolderingTrusted by many manufacturersBest suited for SMT assemblyEffective for numerous SMT package types in a single processEasy to monitor and controlIt is a less wasteful method when dealing with specific parts of a PCB The disadvantages of Reflow SolderingFor those seeking to enhance certain aspects of the convection reflow soldering process, the use of nitrogen can be the key. But the use of nitrogen may be expensive.The temperature thresholds of the PCB assembly and the unique requirements of the solder paste must be taken into account while creating the reflow soldering profile. Accurate profiling must be obtained in order to be effective. What is the Selective Soldering?For THT and mixed technology soldering applications, selective soldering, commonly referred to as mini-wave soldering, provides economical, consistent outcomes. Individually programmable and monitored soldering spots are used to regulate flux quantities and soldering time. Additionally, it is the only technique that can be repeated to solder THT components onto a two-sided PCB assembly.Selective Soldering Selective Soldering ProgressStep 1: Fluxing or the application of liquid flux.Step 2: Preheating of the PCB assembly.Step 3: Soldering with a site-specific solder nozzle. The advantages and disadvantages of Selective SolderingThe advantages of Selective SolderingSecure and fast process optimizationReliable solder joint creation without overheating componentsGuaranteed process repeatabilityThe elimination of expensive wave solder palletsThe ability to solder around tall parts with tight spacingThe ability to solder dense concentrations of THT pins The disadvantages of Selective SolderingSince each circuit board must have a customized program, the technique is time-consuming and not well suited for mass production.As there are several parameters, processing problems may occur. Wave Soldering VS Reflow SolderingHow do you decide which soldering technique to employ when? Pad shapes, how much time you have, component orientations, the type of printed circuit board, and other variables could all play a role. Wave soldering is more difficult in several aspects. Careful observation is required for factors like board temperature and the length of time the board is in the solder wave. Board flaws are far more likely to occur when the proper wave soldering environment is not created.When you use reflow soldering to create your printed circuit boards, you won't have to worry nearly as much about protecting the environment. Even yet, wave soldering is frequently more expedient and less expensive than reflow soldering. It is frequently the only feasible method of soldering a board. Reflow soldering is frequently employed for smaller-scale manufacturing projects that don't call for a technique that can be used for quick, low-cost mass production.Remember that in some circumstances you might be able to employ both reflow soldering and wave soldering. It is possible to wave solder components after reflow soldering them on one side. Additionally, you can always manually solder or hand solder PCB components, but if you have access to one of the mechanical techniques of soldering, this will rarely be a suitable strategy. Reflow soldering is still significantly superior, and manual soldering is simply a substitute for it. Selective Soldering VS Wave SolderingWhen it comes to Printed Circuit Boards with through-hole and bigger surface mount components, wave soldering is the best technique. On the other hand, selective soldering is advantageous for a densely populated board since it enables the consideration of a lot of factors. However, because it necessitates the development of a special program for every circuit board, it is inappropriate for mass production. Reflow Soldering VS Selective SolderingWhen producing a circuit board, through-hole components require the use of a selective soldering machine. Reflow is only suitable for SMT components because it only solders the board's top surface. However, all sides of through-hole components need to be soldered.Fewer businesses are using selective soldering for component assembly due to the high production capacity and ease of reflow oven soldering. There are simply too many benefits to ignore. Reflow ovens have replaced hand soldering as the predominant method of PCB assembly in the industry, whereas selective soldering was formerly far more common. In a given amount of time, a reflow oven can produce many more units.The assembly process is also made simpler. A solder ball (often a mixture of solder and flux) is deposited at the location of the joint after the components have been positioned on the board. The solder starts to flow plastically and form the solder junction when the board is conveyed through the oven. The board exits the oven and can either be used in the product of which it is a part or it can be transported to the person who will use it before the end user. Component assembly takes longer using selective soldering machines. They usually cost more money. Furthermore, assembling a lot of PCB designs doesn't need for intricate soldering. Reflow is frequently used by component manufacturers rather as selective soldering for this very reason. The conclusion of Wave Soldering VS Reflow Soldering VS Selective SolderingWave soldering is more challenging in various respects and close inspection is required for elements like board temperature and the amount of time the board remains in the solder wave, while Environmental preservation won't be a major concern when you employ reflow soldering to make your printed circuit boards. What’s more, wave soldering is frequently more expedient and less expensive than reflow soldering. So if you want to take the cost and environment into account, the wave soldering must be the best choice.Wave soldering is the optimum method for Printed Circuit Boards with through-hole and larger surface mount components. However, because selective soldering allows for the evaluation of numerous variables, it is favorable for a board that is densely packed. But selective soldering is not suitable for mass production, though, as it calls for the creation of a unique software for each circuit board.Due to the great production capacity and simplicity of reflow oven soldering, fewer companies are adopting selective soldering for component assembly. When employing selective soldering machines, component assembly takes longer. They typically have higher prices. Furthermore, complex soldering is not necessary for the assembly of many PCB designs. For this exact reason, component manufacturers commonly use reflow instead of selective soldering. PCB Soldering FAQWhat is the PCB soldering?Your circuit board is the PCB. As you use your soldering equipment to connect various components and terminals to one another and to the board, all of the soldering you conduct will occur on the surface of this board. What are the 4 types of soldering?Lead-free solder, lead-based solder, and flux-core solder are the three primary varieties of solder. The silver alloy solder is a different variety. These kinds are created using alloy composition. Other solder kinds exist as well, depending on the form, core type, and application. What is the difference between reflow soldering and wave soldering?There are two soldering methods that are completely distinct from one another: wave soldering and reflow soldering. In wave soldering, the components are joined together with the aid of a melted solder wave crest. Components are soldered using reflow, which is created by hot air, in reflow soldering. What is the difference between selective soldering and wave soldering?In contrast to wave soldering, which strikes all solder joints simultaneously, selective soldering progressively solders individual components using a local wave on an x-y gantry. However, additional benefits have made selective soldering the method of choice in many circumstances. What are the advantages of wave soldering?Components are held in place during reflow soldering without the use of adhesive. No need to mask off board sections that don't need to be soldered. Selective soldering equipment are typically less expensive to run. Each has adjustable parameters that can be more precisely regulated.
kynix On 2022-09-19
Join our mailing list!
Be the first to know about new products, special offers, and more.
Feature Posts
How Resistors Work: From Basic Principles to Advanced Applications2025-07-30
DC Switching Regulators: Principles, Selection, and Applications2025-05-30
FPGA vs CPLD: In-depth Analysis of Architecture, Performance and Application2025-05-07
MOSFET Technology: Essential Guide to Working Principles & Applications2025-05-04
SMD Resistor: Types, Applications, and Selection Guide2025-04-30