加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入

STM32物联网智能鱼缸智能家居系统(程序+原理图+PCB+图文教程)

07/05 09:08
5077
服务支持:
技术交流群

完成交易后在“购买成功”页面扫码入群,即可与技术大咖们分享疑惑和经验、收获成长和认同、领取优惠和红包等。

虚拟商品不可退

当前内容为数字版权作品,购买后不支持退换且无法转移使用。

加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论
放大
实物图
相关方案
  • 方案介绍
  • 相关文件
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

本设计:
基于STM32物联网智能鱼缸智能家居系统设计方案(程序+原理图+PCB
原理图:Altium Designer
程序编译器:keil 5
编程语言:C语言
编号C0027

功能说明:
1、本设计采用的stm32f103c8t6单片机设计;
2、使用的esp8266 01s wifi模块实现物联网手机通信
3、实现温度测量显示及自动控制;
4、实现浊度测量超过阀值开始报警,提醒主人更换水了;
5、实现自动定时补氧及自动定时喂食控制;
6、实现手机远程控制,有效查看鱼缸内的情况;
7、可手机修改自动喂食、供氧时间备注。

在这里插入图片描述

原理图(提供源文件):
在这里插入图片描述

PCB(提供源文件):
在这里插入图片描述

源程序(提供源文件):

/* 
资料链接:https://pan.baidu.com/s/1V-vFj52GXyqDvvzT7OJ77g?pwd=m293 
*/
#include "main.h"
#include "stm32f1xx_hal.h"
#include "Hal_led.h"
#include "adc.h"
#include "delay.h"
/* USER CODE BEGIN Includes */
#include "hal_key.h"
#include "gizwits_product.h"
#include "common.h"
/* USER CODE END Includes */
#include "bsp_DS18B20.h"
#define intensity_Low  20
#define intensity_High  85
#define Temperature_High  32
#define Humidity_High 85
#include "Hal_Motor.h"

/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;

UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
#define GPIO_KEY_NUM 2 ///< Defines the total number of key member
keyTypedef_t singleKey[GPIO_KEY_NUM]; ///< Defines a single key member array pointer
keysTypedef_t keys;
/* USER CODE END PV */
extern uint8_t Window_Open_Flag,Auto_Flag;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_NVIC_Init(void);
static void MX_TIM3_Init(void);
extern void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
/**
* key1 short press handle
* @param none
* @return none
*/
void key1ShortPress(void)
{
    GIZWITS_LOG("KEY1 PRESS ,Production Moden");
    gizwitsSetMode(WIFI_PRODUCTION_TEST);
}

/**
* key1 long press handle
* @param none
* @return none
*/
void key1LongPress(void)
{
    GIZWITS_LOG("KEY1 PRESS LONG ,Wifi Resetn");
    gizwitsSetMode(WIFI_RESET_MODE);

}

/**
* key2 short press handle
* @param none
* @return none
*/
void key2ShortPress(void)
{
    GIZWITS_LOG("KEY2 PRESS ,Soft AP moden");
#if !MODULE_TYPE
    gizwitsSetMode(WIFI_SOFTAP_MODE);
#endif
}

/**
* key2 long press handle
* @param none
* @return none
*/
void key2LongPress(void)
{
    //AirLink mode
    GIZWITS_LOG("KEY2 PRESS LONG ,AirLink moden");
#if !MODULE_TYPE
    gizwitsSetMode(WIFI_AIRLINK_MODE);
#endif
}

/**
* Key init function
* @param none
* @return none
*/
void keyInit(void)
{
    singleKey[0] = keyInitOne(NULL, KEY1_GPIO_Port, KEY1_Pin, key1ShortPress, key1LongPress);
    singleKey[1] = keyInitOne(NULL, KEY2_GPIO_Port, KEY2_Pin, key2ShortPress, key2LongPress);
    keys.singleKey = (keyTypedef_t *)&singleKey;
    keyParaInit(&keys);
}
/* USER CODE END 0 */
uint8_t AddFoodFlag = 0,AddOxFlag = 0;
uint16_t AddFoodTime = 0,AddOxTime = 0;
void userHandle(void)
{
	static uint32_t thLastTimer = 0;
 
	if((gizGetTimerCount() - thLastTimer) > 1000)      //上报间隔读取温度2S
	{
	    currentDataPoint.valueTemp = DS18B20_GetTemp_SkipRom();//Add Sensor Data Collection
      currentDataPoint.valueTurbidity =  3291.3 - (float)Get_Adc_Average(ADC_CHANNEL_0,10)*3.3/4096*2*865.68;
      if( currentDataPoint.valueTemp  < currentDataPoint.valueHeatLimit)		//开启加热
			{
			  TEMPON;
			}
			else
			{
			  TEMPOFF;
			}
			if( currentDataPoint.valueAddFoodTime > 0)
			{
				AddFoodTime ++;
				if(AddFoodTime >  currentDataPoint.valueAddFoodTime && AddFoodFlag == 0)
				{	AddFoodTime = 0;				
					AddFoodFlag = 1;
					motorNcircle(32,0);//正转
					currentDataPoint.valueAddFoodKey = 1;
				}
				if(AddFoodFlag == 1 && AddFoodTime > 2)
				{
					AddFoodTime = 0;
					motorNcircle(32,1);//反转
				  AddFoodFlag = 0;
					currentDataPoint.valueAddFoodKey = 0;
				}
			}
			if( currentDataPoint.valueAddOxTime > 0)
			{
				AddOxTime ++;
				if(AddOxTime >  currentDataPoint.valueAddOxTime && AddOxFlag == 0)
				{
					AddOxTime = 0;				
					AddOxFlag = 1;				
					OxON;
					currentDataPoint.valueAddOxKey = 1;
				}
				if(AddOxFlag == 1 && AddOxTime > 2)
				{
					AddOxTime = 0;
				  AddOxFlag = 0;
					OxOFF;
				  currentDataPoint.valueAddOxKey = 0;
				}
			}
			
		  if(currentDataPoint.valueTurbidity < 1200)
			{			
				BeepOFF;	
			}
		  else 
			{
				BeepON;	
			}
     
			thLastTimer = gizGetTimerCount();
	}
}

int main(void)
{
    /* USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* USER CODE BEGIN Init */

    /* USER CODE END Init */

    /* Configure the system clock */
    SystemClock_Config();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_TIM2_Init();
		MX_TIM3_Init();
    MX_USART1_UART_Init();
    MX_USART2_UART_Init();

    /* Initialize interrupts */
    MX_NVIC_Init();

    /* USER CODE BEGIN 2 */
    timerInit();
    uartInit();
	  delay_init(72);  //初始化延迟函数   // 延时 初始化
    userInit();

    keyInit();
    LED_GPIO_Init();
    MY_ADC_Init(); 
		//Moter_GPIO_Init();
		gizwitsInit();
    while(DS18B20_Init());
		Moter_GPIO_Init();
    GIZWITS_LOG("MCU Init Success n");
    /* USER CODE END 2 */
    TEMPOFF;OxOFF;
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
		delay_ms(520);
	
    while (1)
    {
		
			userHandle();	 
      gizwitsHandle((dataPoint_t *)&currentDataPoint);
			  

    }
    /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

    RCC_OscInitTypeDef RCC_OscInitStruct;
    RCC_ClkInitTypeDef RCC_ClkInitStruct;

    /**Initializes the CPU, AHB and APB busses clocks
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    /**Initializes the CPU, AHB and APB busses clocks
    */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    /**Configure the Systick interrupt time
    */
    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick
    */
    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    /* SysTick_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/** NVIC Configuration
*/
static void MX_NVIC_Init(void)
{
    /* TIM2_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(TIM2_IRQn, 1, 0);
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
    /* USART2_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART2_IRQn);
}

/* TIM2 init function */
static void MX_TIM2_Init(void)
{

    TIM_ClockConfigTypeDef sClockSourceConfig;
    TIM_MasterConfigTypeDef sMasterConfig;

    htim2.Instance = TIM2;
    htim2.Init.Prescaler = 7200-1;
    htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim2.Init.Period = 10-1;
    htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }
		
}
/* TIM3 init function */
static void MX_TIM3_Init(void)
{

    TIM_MasterConfigTypeDef sMasterConfig;
    TIM_OC_InitTypeDef sConfigOC;

    htim3.Instance = TIM3;
    htim3.Init.Prescaler = 9;
    htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim3.Init.Period = 7199;
    htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 0;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    sConfigOC.Pulse = 500;
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

    HAL_TIM_MspPostInit(&htim3);

}
/* USART1 init function */
static void MX_USART1_UART_Init(void)
{

    huart1.Instance = USART1;
    huart1.Init.BaudRate = 115200;
    huart1.Init.WordLength = UART_WORDLENGTH_8B;
    huart1.Init.StopBits = UART_STOPBITS_1;
    huart1.Init.Parity = UART_PARITY_NONE;
    huart1.Init.Mode = UART_MODE_TX_RX;
    huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart1.Init.OverSampling = UART_OVERSAMPLING_16;
    if (HAL_UART_Init(&huart1) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

}

/* USART2 init function */
static void MX_USART2_UART_Init(void)
{

    huart2.Instance = USART2;
    huart2.Init.BaudRate = 9600;
    huart2.Init.WordLength = UART_WORDLENGTH_8B;
    huart2.Init.StopBits = UART_STOPBITS_1;
    huart2.Init.Parity = UART_PARITY_NONE;
    huart2.Init.Mode = UART_MODE_TX_RX;
    huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart2.Init.OverSampling = UART_OVERSAMPLING_16;
    if (HAL_UART_Init(&huart2) != HAL_OK)
    {
        _Error_Handler(__FILE__, __LINE__);
    }

}


下载方式链接
链接:https://pan.baidu.com/s/1A9mXs9wqkm1o05_QyjrVTQ?pwd=xibu

  • 设计资料获取联系方式.doc

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
MK70FN1M0VMJ15 1 Freescale Semiconductor Kinetis K 32-bit MCU, ARM Cortex-M4 core, 1MB Flash, 150MHz, Graphics LCD, MAPBGA 256

ECAD模型

下载ECAD模型
$18.16 查看
STM32F405RGT6W 1 STMicroelectronics High-performance foundation line, Arm Cortex-M4 core with DSP and FPU, 1 Mbyte of Flash memory, 168 MHz CPU, ART Accelerator

ECAD模型

下载ECAD模型
$14.1 查看
ATXMEGA128A4U-MH 1 Microchip Technology Inc IC MCU 8BIT 128KB FLASH 44VQFN

ECAD模型

下载ECAD模型
$5.12 查看

相关推荐

电子产业图谱