MIT App Inventor 开发安卓 App 控制 Arduino 蓝牙通信
Arduino 端通用协议
串口 38400 波特率。收到 '0' → 关灯回 "LED: OFF";收到 '1' → 开灯回 "LED: ON"。步进电机例程接收文本指令:"Auto"/"Manual" 切模式,"Reverse" 反向,数值字符串设速度/角度。
MIT App Inventor 界面构建
- 登录 ai2.appinventor.mit.edu,新建项目
- 通过 MIT AI2 Companion 扫码实时预览,或用模拟器
- 布局组件:
- ListPicker(蓝牙设备列表,重命名为 BluetoothList)
- Label 显示连接状态与 LED 状态
- Button Turn ON / Turn OFF
- BluetoothClient(不可见组件)
- Clock 定时轮询连接状态
Blocks 编程逻辑
蓝牙连接
BluetoothList.BeforePicking→ 设置 Elements 为BluetoothClient.AddressesAndNamesBluetoothList.AfterPicking→call BluetoothClient.Connect address (BluetoothList.Selection)Clock.Timer(100ms) → 若BluetoothClient.IsConnected则 Label 显示 "Connected" 否则 "Not Connected"
按钮控制
- TurnOn.Click →
BluetoothClient.Send1ByteNumber(49)(ASCII '1') →BluetoothClient.ReceiveText赋值给 LED_Status Label - TurnOff.Click → 发送 48 ('0') → 同理更新状态
进阶:步进电机仪表盘控制
界面增加:
- Canvas + 两个 ImageSprite(固定刻度盘 + 旋转指针)
- CheckBox 切换 Auto/Manual
- Button Reverse 反向
- Slider 调速
核心逻辑:
- Canvas.Touched → ImageSprite.PointInDirection(x,y) 旋转指针 → 读取 Heading → 发送文本给 Arduino
- CheckBox.Changed → 发送 "Auto" 或 "Manual"
- Reverse.Click → 发送 "Reverse"
- Slider.PositionChanged → 发送数值文本
资源下载
BluetoothTest.aia(5.16 KB) - LED 控制项目源文件StepperMotorTest.aia(60.96 KB) - 步进电机项目源文件- 仪表盘指针/刻度盘图片素材
无需编写 Java/Kotlin 代码,可视化拖拽快速生成 APK,适合原型验证与教学演示。
制造工艺
- 无人机弹道降落伞回收系统设计指南
- 用 Arduino 打造绚丽显示器 Ambilight 系统
- 基于 Arduino、1Sheeld 与红外控制的万能安卓遥控器
- Arduino 与智能手机打造智能电压表——简单易做的 DIY 项目
- Android 手势遥控车:Raspberry Pi + Arduino 101 + 电机扩展板,I2T 协同控制
- 精准钢材报价:项目成本估算分步指南
- 喷砂为何能提升定制金属制造项目品质?
- 如何为定制加工项目准备极具竞争力的报价
- 构建成功自动化路线图的七步法
- 选择合适的合金:定制铸造项目中镁与铝的对比
- 工程起重机选型实战指南:载荷、高度、地基三维决策
- 项目选材实战指南:铜、磷青铜、黄铜、铝、钢五大核心材料解析