Design and production of automatic control system for fish tank with automatic fish feeding

Publisher:火箭少年Latest update time:2021-12-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I am often away from home for several days, and have always wanted to make something that feeds fish automatically. I searched for it on the Internet for a long time, and I saw one that used a 15F104W microcontroller and only used the timer function to vibrate the fish food at a fixed time. I didn't like it very much. Today I would like to share with you a small work that I designed and made by myself, and I am quite satisfied with it.


The actual picture produced is as follows:

insert image description here
insert image description here
insert image description here

Pin Assignment lcd lcddata: P0

lcd_e: P2^7

lcd_rs: P2^6

lcd_rw: P2^5


    Set the button limit_choise: P //Temperature upper and lower limit selection button

            increase_temperature P //Increase temperature limit button

            reduce_temperature P //Reduce temperature limit button

    

    Buzzer alarm warning P   


    Temperature sensor temperature_sensor P


    Heating


    Refrigerating


    LED display normal P //Normal temperature indicator

            high_temperature P //High temperature indicator light

            low_temperature P //Low temperature indicator   

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15


The C language reference source code is as follows:


#include


void DelayUs(unsigned char tu)

{

while(–tu);

}


void DelayMs(unsigned char tm)

{

while(tm–)

{

DelayUs(248);

DelayUs(248);

}

}


void dianji() //Feed the fish

{

unsigned int i;

speed=10;

i=3000;

while(i–)

{

A_ON

DelayMs(speed);

AB_ON

DelayMs(speed);

B_ON

DelayMs(speed);

BC_ON

DelayMs(speed);

C_ON

DelayMs(speed);

CD_ON

DelayMs(speed);

D_ON

DelayMs(speed);

DA_ON

DelayMs(speed);

}

ABCD_OFF

}

void dianji_shoudong() //Manually feed the fish

{

unsigned int i;

speed=10;

i=500;

while(i–)

{

A_ON

DelayMs(speed);

AB_ON

DelayMs(speed);

B_ON

DelayMs(speed);

BC_ON

DelayMs(speed);

C_ON

DelayMs(speed);

CD_ON

DelayMs(speed);

D_ON

DelayMs(speed);

DA_ON

DelayMs(speed);

}

ABCD_OFF

}

void Timer0Init()

{

TMOD|=0X01;

TH0=0xB8; //11.0592M crystal oscillator timing 20ms

TL0=0x00;

ET0=1;

EA=1;

TR0=1;

}


void main()//main function

{

init(); //initialization function

K1=1;

XIAODU=1;

YANGQI=1;

BENG=1;

Timer0Init();

while(1)

{

temp_control(); //Control button function

unnormal_proccessing(get_temp(Ds18b20ReadTemp()),up_limit_temp,down_limit_temp);//Constant temperature control function

if((h0)&(m0)&(s5))BENG=0; if((h3)&(m0)&(s0))BENG=1;

if((h4)&(m0)&(s0))BENG=0; if((h7)&(m0)&(s0))BENG=1;

if((h8)&(m0)&(s0))BENG=0; if((h11)&(m0)&(s0))BENG=1;

if(BENG1)

{

YANGQI=0;

XIAODU=1;

}

else

{

YANGQI=1;

XIAODU=0;

}

if((h6)&(m0)&(s0))

{

dianji();

}

if(K10)

{

DelayMs(20);

if(K10)

{

dianji_shoudong();

}

}

}

}


void init()//initialization function

{

uint i,j;

// Function initialization

LcdInit(); //LCD initialization function

Ds18b20Init();


//I/O port initialization

heating=1;//No heating

refrigerating=1; // No refrigeration

normal=1; //Normal temperature indicator light does not display

unnormal=1; // Abnormal temperature indicator light does not display

warning=1; //Buzzer does not alarm


//LCD initialization display

LcdWriteCom(0x80); //First line display

j=strlen(num1);

for(i=0; i{

LcdWriteData(num1[i]);

delay_ms(1);

}

LcdWriteCom(0x80+0x40); //The second line is displayed

j=strlen(num2);

for(i=0; i{

LcdWriteData(num2[i]);

delay_ms(1);

}

LcdWriteCom(0x04); //Close writing a pointer plus 1

}


uint get_temp(uint temp) //Calculate temperature function

{

float tp;


tp=temp; //Because the data processing has a decimal point, the temperature is assigned to a floating point variable

//If the temperature is positive, then the original code of the positive number is the complement code itself

temp=tp0.0625100+0.5;

//Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer

//The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1.

//Calculate and add 0.5, or after the decimal point.

return temp;

}


void display_real_tenp(uint temp) //Real-time temperature display function

{

uchar datas[] = {0, 0, 0, 0}; //define array


datas[0] = temp % 10000 / 1000;

datas[1] = temp % 1000 / 100;

datas[2] = temp % 100 / 10;

datas[3] = temp % 10;


LcdWriteCom(0x80+0x0a); //Write address 80 indicates the initial address

LcdWriteData('0'+datas[0]); //ten digits


LcdWriteCom(0x80+0x0b); //Write address 80 indicates the initial address

LcdWriteData('0'+datas[1]); //unit


LcdWriteCom(0x80+0x0d); //Write address 80 indicates the initial address

LcdWriteData('0'+datas[2]); //Display decimal point


LcdWriteCom(0x80+0x0e); //Write address 80 indicates the initial address

LcdWriteData('0'+datas[3]); //Display decimal point


}


void temp_control()//Control temperature upper and lower limit function

{

if(limit_choise0)//Select button

{

delay_ms(5);

if(limit_choise0)

{

while(!limit_choise);

limit_choise_num++;

if(limit_choise_num>=3)

{

limit_choise_num=0;

}

}

}

if(limit_choise_num==0)//normal display

{

LcdWriteCom(0x0c); //Close the cursor

display_real_tenp(get_temp(Ds18b20ReadTemp()));//display function

}


if(limit_choise_num1) //Adjust the upper limit temperature

{

LcdWriteCom(0x80+0X40+2);

LcdWriteCom(0x0f); //Open the cursor

if(increase_temperature0) //Increase temperature

{

delay_ms(5);

if(increase_temperature0)

{

while(!increase_temperature);

up_limit_temp++;

if(up_limit_temp>=100)

{

up_limit_temp=0;

}

//Write new data

LcdWriteCom(0x80+0X40+0x03);

LcdWriteData('0'+up_limit_temp/10);

LcdWriteCom(0x80+0X40+0x04);

LcdWriteData('0'+up_limit_temp%10);

LcdWriteCom(0x80+0X40+2); //Cursor write back

}

}

if(reduce_temperature0) //Reduce temperature

{

delay_ms(5);

if(reduce_temperature==0)

{

while(!reduce_temperature);

up_limit_temp–;

if(up_limit_temp<0)

{

up_limit_temp=99;

}

//Write new data

LcdWriteCom(0x80+0X40+0x03);

LcdWriteData('0'+up_limit_temp/10);

LcdWriteCom(0x80+0X40+0x04);

LcdWriteData('0'+up_limit_temp%10);

LcdWriteCom(0x80+0X40+2); //Cursor write back

}

}

}


if(limit_choise_num2) //Adjust the lower limit temperature

{

LcdWriteCom(0x80+0X40+12);

LcdWriteCom(0x0f); //Open the cursor

if(increase_temperature0) //Increase temperature

{

delay_ms(5);

if(increase_temperature0)

{

while(!increase_temperature);

down_limit_temp++;

if(down_limit_temp>=100)

{

down_limit_temp=0;

}

//Write new data

LcdWriteCom(0x80+0X40+0x0d);

LcdWriteData('0'+down_limit_temp/10);

LcdWriteCom(0x80+0X40+0x0e);

LcdWriteData('0'+down_limit_temp%10);

LcdWriteCom(0x80+0X40+12); //Cursor write back

}

}

if(reduce_temperature0) //Reduce temperature

{

delay_ms(5);

if(reduce_temperature==0)

{

while(!reduce_temperature);

down_limit_temp–;

if(down_limit_temp<0)

{

down_limit_temp=99;

}

//Write new data

LcdWriteCom(0x80+0X40+0x0d);

LcdWriteData('0'+down_limit_temp/10);

LcdWriteCom(0x80+0X40+0x0e);

LcdWriteData('0'+down_limit_temp%10);

LcdWriteCom(0x80+0X40+12); //Cursor write back

}

}

}

}


void unnormal_proccessing(uint temp,uint up_temp,uint down_temp) //constant temperature control function

{

uchar datas[] = {0, 0, 0, 0}; //define array

uint temp1=0;


datas[0] = temp % 10000 / 1000;

datas[1] = temp % 1000 / 100;

datas[2] = temp % 100 / 10;

datas[3] = temp % 10;

temp1=datas[0]*1000+datas[1]*100+datas[2]*10+datas[3]; //The actual temperature multiplied by 100


if(temp1 < down_temp*100) // Heating function

{

heating=0; //Heating

refrigerating=1; // No refrigeration


unnormal=0; //Abnormal temperature indicator light display

normal=1; //Normal temperature indicator light does not display


//Buzzer alarm

//warning=0;

//delay_ms(10);

//warning=1;

}

else if(temp1 > up_temp*100)//cooling function

{

heating=1;//No heating

refrigerating=0; // refrigeration


unnormal=0; //Abnormal temperature indicator light display

normal=1; //Normal temperature indicator light does not display


//Buzzer alarm

// warning=0;

//delay_ms(10);

// warning=1;

}

else//normal

{

heating=1;//No heating

refrigerating=1; // No refrigeration


unnormal=1; // Abnormal temperature indicator light does not display

normal=0; //Normal temperature indicator light display


//Buzzer does not alarm

// warning=1;

}

}

void Time0() interrupt 1

{

static u8 i;

TH0=0xB8; //11.0592M crystal oscillator timing 20ms

TL0=0x00;

i++;

if(i>=50) //1 second timeout

{

i=0;


Due to limited space, only part of the code can be written

Reference address:Design and production of automatic control system for fish tank with automatic fish feeding

Previous article:Design and production of single chip microcomputer lithium battery capacity tester
Next article:Semiconductor refrigeration refrigerator made of single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号