DIY

Automation for the tank to the country

Automation for a tank to the country With the beginning of the spring-summer season, the issue of watering at the summer cottage becomes relevant. It is correct to water it not with cold water from a well, but with warm water from a container installed in a summer cottage. It is clear that water must first be pumped into the container from the well. And it is very convenient when the process of filling the container is automated. Those. the pump turns on when the container is empty and turns off when it is full.
From this article we will learn how to do it.
Tools and materials: -Microcontroller ATmega328P Xplained Mini with a cable for programming; -Polypropylene float switch – 2 pcs; -Relay KY-019; -Jumpers;
-Electric extension cord;
-Barrel of water; < br> -External battery for powering ATmega328P;
-Plastic container for placing electronics;
-2 brackets for installing float switches
– Insulation tape;
-Glue gun;
-Fasteners;
-Drill;
-Screwdriver;
Step one: extension cord
First you need prepare an extension cord. A relay will be placed inside it and you need to cut one section of contacts, on both sides.
Automation for the tank on dacha Automation for a tank to the country  Automatic equipment for the tank to the dacha Step two: relay
The next step is to install and connect the relay module. The place is prepared for it, and the connection is simple. One of the wires in the cable must be connected not to the contact pad, but to the “COM” contact of the relay. Then you need to install a jumper between the “NO” contact of the relay and the second contact plate of the carrier.
 Automatic equipment for the tank to the dacha Automation for the tank to the country  Automatic equipment for the tank to the dacha Step Three: Installing Float Switches
Next, you need to install two float switches in the barrel. The master fixes the switches on the brackets, and the brackets are mounted inside the barrel, one at the top, the second at the bottom. After fixing the brackets, you need to bring out the wires. The attachment points and holes for wires must be sealed.
Automatic equipment for the tank to the dacha Automation for the tank to the dacha Step four: connection
All electrical parts are installed in a plastic box. They are connected according to the scheme.
Automatic equipment for the tank to the dacha Automation for the tank to the dacha Step five: software
Next you need to download the AtmelStudio 7.0 program to your computer.
Open AtmelStudio. Click “File” – & gt; “New” – & gt; “Project”.
Then “GCC Executable Project C”. We give the project a name and storage location. We confirm “OK”.
Find the ATmega328P. Click “ATmega328P” – & gt; “OK”.
In the terminal, click “main.c”.
 Automatic equipment for the tank to the dacha Automation for a tank to the country Delete the code that is already in main.c and paste the code below.
< pre> #define F_CPU 16000000 #include & lt; avr/io.h & gt; uint8_t top_switch_state; uint8_t bottom_switch_state; void floatSwitchInit (void) & # 123;/* top sensor */DDRD & amp; = ~ (1 & lt; & lt; 0); //set pinD0 as input PORTD | = (1 & lt; & lt; 0); //use pull-up resistor on pinD0/* bottom sensor */DDRD & amp; = ~ (1 & lt; & lt; 1); //set pinD1 as input PORTD | = (1 & lt; & lt; 1); //use pull-up resistor on pinD1} void relayInit (void) & # 123; DDRB | = (1 & lt; & lt; 1); //set pinB1 as output PORTB & amp; = ~ (1 & lt; & lt; 1); //set portB1 low} int main (void) & # 123; //Initialize the components floatSwitchInit (); relayInit (); while (1) & # 123; //if water is above top level, turn off pump top_switch_state = PIND & amp; (1 & lt; & lt; 0); if (top_switch_state == 0) & # 123; PORTB & amp; = ~ (1 & lt; & lt; PORTB1); } //if water is below bottom level, turn on pump bottom_switch_state = PIND & amp; (1 & lt; & lt; 1); if (bottom_switch_state == (1 & lt; & lt; 1)) & # 123; PORTB | = (1 & lt; & lt; PORTB1); }}}

Next, connect the microcontroller to the computer and perform the following actions.
Click on the “hammer” tool.
Select the “mEDBG * ATML” debugger/programmer.
Select the “debugWIRE” interface.
Click “start without debugging”.
This action will write the code to the microcontroller.
Now you can check if everything is working correctly. You need to connect any load to the extension cord, for example a light bulb and check the operation of the device.

Everything is ready, it remains only to test the device in real conditions.

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button