加入星計劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴散
  • 作品版權(quán)保護
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長期合作伙伴
立即加入

STM32物聯(lián)網(wǎng)智能魚缸智能家居系統(tǒng)(程序+原理圖+PCB+圖文教程)

07/05 09:08
5142
服務(wù)支持:
技術(shù)交流群

完成交易后在“購買成功”頁面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗、收獲成長和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購買后不支持退換且無法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論
放大
實物圖
相關(guān)方案
  • 方案介紹
  • 相關(guān)文件
  • 推薦器件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請入駐 產(chǎn)業(yè)圖譜

本設(shè)計:
基于STM32物聯(lián)網(wǎng)智能魚缸智能家居系統(tǒng)設(shè)計方案(程序+原理圖+PCB
原理圖:Altium Designer
程序編譯器:keil 5
編程語言:C語言
編號C0027

功能說明:
1、本設(shè)計采用的stm32f103c8t6單片機設(shè)計;
2、使用的esp8266 01s wifi模塊實現(xiàn)物聯(lián)網(wǎng)手機通信
3、實現(xiàn)溫度測量顯示及自動控制;
4、實現(xiàn)濁度測量超過閥值開始報警,提醒主人更換水了;
5、實現(xiàn)自動定時補氧及自動定時喂食控制;
6、實現(xiàn)手機遠(yuǎn)程控制,有效查看魚缸內(nèi)的情況;
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);//正轉(zhuǎn)
					currentDataPoint.valueAddFoodKey = 1;
				}
				if(AddFoodFlag == 1 && AddFoodTime > 2)
				{
					AddFoodTime = 0;
					motorNcircle(32,1);//反轉(zhuǎn)
				  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);  //初始化延遲函數(shù)   // 延時 初始化
    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

  • 設(shè)計資料獲取聯(lián)系方式.doc

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風(fēng)險等級 參考價格 更多信息
MK70FN1M0VMJ15 1 Freescale Semiconductor Kinetis K 32-bit MCU, ARM Cortex-M4 core, 1MB Flash, 150MHz, Graphics LCD, MAPBGA 256

ECAD模型

下載ECAD模型
$18.16 查看
STM32H757XIH6TR 1 STMicroelectronics RISC Microcontroller
暫無數(shù)據(jù) 查看
STM32H743XIH6 1 STMicroelectronics High-performance and DSP with DP-FPU, Arm Cortex-M7 MCU with 2MBytes of Flash memory, 1MB RAM, 480 MHz CPU, Art Accelerator, L1 cache, external memory interface, large set of peripherals

ECAD模型

下載ECAD模型
$31.15 查看

相關(guān)推薦

電子產(chǎn)業(yè)圖譜