stm32毕业设计 远程家庭智能监控系统


1 简介

Hi,大家好,今天向大家介绍一个学长做的单片机项目

基于单片机的家庭智能监控系统

大家可用于 课程设计 或 毕业设计

2 主要器件

  • 红外传感器-7m
  • ESP32-CAM
  • USB到TTL串行转换器5V
  • 主控MCU(可选)

2.1 ESP32-CAM 模块

在这里插入图片描述
模块包含一块ESP32-CAM的MCU和一个OV2640的200W像素摄像头,ESP32-CAM除了支持OV2640外还支持OV7670摄像头,不过7670只有30W像素

在这里插入图片描述

在这里插入图片描述

2.2 红外热释电传感器

在这里插入图片描述

3 实现效果

在这里插入图片描述

当是房间内有人出现,摄像头自动打开,通过手机或者电脑浏览就可以访问摄像头

在这里插入图片描述

4 部分实现代码

部分关键代码:

/*
albino98
https://github.com/albino98/telegram_esp32.git
*/
#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>   // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
#include "esp_camera.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
// Replace with your network credentials
const char* ssid = "NetworkName";
const char* password = "NetworkPW";
const int motionSensor = 13;

int armed = 1;

#define BOTtoken "xxxxxxx:xxxxxxxxxxxxxxxxxx"  // your Bot Token (Get from Botfather)

// Use @myidbot to find out the chat ID of an individual or a group
#define CHAT_ID "xxxxxxx"

//Pin definition for CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM  32
#define RESET_GPIO_NUM  -1
#define XCLK_GPIO_NUM  0
#define SIOD_GPIO_NUM  26
#define SIOC_GPIO_NUM  27
#define Y9_GPIO_NUM  35
#define Y8_GPIO_NUM  34
#define Y7_GPIO_NUM  39
#define Y6_GPIO_NUM  36
#define Y5_GPIO_NUM  21
#define Y4_GPIO_NUM  19
#define Y3_GPIO_NUM  18
#define Y2_GPIO_NUM  5
#define VSYNC_GPIO_NUM  25
#define HREF_GPIO_NUM  23
#define PCLK_GPIO_NUM  22

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

// Checks for new messages every 1 second.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;

const int ledPin = 4;
bool ledState = LOW;
camera_fb_t * fb;
uint8_t* fb_buffer;
size_t fb_length;
int currentByte;
boolean startTimer = false;
// Handle what happens when you receive new messages
void handleNewMessages(int numNewMessages) {
  Serial.println("handleNewMessages");
  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    // Chat id of the requester
    String chat_id = String(bot.messages[i].chat_id);
    if (chat_id != CHAT_ID){
      bot.sendMessage(chat_id, "Unauthorized user", "");
      continue;
    }
    
    // Print the received message
    String text = bot.messages[i].text;
    Serial.println(text);

    String from_name = bot.messages[i].from_name;

    if (text == "/start") {
      String welcome = "Welcome, " + from_name + ".\n";
      welcome += "Use the following commands to control your outputs.\n\n";
      welcome += "/take_photo to take a picture \n";
      welcome += "/arm to arm the security system \n";
      welcome += "/disarm to disarm the security system \n";
      welcome += "/led_on to turn GPIO ON \n";
      welcome += "/led_off to turn GPIO OFF \n";
      welcome += "/state to request current GPIO state and security system state \n";
      bot.sendMessage(chat_id, welcome, "");
    }

    if (text == "/led_on") {
      bot.sendMessage(chat_id, "LED state set to ON", "");
      ledState = HIGH;
      digitalWrite(ledPin, ledState);
    }
    
    if (text == "/led_off") {
      bot.sendMessage(chat_id, "LED state set to OFF", "");
      ledState = LOW;
      digitalWrite(ledPin, ledState);
    }

    if (text == "/take_photo") {
      take_send_photo(CHAT_ID);
    }

    if (text == "/security_on") {
      armed = 1;
      bot.sendMessage(chat_id, "Security System is ON", "");
    }

    if (text == "/security_off") {
      armed = 0;
      bot.sendMessage(chat_id, "Security System is OFF", "");
    }
    
    if (text == "/state") {
      if (digitalRead(ledPin)){
        bot.sendMessage(chat_id, "LED is ON", "");
      }
      else{
        bot.sendMessage(chat_id, "LED is OFF", "");
      }
      if(armed == 1){
        bot.sendMessage(chat_id, "The security system is ON", "");
      }
      else {
        bot.sendMessage(chat_id, "The security system is OFF", "");  
      }
    }
  }
}


bool isMoreDataAvailable() {
  return (fb_length - currentByte);
}

uint8_t photoNextByte() {
  currentByte++;
  return (fb_buffer[currentByte - 1]);
}

void take_send_photo(String chat_id)
{
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();
  currentByte = 0;
  fb_length = fb->len;
  fb_buffer = fb->buf;
  bot.sendPhotoByBinary(chat_id, "image/jpeg", fb->len, isMoreDataAvailable, photoNextByte, nullptr, nullptr);
  esp_camera_fb_return(fb);
  fb_length = NULL;
  fb_buffer = NULL;
}

void setup() {
  armed = 1;
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG,0);//disable brownout detector
  Serial.begin(115200);

  camera_config_t configg;
  configg.ledc_channel = LEDC_CHANNEL_0;
  configg.ledc_timer = LEDC_TIMER_0;
  configg.pin_d0 = Y2_GPIO_NUM;
  configg.pin_d1 = Y3_GPIO_NUM;
  configg.pin_d2 = Y4_GPIO_NUM;
  configg.pin_d3 = Y5_GPIO_NUM;
  configg.pin_d4 = Y6_GPIO_NUM;
  configg.pin_d5 = Y7_GPIO_NUM;
  configg.pin_d6 = Y8_GPIO_NUM;
  configg.pin_d7 = Y9_GPIO_NUM;
  configg.pin_xclk = XCLK_GPIO_NUM;
  configg.pin_pclk = PCLK_GPIO_NUM;
  configg.pin_vsync = VSYNC_GPIO_NUM;
  configg.pin_href = HREF_GPIO_NUM;
  configg.pin_sscb_sda = SIOD_GPIO_NUM;
  configg.pin_sscb_scl = SIOC_GPIO_NUM;
  configg.pin_pwdn = PWDN_GPIO_NUM;
  configg.pin_reset = RESET_GPIO_NUM;
  configg.xclk_freq_hz = 20000000;
  configg.pixel_format = PIXFORMAT_JPEG;

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, ledState);
  rtc_gpio_hold_dis(GPIO_NUM_4);

  pinMode(GPIO_NUM_13, INPUT_PULLUP);

  if(psramFound()){
    configg.frame_size = FRAMESIZE_UXGA;
    configg.jpeg_quality = 10;
    configg.fb_count = 2;
  }else{
    configg.frame_size = FRAMESIZE_SVGA;
    configg.jpeg_quality = 12;
    configg.fb_count = 1;
  }

  //Init Camera
  esp_err_t err = esp_camera_init(&configg);
  if(err != ESP_OK){
    Serial.printf("Camera init failed with error");  
    return;
  }
  
  // Connect to Wi-Fi
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
  // Print ESP32 Local IP Address
  Serial.println(WiFi.localIP());



}

void loop() {
  if(armed == 1){
    int isDetected = digitalRead(13);
    if(isDetected == 1){
      Serial.println("Presence detected");
      take_send_photo(CHAT_ID);
      delay(3000);
    }
  }
 //delay(1000);
 
  //if (millis() > lastTimeBotRan + botRequestDelay)  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    while(numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    delay(1000);
    lastTimeBotRan = millis();
 // }
}

5 最后

  • 3
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 远程视频监控STM32F4 Qt是一种集成了STM32F4和Qt技术的系统解决方案,旨在实现远程视频监控功能。STM32F4是一款高性能的微控制器,具有丰富的外设和强大的处理能力,而Qt则是一款跨平台的GUI开发框架,其具有丰富的图形界面、网络通信、线程处理等功能。 远程视频监控系统的实现需要通过网络传输视频信号,而STM32F4具有丰富的网络通信接口,可以通过Ethernet或WiFi等网络通信方式发送视频数据。同时,STM32F4内部集成了硬件压缩编码模块,可将视频数据压缩后发送,从而大大降低网络带宽的使用。 Qt提供了丰富的图形界面设计和控件功能,可让使用者方便地进行视窗设计和操作面板开发。同时,Qt的网络通信模块也可以与STM32F4网络接口配合,实现对视频数据的接收和解码显示等功能。 通过以上说明,可知远程视频监控STM32F4 Qt系统可以较好地满足远程视频监控系统的需求,同时系统集成方便,使用灵活。 ### 回答2: 远程视频监控是一种高效、便捷的监控方式,它可以对远程位置的情况进行实时监控。在视频监控中,STM32F4和Qt技术不可或缺。 首先,STM32F4是一种高性能的微控制器,它集成了多种外设与接口,可以广泛应用于各种智能设备。在远程视频监控系统中,STM32F4可以作为底层控制器,通过网络实现对监控设备的控制与数据采集。该微控制器可以通过串口或网络接口连接多种外设,如CMOS摄像头、传感器等,实现对远程环境的实时监控与数据采集。 其次,Qt是一款跨平台的图形用户界面开发框架,可以轻松实现各种应用程序的开发。Qt技术可以应用于远程视频监控系统的前端界面开发,包括监控画面的显示、数据图表化处理与显示等。此外,Qt还可以实现监控视频的压缩与传输,大大减少了带宽的占用和传输延迟,提高了视频监控的实时性和可靠性。 综上所述,远程视频监控中的STM32F4和Qt技术发挥了重要的作用,为远程视频监控系统智能化、高效化提供了有力支持,推进了视频监控技术的不断发展。 ### 回答3: 近年来,随着城市化进程的推进,越来越多的城市建设开始加强社区化建设和智能化设备的应用。其中远程视频监控系统智能化社区建设的关键点之一,该系统可以确保社区居民的安全性和生活质量。 STM32F4是一款嵌入式微控制器,具有高度集成、强大的计算能力、低功耗以及广泛的外围设备支持,适用于各种应用场景。在远程视频监控中,STM32F4可以提供完整的系统控制能力,确保信号处理、存储、传输的稳定性和高效性。 QT是一款可扩展的现代C++开发框架,被广泛使用于开发高性能、可移植、可定制和跨平台的应用程序,具有跨平台性和开放源代码等特点。在远程视频监控中,QT可以轻松地构建友好的用户界面,并实现系统和设备的远程控制和监控。 综上所述,远程视频监控STM32F4 QT是一款高效的智能化社区建设系统,它可以为社区居民提供更为全面的安全保障和更舒适的生活环境。同时,它也具有广泛的应用前景,有望在未来得到更多的发展和应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值