基于单片机巡迹避障智能小车系统

embedded/2024/9/24 6:27:41/

文章目录

  • 前言
  • 资料获取
  • 设计介绍
  • 设计程序
  • 具体实现截图
  • 设计获取


前言

💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗
👇🏻 精彩专栏 推荐订阅👇🏻
单片机设计精品实战案例
感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人

资料获取

文章底部名片,详细资料联系我。

设计介绍

基于单片机巡迹避障智能小车系统是一个集成了单片机控制、传感器检测、路径识别和避障策略于一体的智能系统。以下是对该系统的详细介绍:

一、系统组成

  1. 核心控制器
    单片机作为整个系统的核心控制器,负责接收传感器数据、执行控制算法,并输出控制指令。常用的单片机型号包括STC89C52、Arduino、Raspberry Pi等,这些单片机具有性能稳定、功耗低、适合实时控制等特点。

  2. 传感器
    寻迹传感器:用于检测地面上的特定路径标记,如黑线。通常使用红外线传感器或光电传感器,通过检测反射光线的变化来确定路径位置。
    避障传感器:用于检测小车前方是否存在障碍物,并测量障碍物的距离。常用的避障传感器包括超声波传感器和红外测距传感器。

设计程序

#include <reg52.h>
#define uchar	unsigned char
#define uint	unsigned int
uchar temp, signal, tt1, t0, t1, t2, t3, t4, t5, t6;sbit	jia	= P3 ^ 1;
sbit	jian	= P3 ^ 2;uchar time = 20;void delay_1ms( uint d )
{uint i;while ( d-- )for ( i = 0; i < 75; i++ );
}void delay_50us( unsigned int t )  /* 延时函数 */
{unsigned int j, k;for (; t > 0; t-- ){for ( j = 10; j > 0; j-- ){for ( k = 1; k > 0; k-- );}}
}void motor_run()     /* 电机起动 */
{P1 = 0x35;delay_1ms( 220 - time );P1 = 0x53;delay_1ms( time );
}void motor_left()    /* 左进 */
{P1 = 0x30;delay_1ms( 220 - time );P1 = 0x00;delay_1ms( time );
}void motor_right()     /* 右进 */
{P1 = 0x05;delay_1ms( 220 - time );P1 = 0x00;delay_1ms( time );
}void motor_big_right()    /* 粗右进 */
{P1 = 0x55;delay_1ms( 220 - time );P1 = 0x00;delay_1ms( time );
}void motor_big_left()
{P1 = 0x33;delay_1ms( 220 - time );P1 = 0x00;delay_1ms( time );
}void motor_stop()      /* 电机停止 */
{P1 = 0x00;
}void  key_scan()
{if ( jia == 0 ) /* 判定 */{delay_50us( 100 );/* 延时 */if ( jia == 0 ){time++;if ( time == 200 )time = 200;while ( jia == 0 );/* 自锁 */}}if ( jian == 0 ) /* 判定 */{delay_50us( 100 );/* 延时 */if ( jian == 0 ){time--;if ( time == 20 )time = 20;while ( jian == 0 );/* 自锁 */}}
}void motor_back()
{P1 = 0x53;
}void main()
{t0	= 0;t1	= 0;t2	= 0;t3	= 0;t4	= 0;t5	= 0;t6	= 0;tt1	= 0;EA	= 1;ET1	= 1;TR1	= 1;TMOD	= 0x01;TH1	= -(1000 / 256);TL1	= -(1000 % 256);while ( 1 ){key_scan();if ( P3 == 0xfe ){motor_back();}else{temp	= P2;signal	= temp & 0xff;  /* 得到红外反向信号 */switch ( signal ){case 0xff:              /* 无偏差 */motor_run();t0++;if ( t0 == 10 ){t0 = 0;motor_left();motor_right();}t1 = t2 = t3 = t4 = t5 = t6 = 0;break;case 0xfd: /* 1轮右偏 */motor_big_left();t1++;if ( t1 == 4 ){t1 = 0;motor_left();}t0 = t2 = t3 = t4 = t5 = t6 = 0;break;case 0xef: /* 4轮左偏 */motor_big_right();t2++;if ( t2 == 4 ){t2 = 0;motor_right();}t0 = t1 = t3 = t4 = t5 = t6 = 0;break;case 0xfb:      /* 2轮右偏出轨 */case 0xf9:      /* 1、2轮右偏 */motor_big_left();t3++;if ( t3 == 4 ){t3 = 0;motor_left();}t0 = t1 = t2 = t4 = t5 = t6 = 0;
/*				delay_1ms(10); */break;case 0xdf:      /* 5左偏出轨 */case 0xcf:      /* 4、5轮左偏 */motor_big_right();t4++;if ( t4 == 4 ){t4 = 0;motor_right();}t0 = t1 = t2 = t3 = t5 = t6 = 0;
/*				delay_1ms(10); */break;case 0xfe: /* 0最右偏出轨 */case 0xfa:motor_big_left();t5++;if ( t5 == 1 ){t5 = 0;motor_left();motor_left();}t0 = t1 = t2 = t3 = t4 = t6 = 0;
/*				delay_1ms(10); */break;case 0xbf: /* 6最左偏出轨 */case 0x9f:motor_big_right();t6++;if ( t6 == 1 ){t6 = 0;motor_right();motor_right();}t0 = t1 = t2 = t3 = t4 = t5 = 0;
/*				delay_1ms(10); */break;case 0xeb:      /* 前两传感器压在黑线上 */case 0xdb:      /* 后两传感器压在黑线上 */case 0xbe:      /* 中间两传感器压在黑线上 */case 0xac:      /* 前四传感器压在黑线上 */case 0x9a:      /* 后四传感器压在黑线上 */motor_back();delay_1ms( 200 );motor_stop();/*				delay_1ms(1000); */default:
/**                      motor_back();*                      delay_1ms(50);*                      motor_left();*                      motor_right();*/break;}}}
}/*void time1() interrupt 3* {** TH1=-(1000/256);* TL1=-(1000%256);* tt1++;* if(tt1==300)* {* motor_back();* //	delay_1ms(1);* tt1=0;* }* } */

具体实现截图

在这里插入图片描述
在这里插入图片描述

设计获取

文章下方名片联系我即可~

精彩专栏推荐订阅:在下方专栏👇🏻

毕业设计精品实战案例

收藏关注不迷路!!

🌟文末获取设计🌟


http://www.ppmy.cn/embedded/115952.html

相关文章

dedecms——四种webshell姿势

姿势一&#xff1a;通过文件管理器上传WebShell 步骤一&#xff1a;访问目标靶场其思路为 dedecms 后台可以直接上传任意文件&#xff0c;可以通过文件管理器上传php文件获取webshell 步骤二&#xff1a;登陆到后台点击【核心】--》 【文件式管理器】--》 【文件上传】将准备好…

签署《AI安全国际对话威尼斯共识》 智源持续推动人工智能安全发展

近日&#xff0c;由AI安全国际论坛&#xff08;Safe AI Forum&#xff09;和博古睿研究院&#xff08;Berggruen Institute) 共同举办的第三届国际AI安全对话&#xff08;International Dialogues on AI Safety&#xff09;在威尼斯举办。图灵奖得主Yoshua Bengio、姚期智教授&…

html,js,react三种方法编写helloworld理解virtual dom

学习任何一个新语言&#xff0c;好像都从helloworld开始。&#xff1a;&#xff09;。 html helloworld 静态hello world <!DOCTYPE html> <html> <head><title>Hello World</title> </head> <body><p>Hello World</p&g…

操作系统知识2

1.分页与分段有什么区别&#xff1f; 分页&#xff1a; 内存管理的一种方法&#xff0c;将虚拟地址空间划分为固定大小的页&#xff08;通常是4KB&#xff09;。页表用于映射虚拟页到物理页&#xff0c;简化了内存分配和管理。适合处理大规模程序的内存分配&#xff0c;可以有效…

Apple Intelligence预计会在iOS 18.1和iOS 18.4之间按此顺序推出

本月早些时候 iOS 18 已公开发布&#xff0c;但首批 Apple Intelligence 功能要等到 10 月份 iOS 18.1 发布后才可以使用。Apple Intelligence 功能将继续在 iOS 18.2 及更高版本中推出&#xff0c;预计路线图如下&#xff0c;出自 Apple 网站和传闻。 Apple Intelligence 需要…

Rasa对话模型——做一个语言助手

1、Rasa模型 1.1 模型介绍 Rasa是一个用于构建对话 AI 的开源框架&#xff0c;主要用于开发聊天机器人和语音助手。Rasa 提供了自然语言理解&#xff08;NLU&#xff09;和对话管理&#xff08;DM&#xff09;功能&#xff0c;使开发者能够创建智能、交互式的对话系统。 1.2…

TryHackMe 第4天 | Pre Security (三)

该学习路径讲解了网络安全入门的必备技术知识&#xff0c;比如计算机网络、网络协议、Linux命令、Windows设置等内容。过去两篇已经对计算机网络和网络协议进行了简单介绍&#xff0c;本篇博客将记录 Linux命令 部分。 Linux 系统的优点就是其轻量级&#xff0c;有些 Linux 系…

动态SQL中的foreach标签【后端 21】

动态SQL中的foreach标签 在Java开发中&#xff0c;特别是在使用MyBatis进行数据库操作时&#xff0c;动态SQL是一项非常强大的功能。MyBatis的<foreach>标签就是动态SQL中最为常用的一个&#xff0c;主要用于处理包含IN子句的查询或者批量插入等操作。本文将详细介绍<…