• Budget device based on Arduino for the blind (open hardware). Arduino shield for charging lithium batteries

    The Arduino and the charging circuit added to it can be used to monitor and control the charging of NiMH batteries, like so:

    Finished device

    Batteries are great way to power your portable electronics. They can save you a lot of money proper charging. In order to get the most out of your batteries, they need to be charged properly. This means that you need a good Charger. You can spend a lot of money buying a ready-made charger, or you can have fun making it yourself. In this article, we will look at how you can create an Arduino controlled charger.

    First, it is important to note that there is no universal way charging, which would be suitable for all batteries. Different types of batteries use different chemical processes to make them work. As a result, different types Batteries need to be charged differently. In this article, we cannot cover all battery types and charging methods. Therefore, for simplicity, we will focus on the most common type of AA size battery, the Nickel Metal Hydride (NiMH) battery.

    Accessories

    Parts list from left to right:

    • powerful resistor 10 ohms (minimum 5 watts);
    • resistor 1 MΩ;
    • capacitor 1uF;
    • MOSFET transistor IRF510;
    • temperature sensor TMP36;
    • 5 volt power supply;

    How to charge NiMH AA batteries

    Increasing the charge rate increases the risk of battery damage.

    There are many ways to charge NiMH batteries. Which method you use mainly depends on how fast you want to charge your battery. The charge rate is measured in relation to the battery capacity. If your battery has a capacity of 2500 mAh, and you charge it with 2500 mA, then you charge it at a rate of 1C. If you charge the same battery with 250 mA, then you charge it at C/10.

    When charging a battery fast (above C/10), you need to carefully monitor the battery voltage and temperature so as not to overcharge it. This can seriously damage the battery. However, when you charge the battery slowly (at a rate below C/10), you are much less likely to damage the battery if you accidentally overcharge it. Therefore, slow charging methods are generally considered safer and will help you increase battery life. Therefore, in our homemade charger, we will use the charge rate of C / 10.

    charge circuit

    For this charger, the basis is a circuit for controlling the power supply with Arduino. The circuit is powered by a 5 volt source, such as an AC adapter or computer power supply. Most USB ports are not suitable for this project due to current limitations. The 5V source charges the battery through a powerful 10 ohm resistor and a powerful MOSFET transistor. The MOSFET transistor controls the amount of current flowing through the battery. The resistor is added as an easy way to control the current. Current control is done by connecting each end of the resistor to the Arduino's analog input pins and measuring the voltage on each side. The MOSFET transistor is driven by the Arduino's PWM output pin. The pulses of the pulse-width modulation signal are smoothed to a constant voltage by a filter on a 1 MΩ resistor and a 1 µF capacitor. This circuit allows the Arduino to monitor and control the current flowing through the battery.


    temperature sensor

    The temperature sensor serves to prevent battery overcharging and ensure safety.

    As an added precaution, a TMP36 temperature sensor has been added to the charger to monitor battery temperature. This sensor produces a voltage that is linearly dependent on temperature. Therefore, unlike thermistors, it does not require calibration or balancing. The sensor is mounted in a drilled hole in the battery holder housing and glued into the hole so that it is pressed against the battery when it is installed in the holder. The sensor pins are connected to the 5V rail, to the case, and to the Arduino analog input pin.

    AA battery holder before and after installation on breadboard

    Code


    The code for this project is quite simple. The variables at the beginning of the source code allow you to customize the charger by entering the battery capacity and the exact resistance of the power resistor. Safe threshold variables have also been added. The maximum allowable battery voltage is set to 1.6 volts. The maximum battery temperature is set to 35 degrees Celsius. The maximum charge time is set to 13 hours. If any of these safety thresholds are exceeded, the charger turns off.

    In the body of the program, you can see that the system constantly measures the voltages at the outputs of a powerful resistor. This is used to calculate the values ​​of the voltage on the battery and the current flowing through it. The current is compared to the target value, which is C/10. If the calculated current differs from the target value by more than 10mA, the system automatically adjusts the output value to correct it.

    The Arduino uses the serial interface to display all current data. If you want to control your charger, you can connect your Arduino to USB port computer, but this is not necessary, since the Arduino is powered by a 5V power supply from the charger.

    Int batteryCapacity = 2500; // battery capacity value in mAh float resistance = 10.0; // measured power resistor resistance int cutoffVoltage = 1600; // maximum battery voltage (in mV) that must not be exceeded float cutoffTemperatureC = 35; // maximum battery temperature that should not be exceeded (in degrees C) //float cutoffTemperatureF = 95; // maximum battery temperature that should not be exceeded (in degrees F) long cutoffTime = 46800000; // maximum time charge in 13 hours, which should not be exceeded int outputPin = 9; // output wire connected to digital pin 9 int outputValue = 150; // PWM output value int analogPinOne = 0; // first voltage probe connected to analog pin 0 float valueProbeOne = 0; // variable to store the value on analogPinOne float voltageProbeOne = 0; // calculated voltage on analogPinOne int analogPinTwo = 1; // second voltage probe connected to analog pin 1 float valueProbeTwo = 0; // variable to store the value on analogPinTwo float voltageProbeTwo = 0; // calculated voltage on analogPinTwo int analogPinThree = 2; // third voltage probe connected to analog pin 2 float valueProbeThree = 0; // variable to store value on analogPinThree float tmp36Voltage = 0; // calculated voltage on analogPinThree float temperatureC = 0; // calculated sensor temperature in degrees C //float temperatureF = 0; // calculated sensor temperature in degrees F float voltageDifference = 0; // difference between voltages on analogPinOne and analogPinTwo float batteryVoltage = 0; // calculated battery voltage float current = 0; // calculated current flowing through the load in (mA) float targetCurrent = batteryCapacity / 10; // target output current (in mA) is set to // C/10 or 1/10 of battery capacity float currentError = 0; // difference between target and actual current (in mA) void setup() ( Serial.begin(9600); // setup serial interface pinMode(outputPin, OUTPUT); // set pin as output ) void loop() ( analogWrite(outputPin, outputValue); // write output value to output pin Serial.print("Output: "); // show output values ​​for computer control Serial.println (outputValue); valueProbeOne = analogRead(analogPinOne); // read the input value at the first probe voltageProbeOne = (valueProbeOne*5000)/1023; // calculate the voltage at the first probe in millivolts Serial.print("Voltage Probe One (mV): "); // show the voltage on the first probe Serial.println(voltageProbeOne); valueProbeTwo = analogRead(analogPinTwo); // read the input value on the second probe voltageProbeTwo = (valueProbeTwo*5000)/1023; // calculate the voltage on the second probe in millivolts Serial.print("Voltage Probe Two (mV): "); // show the voltage on the second probe Serial.println(voltageProbeTwo); batteryVoltage = 5000 - voltageProbeTwo; // calculate the battery voltage Serial.print("Battery Voltage ( mV): "); // show battery voltage Serial.println(batteryVoltage); current = (voltageProbeTwo - voltageProbeOne) / resistance; // calculate charge current Serial.print("Target Current (mA): "); // show target current Serial.println(targetCurrent); Serial.print("Battery Current (mA): "); // show actual current Serial.println(current); currentError = targetCurrent - current; // difference between target and measured currents Serial.print("Current Error (mA): "); // show current setting error Serial.println(currentError); valueProbeThree = analogRead(analogPinThree); // read the input value of the third probe, tmp36Voltage = valueProbeThree * 5.0; // converting it to voltage tmp36Voltage /= 1024.0; temperatureC = (tmp36Voltage - 0.5) * 100 ; // conversion based on 10 mV per degree with a 500 mV offset // ((voltage - 500 mV) times 100) Serial. print("Temperature (degrees C)"); // show temperature in degrees Celsius Serial.println(temperatureC); /* temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; //convert to Fahrenheit Serial.print("Temperature (degrees F) "); Serial.println(temperatureF); */ Serial.println(); // extra blank lines to make it easier to read the data when debugging Serial.println(); if(abs(currentError) > 10) // if the current setting error is large enough, then adjust the output voltage ( outputValue = outputValue + currentError / 10; if(outputValue< 1) // выходное значение никогда не может быть ниже 0 { outputValue = 0; } if(outputValue >254) // output value can never be higher than 255 ( outputValue = 255; ) analogWrite(outputPin, outputValue); // write new output value ) if(temperatureC > cutoffTemperatureC) // stop charging if battery temperature exceeds safe threshold ( outputValue = 0; Serial.print("Max Temperature Exceeded"); ) /* if(temperatureF > cutoffTemperatureF) / / stop charging if battery temperature exceeds safe threshold ( outputValue = 0; ) */ if(batteryVoltage > cutoffVoltage) // stop charging if battery voltage exceeds safe threshold ( outputValue = 0; Serial.print("Max Voltage Exceeded" ); ) if(millis() > cutoffTime) // stop charging if charge time exceeds threshold ( outputValue = 0; Serial.print("Max Charge Time Exceeded"); ) delay(10000); // delay of 10 seconds before the next iteration of the loop )

    You can find the downloadable version of the source code at the link below.

    A few years ago, I set myself the task of developing a set of inexpensive devices that allow blind people to better adapt to the world around us. To date, together with a team of like-minded people, I have managed to implement several projects.

    In this article I want to talk about an ultrasonic cane attachment and an ultrasonic key fob - full-fledged devices, which are assembled from inexpensive available modules.

    The Ultrasonic Cane Attachment and Ultrasonic Keychain are devices for blind people that warn of obstacles that are above the level at which they can be detected with a conventional cane. Such obstacles can be cars with a high seating position, barriers, high fences. The ultrasonic nozzle is attached to a regular cane, and the ultrasonic keychain is hung around the neck or carried in the hand like a flashlight.

    The operation of the devices is based on the reflection of ultrasonic waves from obstacles. By measuring the time difference between the moment the pulse is generated and the moment the reflected echo is received, the distance to the obstacle can be determined.

    To develop devices, it is necessary to select a sensor for measuring distance, a control board and a signaling device, select batteries, a method for charging them, and suitable cases.

    ultrasonic sensor

    To measure the distance to an obstacle, two devices were tested:
    • Arduino Compatible Ultrasonic Module HC-SR04
    • Car parking sensors HO 3800
    Both devices work in a similar way. The differences are in the radiation pattern of the sensors, the maximum range for detecting obstacles and design.
    Comparison of sensor parameters:

    During the tests, it turned out that the HC-SR04 modules have a slightly worse ability to detect obstacles and work in difficult climatic conditions (cold).

    Both sensors, despite their differences, can be used in an ultrasonic cane attachment as a means of measuring the distance to an obstacle, so the main parameter for us when choosing a sensor was the price. We settled on the cheaper HC-SR04 sensor.

    Control board

    The Arduino platform was chosen as the control board. In our case, the boards of miniature versions are most applicable: Arduino Mini, Arduino Nano or Arduino Pro mini. In general, any other controller that provides similar capabilities can be used.

    Batteries

    To provide power to the device, it is advisable to use lithium-ion (Li-ion) or nickel-metal hydride (Ni-Mh) battery cells.

    When operating in normal climatic conditions, it makes sense to use Li-ion batteries, which have the following advantages compared to Ni-Mh:

    • ease of implementation of the charging scheme
    • availability of ready-made charge modules
    • higher output voltage
    • manifold overall dimensions and containers
    At low temperatures, it is preferable to use Ni-Mh batteries.

    The voltage at the output of one Ni-Mh battery (1.0 -1.4 V) is not enough to operate the device. To obtain a voltage of 5 V (necessary for the operation of both the Arduino and the parking lot), in addition to the batteries, we will use a DC-DC boost converter.

    For the operation of the DC-DC converters we have chosen, it is necessary to provide an input voltage of 0.9-6.0 V. To obtain the required output voltage, one could use one Ni-Mh element with a voltage of 1.2 volts. However, with a decrease in the input voltage, the load capacity of the converter also decreases, therefore, for stable operation device, it is desirable to supply at least 2 V to the input of the converter (two Ni-Mh elements of 1.2 V each or one Li-ion element with a voltage of 3.7 V). Note that there are DC-DC converters for which an input voltage of 1.2 V is not enough.

    Charging batteries

    For Li-ion batteries there are many ready-made inexpensive modules with end-of-charge indication.

    In the case of Ni-Mh batteries, everything is more complicated. We have not found ready-made embedded solutions on the market at the moment. To charge Ni-Mh batteries, you can use specialized external chargers or create your own charging circuit.

    One way to charge a Ni-Mh cell is serial connection with a battery of two linear stabilizers LM317 (or similar): the first is in current limiting mode, the second is in voltage limiting mode.

    The input voltage of such a circuit is 7.0-7.5 V. In the absence of cooling of the stabilizers, it is not recommended to exceed this voltage. The voltage on each Ni-Mh battery during charging should be about 1.45 V (the voltage of a fully charged Ni-Mh cell). To avoid overheating and failure of microcircuits, the battery charging current should not exceed 100 mA and can be increased up to 200 mA when using appropriate heatsinks.

    The advantage of this charging scheme is that there is no need to monitor the state of charge: when the desired voltage on the cell is reached, the current will automatically drop to a safe minimum.

    signaling device

    Depending on the choice of warning channel (auditory or tactile), an actuating device is selected - a buzzer or a vibration motor. In addition, you can combine both notification methods, allowing the user to switch between them.

    While testing prototypes, we found out that it is most convenient to transmit information about the proximity of an obstacle through vibration, because. in this case, the audio channel, which is very important for a blind person, is not engaged. Therefore, all products designed and assembled by us use vibration to warn of an obstacle. The vibration intensity is proportional to the distance to the obstacle.

    Frame

    We were not able to find a convenient case for an ultrasonic cane attachment among mass-produced cases. To test the device, we used a 3D-printed ABS plastic case. To print the case on a 3D printer, we developed the following 3D model:

    The result of testing prototypes

    During the development process, more than 12 variants of the product were assembled. Each new product eliminated the shortcomings of the previous ones: during the development process, we reduced the dimensions and weight of the product, selected an ultrasonic sensor that satisfies us both in terms of price and technical characteristics, abandoned the use of an audio channel and optimized the device operation algorithm. Together with the blind (Bortnikov P.V., Shalintsev V.A.), all assembled products were tested. As a result, we received the final sample.

    The following are the principal circuit diagram developed device:

    When disassembled, the ultrasonic keychain around the neck looks like this:

    All components used in the assembly, except for the 3D printed cane attachment housing, were purchased through AliExpress:

    1. Ultrasonic sensor HC-SR04.
    2. Adruino control board Pro Mini.
    3. Rechargeable battery 3.7 V 300 mAh.
    4. Voltage converter 0.9V ~ 5V to 5V 600 mA.
    5. Charging module AC/DC 220V to 5 V 1 A.
    6. Charger LA-520W.
    7. Signaling device: vibration motor for mobile phone 4x10mm DC 3V.
    8. Button PB-22E60.
    9. Case Gainta G1906 (for key fob).
    10. Transistor: bss138/bcr108 or optocoupler CPC1230N.
    The appearance and prices (including delivery from China) of the components used to assemble the ultrasonic cane attachment are shown in the figure:

    Of the components used in the assembly, the largest contribution to the cost of the device is made by the case printed on a 3D printer.

    The appearance and prices (including delivery from China) of the components used to assemble the ultrasonic key fob are shown in the figure:

    In the future, you can develop a mount for the Gainta G1906 body and use the device with such a body as a reed attachment.

    One of the ways to reduce the cost of devices is to save on labor costs and the cost of shipping device components to Russia by expanding production directly in China.

    The devices developed by us have the following characteristics:

    After conducting preliminary tests of the devices, we were forced to limit the detection range of obstacles to 1.5 meters in order to avoid unnecessary triggers when using the devices in a stream of people. With a continuous change in the vibration level, it is more difficult to determine the approach of an obstacle, therefore, according to the results of preliminary tests, we settled on three vibration levels.
    The appearance of the ultrasonic cane attachment:

    The appearance of the keychain around the neck:

    3D model of the ultrasonic cane attachment and source Firmware for Adruino is available for download at

    Good old "Rectifier"
    B14 charger"!
    You were always like a savior:
    Rescued us, darling!

    With heat and winter cold
    Revived the battery;
    Even if I have a cold
    You are like a robot Terminator!

    Didn't break, didn't give up
    Even in the most difficult hour;
    When necessary - strained,
    Charging everything for us.

    Forty years have passed
    From the good Brezhnev times,
    When your body is like a body
    It was attached at the factory.

    And since then you have served
    You are for the benefit of all machines,
    different from the Union
    The fact that the truth is indestructible.

    But it's time to change
    Throw off the heavy burden of time,
    So that you can climb up
    So that Hawking became smart.

    If someone asks falsetto
    "How can I do this?" -
    Don't worry, I'm talking about it
    In this article I will tell.

    A moment of addiction.

    Greetings, dear readers! After an almost four-month break, I am back in business and, as a report on the work done, I consider it necessary to write this article. I thought for a long time where to start, well, don’t post for the fourth time about zero visibility, etc. - this quote has been working for me for the last three articles so regularly, so enough is enough - let him go on a well-deserved rest! Well, in the meantime, I will use a new experimental trick, let's call it a "drug addiction minute" - such a fun and laid-back minute "with regards", smoothly leading to the main idea of ​​the article. 🙄

    So, as already mentioned in the "minute", today I will tell you about how I turned an old charger from the early seventies into a new, modern one, controlled by a microcontroller. This thought came to me because my friend invited me to his place for a beer at the moment when my battery was charging. I would have been glad to go, but that's bad luck - the charger had to be constantly monitored! Run to it once every half an hour, or even more often, to check the voltage on the battery, and if it exceeds the maximum, reduce the power with the corresponding switch on the front panel. Agree, it’s inconvenient: you are constantly chained to a charging battery and you can’t go anywhere, and if you suddenly miss the right moment, the battery won’t thank you. On the other hand, he won’t say it anyway: he doesn’t know how to speak a monument))))

    Jokes are jokes, but I have long wanted to do something serious on Arduino, which I met back in November, having taken the treasured package from the Chinese from Aliexpress with a microcontroller, shield and other goodies in the mail. And here it is, a great opportunity - take it, but do it! So I took it and started, directly, to do!

    Charger circuit

    In the beginning, I will give you a very clickable diagram of the finished device:

    List of main components

    • 8 capacitors: 2 x 22 pF, 1 x 100pF, a couple of pieces of 100 mF, and for power - one large 6.3 volt and two large 16, for example, and 1500 mF, respectively (everything can be 16 volts or more, doesn't matter).
    • Atmega328 programmable microcontroller with 16 MHz quartz and preferably a shield for it (flipping a few pages to the first shield, this will be the most cheap option) to make stitching easier.
    • For the same reason - clamp sockets for the above microcircuit. Although it is possible, as an economy option, you can get by with the usual ones. Well, or solder the wires to the MK and flash them with another arduino or flasher - as you wish.
    • 9 transistors KT315 and 1 KT815 (or analogues) - solder from any old Soviet technology.
    • 8 white diffusing LEDs and 1 green.
    • 9 relays with coils for 12 volts: one for 220 V, four for 12 V 16 A and four smaller ones for 12 V 12 A. The last 8 are needed as small as possible.
    • 40 resistors: 15 x 560 Ohm, 12 kilo-ohm, 8 x, 2 x 10k and one each 3k3, 4k7 and 30k.
    • A couple of diodes for 12 volts: one for a half-amp, the second minimum for an ampere, the margin will not hurt. It is soldered from anywhere, for example from a dead PSU.
    • Some kind of light bulb, you can LED with a resistor, burning from 220 volts. In general, neonka would look cool there!
    • A sixteen-segment screen from an old system unit to display the current voltage on it. Well, or three seven-segment. Or even hammer a bolt on displaying the current voltage: after all, this is an automatic device, it controls the voltage itself, you don’t need to know it, in extreme cases you can measure it with a tester. Instead of a screen, you can just put a couple of LEDs so that the arduina winks with them, they say, I don’t freeze, I’m working, everything is under control! (No, I have never seen a frozen Arduino, but nevertheless you have to be ready for anything.) 🙄
    • 3 shift registers 74HC595
    • Well, something like halves of such a circuit board (I bought 10 pieces on ebay for a glass of compote):

    I want to note that almost all the components used in this project do not have exact ratings and can be replaced with similar or similar ones, either with minimal adaptation of the circuit and firmware, or without any changes at all. I tried to use those details that were literally lying around at my fingertips: for example, the vast majority of the resistors and transistors used here I recently dropped out of an antediluvian Vilma tape recorder, the remains of which, after unsoldering, safely went to a landfill. So the amount spent on the purchase of parts for this device does not exceed $15, and even then, most of the budget was spent on relays.

    original charger version

    Unfortunately, I did not have a photo of this charger in its original state, so all I can offer you at this stage is a photo with the cover already removed, the mechanical part of the power switch (left) and the knob of this switch (right) unscrewed. Its electrical part sticks out on top of the device. Also, a voltage switching toggle switch (6 or 12 volts) was removed from its native hole:

    After carrying out the above manipulations, I also unsoldered the power wire from the fuse and the primary winding of the transformer, although it still lies in the right upper corner next frame. But you don't get too used to it - I found a great replacement for it, so you won't see it again.

    The principle of operation of the original device

    The charger itself is built according to simple principle- 220 volts is supplied to the primary winding of the transformer, respectively, an alternating voltage also appears on the secondary. Power can be controlled due to the fact that there are several outputs from the secondary winding (9 in total). This means that between the first and each of the next eight conclusions, everything is obtained large quantity turns, and the more turns, as you know, the higher the voltage (that is, current or power - as you please). These 8 pins come to the same switch with which you select the current battery charge power.

    It turns out that between the first output of the secondary winding and the output from the switch, we have an alternating voltage selected by this switch. But they still cannot charge the battery, because for this it needs to be turned into a permanent one, that is, straightened. Hence the name of this device - a rectifier.

    For straightening AC voltage this charger uses such a simple and reliable thing as a diode bridge, consisting of four powerful D242 diodes, planted on individual radiators and fixed on a dielectric substrate. So from the switch, the current goes first to the input of the diode bridge, and then from its output through the ammeter to the battery.

    The choice of the method of switching the secondary windings

    The most important problem of this project was the choice of a method for switching the above-mentioned conclusions of the secondary winding. There were many options, but right away I decided to try the most crazy and unreliable of them, but the easiest in terms of labor costs - connecting a servo instead of manually switching the switch position:

    I attached a servomotor to the switch, quickly wrote the firmware and tried to spin it, but as it turned out, the power was not enough and it sometimes got stuck in the most critical place, so this option, alas, did not work.

    Oh yes! I almost forgot! In fact, there were not 9 but 10 conclusions from the secondary winding, the first two were one for six volts, the other for twelve, both went to the toggle switch, and only then to the diode bridge:

    But since I didn’t plan to charge the batteries at 6V, I refused this function, so I threw out the toggle switch (from the design, and not at all) and insulated the wire for six volts, and let the twelve-volt one from the transformer directly to the diode bridge.

    So how do you commute? Here it is either transistors, or thyristors, or using a relay. And I chose the last option, because the relays are smaller than transistors / thyristors and, unlike them, do not heat up at all if you take them with a current margin. So I did - I bought 8 small relays with 12 volt coils, 4 pieces for 16 amps and 4 for 12. In size, they just fit in free space inside the charger case:

    Device operation algorithm

    And here, having finally decided on the method of switching the outputs of the secondary winding, I consider it necessary to make some "lyric advance" and talk about the algorithm for the operation of the device. Initially, to compile it, I simply analyzed my actions while charging the battery with this shaitan machine and based on this I began to sketch the first strokes of a new sketch that you can pick up. I will often quote some of its pieces so that you understand what's what, so, if I were you, I would open it right now and study it along the way.

    Let's start with 3 the most important parameter:

    // Max Voltage * 10
    byte maxVoltageX10 = 148;

    // Voltage * 10, at which it is no longer possible to increase power
    byte powerUpMaxTreshold = 142;

    // Voltage * 10 at which power will be forced up
    byte powerUpMinTreshold = 136;

    They are multiplied by 10, firstly, because when calculating them it is more convenient to use integers - no rounding, etc., and secondly, because such numbers are actually displayed on the screen, and the comma is, as it were, virtual , so there is no need to do unnecessary calculations in the code, and so it is clear that these are 14.8, 14.2 and 13.6 volts, respectively.

    The first parameter tells the program the maximum allowable voltage, above which the power will be reduced by one level, and if there is nowhere to reduce, the charger should simply turn off.

    The second parameter will be used at the beginning of the charging process - after switching on, the power will increase until the voltage on the battery is less than the value set by it.

    The third parameter was introduced specifically for cases when the battery connected to the car will be charged. For example, someone turned on the radio -> the voltage sank below this value -> we raise the power. But what if the load that drops the voltage to this level is short-term (turning on the headlights or cigarette lighter), or periodic, with a certain frequency (for example, from subwoofer strikes), and will come out so that as soon as the brains increase the power, it will be needed immediately reduce, then immediately increase again, etc.? It will turn out a vicious circle, the relays will constantly click, wearing out, and it may not be very useful for the battery either ... Specially for this, we can make our system, as it were, self-learning by entering additional parameter:

    // If less than this many milliseconds elapsed between powerup by powerUpMinTreshold and its decrease, then powerUpMinTreshold will decrease by 1
    unsigned int powerUpMinTresholdTimeout = 60000;

    As you can see from the comment, thanks to this parameter, powerUpMinTreshold will decrease by one tenth of a volt every time the brains decrease the power in less than powerUpMinTresholdTimeout milliseconds after it is increased. That's it, the problem is solved: the relays click once, click the second, and on the third they will think 10 times before clicking. Ha ha ha, contacted the wrong ones!

    Well, we seem to have more or less figured out the basis of the algorithm, now let's move on to the details and nuances.

    I immediately planned that the entire system would be powered from the battery itself, and 220 volts would be connected through a relay controlled by the brains (that is, Arduino), thanks to which we would be able to turn off the power supply to the device in case of an emergency or when the battery was charging . Moreover, there will be less sparking from the relay than from plugging the plug into the socket, so this option is also more reliable. About its connection will, of course, be written below, because so far we are discussing only theoretical issues.

    The power-on process will take place as follows: first you will need to plug the power plug into the outlet, after which, of course, nothing will happen, and then you will need to connect the battery itself, and if the voltage on it is more than eight volts, the whole system will start up and start charging it . But here another tricky parameter comes into play:

    // Delay in milliseconds before turning on charging
    unsigned int powerOnDelay = 2000;

    It is needed in order, for example, to reduce sparking in the relay unit, with the help of which the outputs of the secondary winding of the transformer will be switched in the final device, because the current on the first relay of the relay unit will be higher than on the relay supplying power to the transformer, moreover this second relay, in which case, it will be much easier to replace. That is, when the battery is connected, the power will first rise to unity, and then, after this delay, the power relay will turn on. These four lines of code in the power increase procedure are responsible for this:

    if (powerLevel == 1) (
    delay(powerOnDelay);

    }

    In general, this conditional operator could be clarified so that it is executed only once when it is first turned on, but, in theory, if this happens later, when the power drops to the first level from higher ones, nothing will change, the relay will be turned on anyway , so I decided not to fence an additional vegetable garden.

    By the way, there is a very interesting parameter in the code:

    // Power level (initial)
    byte powerLevel = 0;

    It, you guessed it, sets the initial power level and was introduced at a very early stage of firmware development and is currently used there simply as the current level. It is curious that if you increase it now, then the condition described in the previous paragraph will never work, that is, 220 volts will never get to the primary winding of the transformer, which means that the device will not charge the battery. Pichalka.

    Well, okay, let's not talk about sad things. Let's say we turned on the device and charging started. Everything is fine, but do not forget that after raising the current, the voltage on the battery does not rise instantly, and if you do not delay before increasing, then the brains will instantly transfer the power to the maximum level after switching on, and this is wrong, therefore the following parameter is introduced:

    // Time after which you can increase the power by one level, in milliseconds
    int powerUpTime = 5000;

    That is, between two power increases, at least 5000 milliseconds will have to pass, during which the voltage can already rise above powerUpMaxTreshold and then it will no longer be necessary to increase the power.

    As for lowering the power, everything is simple here: the program periodically checks whether the current voltage exceeds the maximum allowable level, and if it does, the power must be reduced:

    // Power Down
    if (voltageX10 > maxVoltageX10) (

    But if this condition is met, there should be two options for the development of events. The first is when the current power level is greater than one:

    In this case, we need to set the power to a lower level and continue charging further. Otherwise, when the power level was already the lowest, just turn off the power and blink the screen. Smile and wave, in short, the battery is fully charged!

    In general, as practice has shown, those batteries that I charged, even at the second power level, could be safely removed from charging, because the current already drops below 500 mA. Nevertheless, do not neglect the auto-shutdown function - batteries are different ...

    Also, for lowering power, there is a delay parameter similar to the powerUpTime parameter for increasing:

    //Pause after power down, in milliseconds
    int powerDownPause = 500;

    True, it is implemented more simply, through the usual delay () after a direct decrease. I figured that half a second is not such a long period to use it as an additional condition in the select statement, but to each his own, so if one of you has nothing to do, first of all, you could modify this piece of code according to the principle powerUpTime.

    It's amazing how I have already written so much and did not say where I get, in fact, the current voltage itself. Fixing:

    void loop() (
    ct=millis();

    It turns out that at the beginning of each iteration of loop "and, which, as you know, simply repeats endlessly after the system starts, we do two things. First, we write the current time since the start of the microcircuit, in milliseconds, to the ct variable, and then we just calculate the current voltage using the analogRead() procedure, using the monitoring analog input number specified at the beginning of the sketch:

    // Analog input for voltage monitoring
    byte voltageInput = 5;

    As well as 2 coefficients, which I will discuss in detail later:

    // Voltage calculation factor (divided by it)
    float voltageX10Coefficient = 5.11;

    // Offset voltage calculation (it's added)
    int voltageX10Shift = 35;

    But it would be too simple if everything was so simple. Therefore, to complicate the algorithm, 2 more variables were introduced into the code:

    boolean goingUp = true, isUpAfter = false;

    The first variable tells us what state the charging process is in right now. Its value is true until the power is reduced for the first time. That is, goingUp = true tells us that we turned on the charger not so long ago and it still charges the battery with the maximum possible current, never lowering it to protect against overvoltage.

    Everything is more complicated with the second one - it tells us whether the power increase occurred after goingUp became false and is set by the following simple piece of code at the end of the power increase procedure:

    if (goingUp == false) (isUpAfter = true;)

    Right now, you're probably thinking, why the hell do you need all this? I'll explain right now!

    The reason for adding these two variables was just the implementation of the ability to charge a battery standing on a car with a variable load connected to it. The first purpose of the goingUp function is to determine the parameter by which the power increase will work:

    if ((powerLevel<8) && (ct >powerTime + powerUpTime) && ((goingUp == true && voltageX10< powerUpMaxTreshold) || (goingUp == false && voltageX10 < powerUpMinTreshold))) {

    As you can see, in the first phase of charging, we increase the power if the current voltage is less than powerUpMaxTreshold, and in the second phase - if it is less than powerUpMinTreshold: these are the same parameters that I talked about at the beginning.

    If the conditional statement written above is still executed, and this very goingUp is equal to false, then the patented system comes into play additional verification voltage:

    boolean stillLow = true;
    if (goingUp == false) (
    for (int x=0; x<= upCycles; x++){
    voltageX10analogRead(voltageInput)+voltageX10Shift)/voltageX10Coefficient;
    if (voltageX10 > powerUpMinTreshold) (stillLow=false; break;)
    delay(1);
    }
    }
    if (stillLow == true) (

    In which a new character enters the stage:

    //Number of millisecond iterations of voltage check before power up
    int upCycles = 5000;

    The fact is that with a signal to increase power after goingUp has become false, we are most likely dealing with some kind of unstable load - the same subwoofer, as I already assumed, or some other unknown garbage. And if so, then why should we, instead of stupidly raising the power, once again clicking our precious relays and risking getting the battery voltage higher than the maximum specified for a moment, do not arrange a simple check: 5 thousand times (upCycles) with an interval of one millisecond, check the current voltage, and if it at least once, you hear, at least once exceeds powerUpMinTreshold - that's it, khan, there will be no increase, turn off the fishing rods! A simple but effective check.

    isUpAfter, in turn, helps us implement the powerUpMinTreshold decrease function (I talked about it at the beginning), here's what it looks like:

    if ((isUpAfter == true) && (powerTime > ct - powerUpMinTresholdTimeout)) (powerUpMinTreshold = powerUpMinTreshold - 1;)

    Here powerTime is the time of the last power increase to date.

    The fact is that, in addition to the condition of the powerUpMinTresholdTimeout mentioned above, we need to reduce it only when we lower the power after we have previously raised it after we have already begun to lower it. I said that with this isUpAfter everything is complicated!

    Here is such an algorithm, believe it or not. I will talk about the rest of its details and subtleties in the course of further narration about, directly, the assembly of the device.

    Preparing the relay box

    So, having figured out which contacts of the relays are responsible for what and having decided on their placement relative to each other, I started gluing:

    To do this, I used the "Moment - Crystal" lying nearby. I will not say that this is some kind of super-duper glue, but in terms of its properties, it suits me. It is better, of course, to use Khaigir's "Glue to Death", it dries faster and generally hardens at the end, but it is 2-3 times less in a tube, and it costs one and a half times more expensive than Moment, therefore, as the hero of one good Soviet cartoon said, "And so it will come down!"

    As for gluing, everything is simple and it is written on the tube - apply to both surfaces, wait 5-10 minutes and squeeze hard (yeah, so hard that the coal sandwiched between the relays turns into a diamond 😆):

    That's it, the relays are compressed. As you can see, I placed the central contacts next to each other, they still need to be connected to each other:

    I did the same with large relays, and then glued these 2 resulting blocks together with each other, after which I began to solder the wires to the contacts. The thick yellow wire is connected in turn to all the relays - this is the output bus, which will then go to the diode bridge, the red wires - to the first 4 outputs from the secondary winding of the transformer, and the small yellow wire that goes in turn through all the relays is constant +12 volts coils. And the minuses of the coils, as you may have guessed, are brown and white-some-thing-there wiring, we will return to them soon.

    The same design, but on the other hand, with new soldered wires for connecting the secondary winding leads. Moreover, from large relays, 1 output has 2 wiring - this is how this relay model is made, for a more even distribution of the load and, as a result, less heat generation:

    Since the current drawn by the coils in such relays (~100 mA) is much higher than the maximum current that can be taken from the outputs of the Arduino (~40 mA) or the 74HC595 shift register (~25 mA), transistors must be used to turn on the relay coils. And the good old orange KT315s seem to be made for this!

    This npn transistors, therefore, in the circuit, if explained in a simple way, the current should go from plus to the coil, then from it to the collector of the transistor and further from the emitter of the transistor to minus. This transistor opens with a current from the base to the emitter, but the current is needed there is very small, so we connect the bases of the transistors through resistors of 1 kOhm (1000 Ohm):

    Now it remains to solder short wires to the resistors, not forgetting to carefully isolate everything, and you can fix it - I personally decided to glue the transistors to the relays on the side so that they do not get confused and nothing comes off:

    As you can see in the photo, the transistors are perfectly located on both sides of the relay block, I also filled the rest of the contacts with glue to be sure that nothing will short-circuit or burn out anywhere:

    The transistors are glued and the block is almost ready:

    Now we face the question - what to connect the transistors to? To the Arduino? No, then there will not be enough outputs for other components, and in such situations, the saving microcircuit comes into play - the 74HC595 shift register. So much has been written about him on the Internet, so I will not write 3 paragraphs here, I will only say that thanks to such microcircuits, you can increase the number of Arduino outputs by donating only three for this. Moreover, they can be connected in series in a chain. Eat different variants similar microcircuits, for example, 16 outputs or 8, in different cases. In this project, I decided to use the 8-out option in a small SO-16 package. Although the work is jewelry, all this takes up little space, which is already lacking in the compact body of the device, which is not designed for such improvements:

    To indicate the current power of the device, I decided to use 8 LEDs, one for each pair of transistor / relay, for this I used an eight-wire cable, soldering each wire to the corresponding control channel, but not immediately to the register, but to the resistors, there is no electrical difference, but mechanically more reliable, I think. I, after a thorough check (more on that later), filled the microcircuit with the same glue and once again went through all the transistors with it - now this system has become even more "solid" and strong:

    Voltage indication system

    The time has come for theoretical tests of the display system. To display the current battery voltage, I used a screen from an old system unit from the time of the first Pentiums. There are no tricks with it, each segment is a simple green LED operating from 2-2.1 volts. The only exception is one - in it 2 segments are parallel and brought out on one leg. In total, the screen has 16 legs: 1 plus and 15 minuses. That is, power is always supplied to the plus, and the supply of land to a certain leg ignites the segment we need - everything is extremely simple, but how to implement it? To do this, we again use shift registers, this time 2 pieces. For prototyping breadboard I used the same 74HC595, but already in the DIP-16 package, because it is much more convenient to work with them. In the following picture, as you can see, the system is already assembled and running:

    But this system very different from what was included in the final device. Let's start with the fact that initially I decided to use a stabilizer to power the screen, although in the end I refused it and connected each leg of the screen through a 560 Ohm resistor, secondly, in this circuit, the LEDs are powered through another stabilizer, moreover, it feeds and the shift register itself. But in the end, there was only one stabilizer in my charger - made back in the USSR KREN5V, as you might have guessed, for 5 volts.

    However, at this stage, the method of powering the iron was not so important - the main thing was to learn how to display meaningful information on the screen, for which it was necessary to find out which segment each of the register outputs corresponds to and then create two arrays in the firmware - tens and ones, into which, using ones and zeros, fill in the desired mask for each displayed number, that is, 0-19 for the first two characters of the screen and 0-9 for the third character:

    // Templates for the screen
    char* dozens=("10000001","10111011","01100001","00101001","00011011","00001101","00000101","10101011","00000001","00001001", "10000000"," 10111010","01100000","00101000","00011010","00001100","00000100","10101010","00000000","00001000");
    char* ones=("10000010","10111110","10001001","10011000","10110100","11010000","11000000","10111010","10000000","10010000");

    Also, the order of connecting registers in the process further work has changed - the relay block will be the first in the chain, and only then the screen, the relays are still more important, however, at the moment this is not so significant, because the order does not really matter - just in the firmware, in the output procedure, you need to change a couple of lines places and everything.

    When the system started working, instead of the third shift register, I connected a ready-made relay block to it. And in order for the relays to also click, I needed a twelve-volt power supply (not from a Chinese switch, but stabilized, with a smooth voltage selection). If you want to use an unstabilized one - use a nine-volt one, or even 7.5 - they will have 12 volts just without a load. The main thing - do not confuse the permanent with the variable! The next photo shows how 12 volts are connected to the snot with two plugs with wires in the upper right corner 🙄

    Now the screen is working! I wrote a sketch that displays numbers from zero to 199 one by one on the screen, and their binary representation on the LEDs on the right. Well, it's fun!

    Work with shift registers, as I said, is carried out on three wires. Their contact numbers are set at the very beginning of my sketch:

    // Pin that is connected to ST_CP input of 74HC595
    int latchPin = 8, voltageX10,voltageGuard,ons,dz,
    // Pin that is connected to SH_CP input of 74HC595
    clockPin = 12,
    // Pin that is connected to the DS input of the 74HC595
    dataPin = 11;

    When the system starts, the mode of operation of these contacts, as well as the rest used by us, is set as OUTPUT:

    void setup()(
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
    pinMode(relay220Pin, OUTPUT);
    pinMode(fanPin, OUTPUT);

    Well, the output of information to the registers itself is as follows:

    digitalWrite(latchPin, LOW);



    Moreover, initially shiftOut() takes as input type variable byte, and since it is much clearer for us to write ones and zeros directly into the registers, the code uses special function bitseq(), which converts the above patterns to exactly what shiftOut() wants us to do:

    byte bitseq (char s)(
    byteab=0;
    for (byte ba=0; ba<8; ba++){
    if (s == "0") (bitWrite(ab,ba,0);) else (bitWrite(ab,ba,1);)
    }
    return ab;
    }

    By then, my desktop looked something like the following photo. Don't rack your brains wondering what the ambulance is on the monitor. Great series, I'm watching it for the second time. 🙄 By the way, to connect non-power circuits in my device, I used a twisted pair cable, the one that is category 5e, I just have a lot of it - I don’t throw old cables from the roof, but dissolve it. But for such things, not any wiring is good. Those that I used are not solid inside, but stranded, so they are very elastic and not brittle, they also have high-quality insulation. But I would not use an ordinary twisted pair with solid cores - it bends very tightly (well, relatively), and it would be generally unreasonable to solder it to small microcircuits in the SO-16 package. What, you say, they say, it was necessary to use DIP mikruhi? Ha, you haven't seen the masochism going on right now, so let's not pull the cat by the horns (yeah) - let's go!

    It's actually not such a bad idea to put small chips inside the indicator. After all, there is no place in the old case anyway, the front panel had to be put on small spacers, and if I used registers in DIP cases - uuuuuu, I don’t know how everything would fit in there!

    As I said, in the final version, the segments are connected through resistors, and not directly, but, nevertheless, I decided to show the first option too: maybe someone will like it more. Since this screen itself is filled with something on the reverse side (what a disgusting thing these fill screens of yours are), and the surface of this filling is also concave inward, I cut out a small flat plate from a plastic payment card, guess which Belarusian monopolist in the field of telecommunications, which I glued directly to the screen and then glued the registers themselves onto it, having previously marked the first leg on the back of each of them (because "Don't mix up the reviews, Kutuzau!").

    After soldering all the wires and, again, checking that everything worked, I filled everything with glue. Because one wrong move and the wiring will break off from the contact, something will short-circuit and there will be a big, big pichalka. But this will not happen with glue, everything is fine with glue. Glue, in short, rules. Until you have to tear it off 😆 👿 But let's not talk about sad things, here's what happened after these manipulations:

    So I even connected these two blocks together (albeit temporarily) to once again enjoy the blinking tsyferki and clicking relays:

    Unfortunately, when combining the screen with registers into one whole, I had to slightly change the order of connecting its legs, so after starting the whole system, I saw some alien numbers instead of Arabic numerals:

    Although, in fact, there is little alien in the one and nine, only in the middle there was some kind of garbage, but these are all trifles. The next step was to screw the voltmeter, that is, the creation of a voltage sensor, because the algorithm of my charger should depend on the current voltage.

    Measuring voltage with Arduino

    Arduino is a good thing, it initially has analog inputs on which you can monitor the voltage in real time. The only catch is that the measurement range of these inputs extends from zero to only five volts, and we will have voltages up to almost 15, so this problem must be somehow solved. And here the simplest voltage divider on two resistors comes to our aid. For example, we will take 20 volts for the absolute maximum (well, just in case, so that nothing, if anything, does not burn out), and our ceiling is 5, that is, a fourth of the maximum, which means we need to divide the voltage by 4. For To do this, we take 2 resistors of such denominations so that the denomination of the first is 1/4, and the denomination of the second is 3/4 of the sum of their denominations. For example, 10 and 30 kOhm. Or 5 and 15 kOhm, or 2.5 and 7.5, you get the idea. It is not worth taking less, because the current there is small. Well, connect according to the scheme: 10 between the analog input and ground, and 30 between the analog input and the charging output to the battery.

    But not everything is so simple - the analogRead() procedure will give you a value from 0 to 1024, where zero is zero, and 1024 is 5 volts for it or 20 volts for us. Therefore, to recalculate this value, we need to enter a certain coefficient, which we will set as a constant in the firmware header (float voltageX10Coefficient = 5.11;). Looking ahead a little, I’ll say that later the voltage that the Arduino sees, when high current it started jumping with a spread of up to half a volt, so we had to connect our impromptu sensor through a diode, after which I put a 16V 1000 mF capacitor, and I connected a 220 V relay there, but more on that at the end. Why am I talking about this now? Because the diode, as you know, slightly lowers the voltage, so I introduced a second coefficient that compensates for the presence of this diode (int voltageX10Shift = 35;), that is, first the second coefficient is added to the output value, and then what happened is divided by the first .

    As a result, voltage monitoring turned out to be a success - compare the readings with the tester (this is not a battery connected to the device, but the same home-made stabilized power supply):

    Charger Front Panel

    Next, it's time to do the face of our device. Initially, I had thoughts of making and sticking a new panel there, but on reflection, I figured out how to use the old inscriptions, so everything turned out to be quite meaningful. In place of the current regulator, holes are drilled for the LEDs, and the arrow on top just shows in which direction the current will be greater, well, cool!

    Now the LEDs have been put in their places, and the screen has been inserted into a new place, and even the rest of the holes have been used: in the hole from the current regulator there will be a light bulb connected to the primary winding of the transformer - it will light up when charging is in progress, that is, when the transformer 220 volts are supplied. And if charging seems to be charging, but the light is off, then check if you forgot to insert the plug into the outlet! In the hole from the 6-12 volt switch, a plastic edging for the LED is inserted, which through a resistor without a stabilizer will be connected directly to the battery and by the brightness of its glow it will be seen how charged the battery is. This is useful if the battery is generally dead and there is not even five volts on it to power the brain - then the diode will glow dimly and there will be no questions, they say, maybe the device is broken. Although, of course, I make excuses: if there were no hole, I would not even think about inserting anything there. It's always like this with men, if you know what I mean.

    By the way, you will say, they say, where did you, Andryusha, see car batteries discharged to 5 volts? Well, at that time I didn’t see them anywhere, but after finishing work on this charge, they brought me one of these. 3 volts. And I even charged it, and it's even alive, though, I believe, and sulphated to death. There was a second one in a similar condition, but nothing saved him 😆

    This is how the muzzle looked at that time from the back:

    And in the next photo, I slowly peel off the glue and replace the wiring with resistors. Of course, I also amputated the stabilizer in the lower left corner of the photo as unnecessary. And by the way, soldering resistors is much easier than wiring - if I were doing it all over again - I would do it right away, with resistors and these small microcircuits.

    Also in this photo in the upper left corner you can see how I connected the LEDs. They have a common minus, it goes along the inner radius and is connected to the common minus of the device through a 3.3 kOhm resistor - I picked this one so that it would be bright and not blind. Seems like it worked just right. Why is there only one resistor? Because at any moment of time, with the exception of the moment of switching the load between relays, only one LED will be lit on the display.

    Why except for the moment of switching? Because if one relay is turned off, and the second is then turned on - at the moment the first is turned off and at the moment the second is turned on, a spark will appear on their contacts, these sparks will form deposits on the contacts, due to which they will fail over time - it will increase their resistance, they will start to warm up, and that's it, memento sea! So it’s right to turn on the second relay first, and as soon as it turns on, turn off the first one, then we get rid of the sparks and the relays will live happily ever after! By the way, everything is done exactly like this on the native switch, so no, I didn’t come up with it, applause and flowers go to the car this case designers of the original device, and not your humble servant. Well, not everything is carnival for the cat. 🙄

    By the way, the switching delay between relays is set by this parameter:

    // Duration of transition between relays in milliseconds
    byte relayTransition = 80;

    But what happens if, in some magical way, two or more relays turn on at the same time for a time longer than the time allotted for switching, due to some kind of glitch? And it will be very bad: you, consider, will short-circuit the section of the secondary winding. The wires will start to melt, smoke will come from the transformer and Armageddon will happen in general. The one that Michael Bay filmed.

    So, dear gentlemen, ladies and van dammes, especially for this I came up with a system of protection against such an Armagedian. A 220 ohm resistor is connected to the plus of each LED. Why exactly 220? Firstly, because on that day the Moon was in Saturn, and secondly, because before the New Year I happened to unsolder a couple of domestic tape recorders, as well as a no less domestic electronic piano (or piano, I don’t know, but not a piano in short), so from there I soldered a whole box of these 220 Ohm resistors, you have to put them somewhere - well, great use!

    On the other hand, all these resistors are connected and pulled to the ground through a 4k7 resistor (this means 4.7 kOhm, it's time to call things by their proper names!), Of which I also have a hell of a lot more. So we measure at this point G, where all these 9 resistors converge, the voltage, that is, we connect this point to the next Arduino analog input, which is set by the following parameter:

    // Analog input for monitoring the number of switched on relays
    byte guardInput = 4;

    And by this voltage, we immediately see - how many LEDs are currently lit there, and since they are connected directly to the transistors, this is the same as we see how many relays are currently on, and this is exactly what we and it is necessary in this situation! That is, we set the voltage threshold, above which we firstly immediately cut off 220 volts with the help of the corresponding relay, and secondly, we try to correct the situation with the relays, and as soon as it is corrected, we turn on 220 again and continue to work as if nothing happened. Everything is simple and reliable, I checked!

    This threshold is set here:

    // Maximum allowable guardInput value
    byte guardTreshold = 160;

    And the procedure of the above check is performed every cycle of the loop and looks like this:

    // Check for the number of enabled relays and automatic shutdown - recovery - enable
    if (voltageGuard > guardTreshold) (
    digitalWrite(relay220Pin, LOW);
    while (voltageGuard > guardTreshold) (
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, bitseq(ones));
    shiftOut(dataPin, clockPin, MSBFIRST, bitseq(dozens));
    shiftOut(dataPin, clockPin, MSBFIRST, bitseq(relays));
    digitalWrite(latchPin, HIGH);
    voltageGuard=analogRead(guardInput);
    }
    digitalWrite(relay220Pin, HIGH);
    }

    And now I will nevertheless show the photo promised 9 paragraphs ago, at least just for decency:

    A removed cover shows us tension. Milota!

    AC connection relay

    However, we need to move on. As you can see, the charger is gradually assembled, the wires are gradually lengthening and two new characters enter the scene - the same 220-volt relay and a small twelve-volt cooler - eighty from the computer:

    Relyukha is ordinary, no different from others. Pulls 220 volts at like 10 amps. But we don’t need this, we also have a 1 ampere fuse. But the stock in such things is good, it is reliability. The coil of this relay works from 12 volts, but there are the same for 5. I immediately bought 25 of these on Ali, at a low price. Why did I take 12 and not 5? Look, wherever I turn it on - you still need a transistor, right? Even if it was 5 volts. Only now, if it is at 5 - it must be connected through a stub, through which all the brains are powered anyway, it would warm up even more from this - why the hell is it necessary? You can directly click at 12, but at least 15 will be there - she doesn’t care, she works. Moreover, starting from eight volts. I connected the LED to it just for indication at the time of testing, like if the LED lights up, then it works and virtually 220 volts went to the transformer. It is connected directly to the output of the arduino, through the same KT315, in the same way as the rest of the relays in the same block. And yes, the cut is also at 1 kOhm, although it will probably work 2 there, you can put those that are more, but keep in mind that the smaller the cut value, the more current will go nowhere through the transistor. For general energy efficiency, these + - a couple of milliamps do not care, but for low-current outputs of arduins and registers - not really, so here it is.

    The inclusion of this relay, as you probably already understood, occurs with the help of

    digitalWrite(relay220Pin, HIGH);

    And shutdown with

    digitalWrite(relay220Pin, LOW);

    Connecting a cooler to cool the charger

    But the cooler consumes like 140 milliamps, judging by the sticker on it, so KT315 will not be rolled here anymore, they are only up to a hundred according to the specification, so I took KT815A. They go up to one and a half thousand milliamps and it will be enough. There are other options, I just always try to use what I have a lot, maybe you, for example, will have some other transistor for the cooler, if it pulls up to 20 volts and up to 150 milliamps - put it, if n-p-n, then just see the pinout for the legs, and if p-n-p, then you need to change the circuit a little, but in this case it's all insignificant. There is just one more thing here...

    Have you ever heard a cooler beep? No, not from rotation, just beeps? I didn't hear it either, but I got lucky here. And all because the Arduino intermediate values output voltages (greater than zero, but less than five) are generated using PWM, that is, these are fast-fast voltage fluctuations, the pulse-width modulator itself operates at a certain frequency, and transistors, as you know, can also operate at fixed frequencies, so these pulses are transmitted through the transistor to the cooler and, due to its architecture, it starts to squeak. I won’t go into details, because I don’t know them myself, but all this is treated by sticking a 100 mF conduit plus to the base and minuses to the emitter of this transistor. The voltage there is up to 5 volts, respectively, the conduit can be set at least 6.3 volts. That's it, the squeak will disappear and there will be general nonsense!

    The number of the PWM contact by which the cooler is controlled is set by the following parameter:

    // Fan control output
    byte fanPin = 6;

    Its speeds from zero (0V) to 255 (5V) with reference to power levels are set by the following array:

    // Fan speed settings
    byte fanSpeeds=(0,0,80,90,100,110,120,180,255);

    And the very task of these speeds is written in the procedures for increasing and decreasing power:

    analogWrite(fanPin,fanSpeeds);

    Here, by the way, is a relay with a cooler closer:

    Further work on the front panel

    But let's go further. Here I already tried on the fuse in its place in the new case - the old one had supposedly several voltages, although in fact only one was used, and a piece was chipped off from it, and this one is like new, for 220 volts, from my father's stocks. Well, the same lower LED was installed and pasted on the same glue.

    Finally, it's time to assemble and replace the front panel! As you can see, all the wires are already soldered, even a five-volt KRENka sticks out at the bottom of the frame, spacers are screwed into the case to move the panel a little (I already talked about this), because before it was attached close to the case. As you can see, in many places I put the wires into the cambric so that nothing frayed or shorted anywhere. 12 volts to Krenka come directly from the diode bridge, with a wire of a higher class than a simple one twisted pair. The minus is connected to the common minus directly, but the plus is through a diode, otherwise Vasya Pupkin will reverse the polarity when connecting the battery and that's it, finita la comedy, re-solder half of the burnt components! And so you can be calm.

    After I figured out a couple of times how the wires would go between the case and the panel - I decided to glue them in the right places so that they would not hang out and interfere, I pressed down on the top with improvised objects, secured with clothespins and left it overnight so that the glue dries :

    Mounting the Atmega328P controller with strapping and other elements

    By this time, on the half of one of those same circuit boards, I had already mounted the lion's share of the remaining components - a socket for a microcircuit, quartz, conduits, a transistor for a cooler, etc. and so on.:

    The board itself had to be cut off on one side - it was too big and did not fit. I wrapped the lower part, and then the entire one, with paper tape so that it would not short-circuit anything during operation.

    By that time, the front panel had already been finally installed in its place of honor, and the five-volt KRENka was screwed to the case behind the panel through a heat-conducting insulating gasket and a plastic insert for the screw - thanks to this, the microcircuit will be reliably cooled through the massive metal case, without connecting to it electrically.

    Final setting of device parameters

    Here you can already see how the semi-assembled system works, but again, so far only from the power supply, because in my design the socket to turn on the battery is connected at the very last moment. Well, it just so happened, what to do ...

    After turning it on, it was found that at a high current, when the ammeter goes off scale, the charger sees a voltage of 0.5-0.8 volts more than it actually is on the battery at the moment. The test showed that as much as half a volt was lost on the wires, so I replaced them with better ones, with a larger section and soldered them to a cool plug, very suitable for the overall design of the device. This solved the problem, but not 100 percent - at high currents, some difference still remained. But I thought that this is not a bug, but a feature, because there is nothing to charge the battery with such large currents - let it work as some limiting factor!

    Here, by the way, the charging of my father's battery is in full swing, this can be seen on the ammeter. True, the 220 volt bulb turned out to be quite dim and it is almost invisible in the photographs that it is on. But it burns, trust me!

    Charger is ready!

    Here is a bottom view of the device. Initially, I planned to close up this entire gap between the case and the panel, but then I changed my mind - it’s better to let it ventilate!

    View from the left side. Well, or from the right - it depends on how you look, sorry for the pun.

    Well, it's on top. Here you can see that I glued the panel to the protruding part of the ammeter - it turned out to be a large third fulcrum, otherwise the panel sat somehow uncertainly. And so everything is hurt, reliable and beautiful! By the way, imagine if instead of the Crystal I used the usual Moment, and through the gap you could see all this light yellow crap. Fuuuuuu! 😳

    And, of course, the back view. On the fan, I fastened a beautiful grill that protects the fingers and other limbs of people and animals from injury. And here you can also see a new power cable, which, after charging, is conveniently wound onto the cooler and does not bother anyone!

    By the way, after assembling and testing the device, I had to disassemble it again in order to lubricate this fucking cooler, why didn’t I immediately lubricate it, was there such an idea ???

    Here is my first project on a programmable microcontroller. I spent almost a month working on it in the evenings. I even took a week-long break, because I got bored, this work is so boring or something. But I'm satisfied. Happy with the experience, happy that I was able to get this done, happy that I now have a great plug-and-forget automatic charger. And I am pleased that when my friends or acquaintances ask if I have a charger for their battery, I will hand it to them and proudly say that I made this cool thing!



    Magnetic induction is a technology you probably remember from high school physics classes. To transmit power wirelessly, you need two coils: a transmitter coil and a receiver coil. The alternating current in the transmitter coil generates a magnetic field which induces a voltage in the receiver coil. This voltage can be used to power mobile device or to charge the battery.


    Not less than important elements there will be inductors that you can make with your own hands. These simple coils are wound with copper wires and are called air-core coils. Creating such a winding for our purpose is a very simple task. Find a round cylinder with a diameter of about 5 centimeters, and wind the wire around it so that each turn does not overlap the other turn, but at the same time is as close as possible to the other turn. The round cylinder can be, for example, a PVC tube. You may need to use duct tape or tape in 2-3 places to keep the structure stable.


    In addition to the Arduino and the inductors, we will need: one 2N3055 NPN transistor, one 1A diode bridge (diode assembly, they have four leads), one LED, one 100 ohm resistor, two 47 nF capacitors, a 9 V battery to power the Arduino , and preferably two prototyping boards. The diagram for connecting components to create a wireless data transmission device is shown in the figure below.



    The circuit can be tested with the simple Arduino code below.


    void setup() ( pinMode(13,OUTPUT); ) void loop() ( digitalWrite(13,HIGH); delay(0.5); digitalWrite(13,LOW); delay(0.5); )

    However, a simple wireless power transfer device can be made without an Arduino. In principle, we can only use one 2N2222 transistor. Connect its base lead to the first end of the coil and the collector to the other end of the coil. The emitter terminal is connected to the battery. As a result, such a simple construction may look like this:




       Thank you for your interest in the information project site.
       If you want interesting and useful materials came out more often, and there were fewer ads,
       You can support our project by donating any amount for its development.