To come in
Sewerage and drainpipes portal
  • Connecting a rotary encoder to a computer via USB
  • Homemade TV backlight from USB
  • Evaluation of methods for measuring low frequencies on the Arduino Brief description of the frequency meter FC1100-M2
  • Photoresistor and LEDs on Arduino
  • Line transformer tvs
  • Complementary FET Hi-Fi Amplifier
  • PIC controller. PIC programming

    PIC controller.  PIC programming

    This article proposes a digital thermometer circuit based on an AVR ATtiny2313 microcontroller, a DS1820 (or DS18b20) temperature sensor connected to the microcontroller via the 1-wire protocol, and a 16x2 LCD display on the HD44780 controller. The described device can be widely used among radio amateurs.

    The program for the microcontroller is written in assembler in the AVR Studio environment. The installation is performed on a breadboard, a 4MHz crystal resonator, the ATtiny2313 microcontroller can be replaced with an AT90S2313 by first recompiling the source code of the program. The error of the DS1820 sensor is about 0.5 C. The archive also contains the firmware for the case if the DS18B20 sensor is used. The sensor is polled every second.

    The WAV player is built on the AVR ATtiny85 microcontroller (ATtiny25 / 45/85 series can be used). The microcontrollers of this series have only eight legs and two PWM (Fast PWM) with a carrier of 250kHz. To control the memory card, only 6 wires are enough: two for power supply and four signal wires. Eight legs of the microcontroller are enough for working with a memory card, sound output and control buttons. In any case, this player is very simple.

    With this capacitance meter, you can easily measure any capacitance from units of pF to hundreds of microfarads. There are several methods for measuring capacitance. This project uses an integration method.

    The main advantage of using this method is that the measurement is based on the measurement of time, which can be done fairly accurately on the MC. This method is very suitable for a homemade capacitance meter, moreover, it is easy to implement on a microcontroller.

    This project was made at the request of a friend for installation on a door to a warehouse. In the future, several more were made at the request of friends and acquaintances. The design turned out to be simple and reliable. This device works like this: it lets through only those RFID cards that were previously entered into the device's memory.

    On a seemingly outdated 2051 controller, we have often thought about assembling a similar meter, but on a more modern controller to provide it with additional capabilities. Basically, there was only one search criterion - these are wide measurement ranges. However, all similar schemes found on the Internet even had a software range limitation, and quite significant. For fairness, it is worth noting that the above-named device for 2051 had no limitations at all (they were only hardware), and software even included the measurement capabilities - mega and -ig of values!

    Once, studying the circuits once again, we discovered a very useful device - the LCM3, which has decent functionality with a small amount of details. The device is able to measure inductance, capacitance of non-polar capacitors, capacitance of electrolytic capacitors, ESR, resistances (including ultra-small ones), and evaluate the quality of electrolytic capacitors within the widest range. The device works on the well-known principle of frequency measurement, but it is interesting in that the generator is assembled on a comparator built into the PIC16F690 microcontroller. Perhaps the parameters of this comparator are not worse than those of the LM311, because the declared measurement ranges are as follows:

    • capacitance 1pF - 1nF with a resolution of 0.1pF and an accuracy of 1%
    • capacitance 1nF - 100nF with 1pF resolution and 1% accuracy
    • capacitance 100nF - 1μF with 1nF resolution and 2.5% accuracy
    • capacity of electrolytic capacitors 100nF - 0.1F with 1nF resolution and 5% accuracy
    • inductance 10nH - 20H with 10nH resolution and 5% accuracy
    • resistance 1mOhm - 30Ohm with 1mOhm resolution and 5% accuracy
    For more information on the description of the device in Hungarian, please visit:

    We liked the solutions applied in the meter, and we decided not to assemble a new device on the Atmelov controller, but to use the PIC. From this Hungarian meter, a partial (and then - and completely) circuit was taken. Then the firmware was decompiled, and a new one was written on its basis, for our own needs. However, the author's firmware is so good that the device probably has no analogues with it.

    Click to enlarge
    Features of the LCM3 meter:

    • when turned on, the device must be in the capacitance measurement mode (if it is in the inductance measurement mode, then the appropriate inscription on the screen will ask you to switch from another mode)
    • tantalum capacitors should be with the lowest ESR possible (less than 0.5 ohms). ESR of CX1 33nF capacitor should also be low. the total impedance of this capacitor, inductor and mode switch button should not exceed 2.2 ohms. The quality of this capacitor as a whole should be very good, it should have a low leakage current, so you should choose from high-voltage (for example, 630 volts) - polypropylene (MKP), styroflex-polystyrene (KS, FKS, MKS, MKY?). Capacitors C9 and C10, as written in the diagram, are polystyrene, mica, polypropylene. The 180 ohm resistor should be 1% accurate, the 47 ohm resistor should also be 1%.
    • the instrument evaluates the "quality" of the capacitor. there is no exact information about which parameters are calculated. it is probably leakage, dielectric loss tangent, ESR. "quality" is displayed as a filled cup: the less filled, the better the capacitor. the cup of a faulty capacitor is completely painted over. however, such a capacitor can be used in a linear regulator filter.
    • the choke used in the device must be large enough (withstand a current of at least 2A without saturation) - in the form of a "dumbbell" or on an armored core.
    • sometimes, when turned on, the device displays "Low Batt" on the screen. in this case, you need to turn off and then turn on the power (probably a glitch).
    • There are several versions of the firmware of this device: 1.2-1.35, and the latter, according to the authors, is optimized for a choke on an armored core. however, it also works on a dumbbell choke and it is only in this version that the quality of the electrolytic capacitors is evaluated.
    • It is possible to connect a small attachment to the device for in-circuit (without desoldering) ESR measurement of electrolytic capacitors. It lowers the voltage applied to the capacitor under test to 30mV, at which the semiconductors do not open and do not affect the measurement. The scheme can be found on the author's website.
    • The ESR measurement mode is activated automatically by inserting the probes into the corresponding socket. If, instead of an electrolytic capacitor, a resistor (up to 30 Ohm) is connected, the device will automatically switch to the low resistance measurement mode.
    Calibration in capacity measurement mode:
    • press the calibration button
    • release the calibration button
    Calibration in inductance measurement mode:
    • close the probes of the device
    • press the calibration button
    • wait for the message R = .... Ohm to appear
    • release the calibration button
    • wait for the message about the end of calibration
    Calibration in ESR measurement mode:
    • close the probes of the device
    • press the calibration button, the screen will display the voltage applied to the measured capacitor (recommended values ​​- 130 ... 150 mV, twisted from the choke, which must be placed away from metal surfaces) and the ESR measurement frequency
    • wait for the message R = .... Ohm
    • release the calibration button
    • the resistance reading on the screen should go to zero
    The ability to specify the capacity of the calibration capacitor manually has also been implemented. To do this, the following circuit is assembled and connected to the programming connector (the circuit may not be assembled, but simply close the necessary contacts):


    Then:

    • connect the circuit (or close vpp and gnd)
    • turn on the device and press the calibration button, the value of the calibration container will appear on the screen
    • use the DN and UP buttons to adjust the values ​​(it is possible that the main calibrate and mode buttons work in different firmware versions for faster adjustment)
    • depending on the firmware version, another option is also possible: after pressing the calibration button, the value of the calibration capacity appears on the screen, which begins to grow. When it reaches the desired value, you need to stop the growth with the mode button and open vpp and gnd. If you did not have time to stop in time and jumped over the desired value, then using the calibration button you can reduce it
    • disable the circuit (or open vpp and gnd)
    Author's firmware v1.35: lcm3_v135.hex

    PCB: lcm3.lay (one of the options from the vrtp forum).

    On the supplied printed circuit board, the display contrast of 16 * 2 is set by the voltage divider across the 18k and 1k resistors. If necessary, you need to select the resistance of the latter. FB - ferrite cylinder, you can put a choke instead. For greater accuracy, two 360 ohms in parallel are used instead of a 180 ohm resistor. Before installing the calibration button and the measurement mode switch, be sure to check their pinout with a tester: often there is one that does not fit.


    The case for the device, following the tradition (one, two), is made of plastic and painted with black metallic paint. Initially, the device was powered by a 5V 500mA mobile phone charger via a mini-USB socket. This is not the best option, since the power was connected to the meter board after the stabilizer, and how stable it is when charging from the phone is unknown. Then the external power supply was replaced by a lithium battery with a charging module and a step-up converter, the possible interference from which is perfectly removed by the usual LDO stabilizer present in the circuit.


    In conclusion, I would like to add that the author has put maximum capabilities into this meter, making it indispensable for the radio amateur.

    When diagrams are made, it is necessary for someone or something to control the execution of the necessary steps. For a person, this is quite problematic, since you have to use a significant number of different elements that allow you to control their work (transistors, resistors, thyristors, diodes, capacitors, and others). But all complex and large circuits can be controlled using controllers (microcontrollers). What they are will be described using the example of the PIC families. So for dummies? What is their scheme and where are they used.

    What is a PIC microcontroller

    A PIC controller (or microcontroller) is a means of automating the execution of certain actions using a pre-prepared program. A feature of the representatives of this product line is the ease of programming and the availability of all the necessary functions for work. Outlining its design, it should be noted that it contains only one silicon crystal (this is a characteristic feature of all microcontrollers). In addition to it, the PIC controller has a certain number of pins. Some of them can be used as logic inputs, some as outputs, the rest are bi-directional. Legs can be either digital or analog.

    The overwhelming majority of PIC controllers require a stable voltage of 5V to operate. This is enough for him to work in his usual mode and execute the program assigned to him. directly from a computer is not possible. A programmer is used for this purpose.

    Controller families

    The PIC controller does not exist in a single instance. The manufacturer company produces a significant range of microcontrollers, each of which has its own characteristics, capabilities and potential applications. The number of families themselves is quite large and depends on the classifying characteristic, which is taken as the main one. Therefore, it is worth reporting only about the main classification, in which there are only three families: 8-, 16- and 32-bit. They, in turn, are divided into others, but since the families themselves are not the topic of the article, then they will not be discussed.

    Where is applied

    Due to its versatility, the PIC controller can be used almost anywhere. Microcontrollers themselves can be found in refrigerators, televisions, washing machines. But the PIC product line has the peculiarity that PIC-based circuits are popular among radio amateurs and self-taught robotics. With their help, you can easily customize the operation of the unit or the entire device. Reasonable price, ease of programming and a significant amount of educational material contribute to this popularity.

    You can use the PIC controller when creating a robot arm and in other crafts that can be done on a modest budget. It can also be used for something industrial - the topic of creating automatic self-made machines controlled by a microcontroller is quite popular. The range of use is wide, and with a competent approach, almost any purpose can be fulfilled, so circuits on PIC controllers can be seen not only on amateur creations.

    PIC software

    The minimum software required is a notepad. But still, due to free distribution, you can use the MPLAB software tool offered by the manufacturer. More precisely, a line of software tools (development environments, compilers) MPLAB. Thanks to the company's policy, it is distributed free of charge, but has certain restrictions. So, with a short-term demo version, you can try with all the possibilities, but after its completion, the functionality of the program will be curtailed. A full-fledged program contains significant tools that make it easy to create programs, conveniently search for various problem areas and optimize the code. Depending on the version, the code optimization function may be discontinued or the number of controllers supported by the program may be reduced. For the sake of truth, it should be said that the company leaves support exclusively to the most popular representatives.

    There are also a number of software provided by other companies. In general, their functionality is similar, but there are differences. For example, many complain that MPLAB has a design that is disloyal to users. Therefore, manufacturers rely on the preservation of the trimmed functions and the convenience of working with their software. Programs for PIC controllers are very diverse, so this is largely a matter of taste.

    Creating a program for the PIC controller

    You can create a special program using the appropriate software and even in a simple notepad. This possibility exists due to the fact that it works with such programming languages ​​as assembler and C. The main difference lies in the amount of written information and the ease of specifying data. You can hear a lot about the complexity of C, but assembler is even more complex and requires a more thorough approach.

    So, when creating a program, you must specify for which controller it is intended. It may be necessary to make a number of adjustments, but they must be carried out if you have experience or confidence in your abilities, because mistakes can lead to the fact that microcontrollers turn into ordinary pieces of plastic and iron.

    Programming with the programmer

    But how to transfer the developed program to the microcontroller itself? How are microcontrollers programmed? There are special devices for this purpose - programmers. They send signals to the microcontroller that change the locations in memory according to the program. To start the process of transferring data, you need to insert the microcontroller into the programmer, and, in turn, connect it to the computer. Then, using the software, you should run the firmware. Typically, PIC programming lasts from thirty seconds to two minutes.

    Types of programmers

    Which programmer should I choose to write a program to a microcontroller? Conventionally, three types can be distinguished: self-made, from the manufacturer and factory from other companies. The use of each of them has its own characteristics.

    So, homemade programmers are pretty cheap. But their use is fraught with the fact that they can easily turn the microcontroller into a piece of plastic and iron. And programming microcontrollers can in such cases turn back to unpleasant consequences in the form of electric shock, so you should adhere to safety precautions. In addition, if you do it yourself from scratch, you will often end up with a product with rather limited capabilities regarding changing the object of work. But on the world wide web you can find a significant number of solutions to this problem, proposed by other people, and which probably will not give you problems.

    The original programmer from the manufacturing company will be able to do its job efficiently for any microcontroller. There is a guarantee for it, and if after receiving it does not work, then it is not a problem to replace it. But in the order of things, when the firmware of PIC-controllers is carried out without problems.

    But the rather high price stops him from purchasing.

    Programmers released by other companies have a fairly wide range of objects to work with. Their feature is low price and / or the ability to work with other microcontrollers except PIC. There are also truly versatile "monsters" that can support various types of work, but due to the need to create a large number of connections, their price is never low.

    Schematic features

    And finally, a few words about image schemes. You should be guided by the legs on the basis of the accompanying documentation, since schematically microcontrollers often differ from the actual construction of conclusions. The main thing in such cases is the signed conclusions, and it is by them that one should be guided when creating a device.

    Light and extractor hood in the bathroom.

    Touch-sensitive combination lock.

    Touch button to turn on the PC.

    When the PC is turned off nothing lights up and does not work.

    When you touch the sensor, the backlight responds with a short flash, then the contacts are closed
    the relays remain in the closed position until the 2nd leg of the MC appears a signal lowered to +5 volts from the +12 volt bus of the computer's UPS, as soon as the signal is received, the relay contacts open and the sensor backlight turns on smoothly. If the voltage of +12 volts does not appear within -2 seconds, the relay turns off, and the backlight double-blinks to indicate a malfunction code, to reset
    you need to turn off the computer. To turn off, it is enough to hold down the sensor for 3 seconds and the MK will make a hard shutdown of the PC. In this case, the relay contacts close and hold until 2
    When the +12 volt signal from the computer's power supply unit disappears, as soon as +12 volts are gone, the sensor releases the relay contacts and turns off the backlight.

    To control the operation of the sensor during holding, the backlight blinks. Hang the circuit on the power supply of the standby line of the wall-by in 5 volts. When the computer is turned off by software, the backlight will go out as soon as the 12 volt power supply is lost.

    MEGA IR RECEIVER FOR 35 CHANNELS.

    Support for consoles with NEC protocol. First, we write down the "Master" button on the remote control. Using it, we turn on the mode of rewriting the buttons of the remote control into the memory of the MK. Next, write down the 35 selected buttons on the remote control.
    Correspondence of the recorded commands to the MK legs, the first command belongs to leg 2 and so on in a counterclockwise circle, skipping the MK power legs (a freshly programmed MK is ready to write commands from the remote control to its memory immediately after power is applied). After turning on the power, the LED from 2 legs blinks three times and the MK is ready for recording, when the button is recording, it also blinks, talking about recording, after recording the last 35 buttons, its glow is slightly longer. When it goes out the MK is ready to work.

    In the EEPROM memory, you can configure the mode of operation of each leg in toggle or hold mode. To do this, starting from address 02 EEPROM to 06 address, it is necessary to write down the correct numbers, which we obtain in the following way. The legs are "grouped" by 8 pieces, since there are only 8 bits in one EEPROM register in the MK. Let's say we want the first three legs to work in hold mode and the other 5 in toggle mode. We write down the number 1 for the leg that will work in hold mode and the number zero for the switch mode. From here we get this kind of number in the binary system 00000111 - the first leg is counted from right to left, this number must be converted to hexadecimal form, which in this case is easy, but a convector of numbers may be required. We get the number 07 in hexadecimal form, ready to be written in the programmer. We also do the same to configure the remaining pins. In the current firmware, all pins are configured in hold mode (-FF numbers are written). In the last cell at address 06 of the EEPROM memory, we use only the first three bits, the rest are not used (00000111).

    Light and extractor hood in the bathroom.

    The device is designed to control the switching on of the light and the exhaust fan in the bathroom.

    In the off mode, the backlight of the switch is constantly on.

    When the switch is turned on, the lighting lamp is smoothly ignited (we extend the lamp life), after which the exhaust fan is immediately turned on. The backlight starts flashing, indicating that the room is occupied. If you forgot to turn off the light, it will automatically turn off after an hour and the backlight will go out, which indicates the reason for the shutdown.
    The switch must be returned to the off position, the backlight will immediately turn on, after which it can be used again in normal mode.After the light is manually turned off, the backlight goes into normal mode (permanently on), the exhaust fan works for another three minutes.

    Structurally, the circuit is designed for laying new wiring,
    which is what my godfather did when building a bathroom.

    The second version of the firmware for housekeepers, the scheme has become simpler. Scheme. Firmware.

    12 command IR receiver on PIC12F629

    The device allows you to record 12 commands from the IR remote control into the MK memory and display their reception on their outputs in binary form in the button hold mode, after releasing the remote control buttons there will be zeros at the MK outputs.

    To control the driver, any IR remote control from household appliances with the NEC protocol is suitable. The reception range depends on the location of the receiver and the remote control used.

    How to determine the suitability of the remote control and program the buttons. We supply power to the circuit, the LED on the board "blinks" three times, indicating readiness for recording.

    Then we press alternately 12 buttons during programming when pressing the next button, the LED on the board "flashes" indicating a successful recording. At the end of programming, the LED will blink three times and no longer respond to commands, but switches to the button scan mode.
    If the wrong commands are set or to change the remote control, you must press the button on the device and repeat the dialing, the button is active only after all commands have been entered.

    Binary data output on legs 7-6-5-3. That is, the number of the received command is displayed in accordance with the order of their recording. The first recorded command is accepted - the number 1 is displayed, etc. In rest mode, the terminals are 0000.

    IR control of electric drive -2.

    Simplified version.

    The device is designed to control the electric drive of the actuator performing the action of opening and closing any mechanism, such as gates, curtains, TV exit, etc. The determination of the performed action is carried out using two limit switches, which are normally open in the free position.

    The universal IR receiver program supports almost all remote control protocols. The remote control can be recorded by pressing and holding the “remote control record” button from the power off state, after turning on the power, release and press the selected button on the remote control. The remote control button must be held for more than three seconds, after releasing the button, the device is ready for use, the button code will be written into the MK memory and it will not be necessary to re-record if the device's power was turned off (to overwrite the remote control button, the procedure must be repeated).

    Slightly improved firmware, PIN code corrected, now you can select numbers for the code in any order. Improved sound. And in the archive there are two options with different sensor sensitivity. Although such schemes are calculated to determine the change in the capacitance of the sensor sites, the used power supply unit and also the room in which the device will operate quite strongly affects the operation of the device. Therefore, now it is possible to choose the firmware that works with the best performance.

    Changes - it is possible to independently adjust the time for outputting the signal to the executive device after the correct PIN code is typed, by changing the numbers in the EEPROM memory in the cells immediately after the PIN code at 05H and 06H. Time can be calculated by calculation Time in seconds = ADR_05H (1- do not write zero) * ADR_06H (50- decimal digits) * 0.02 seconds = we get a delay of 1 second. Now, there is still no indication of the LED of the pressed digit from the 8th leg of the MK, as such, there is no, instead, the number of the pressed button is displayed in binary form at the conclusions 11-10-9-8, the 8th leg is the lowest BIT and so on.
    Using a decoder type 155ID3, you can get an equivalent output for each digit (LED).

    P.S. The numbers for writing to the EEPROM must be converted, programmers do not support the decimal system.