Section outline

  • Controlling a Robot via Mobile App (MIT App Inventor)

    Now that your Bluetooth module is connected, it's time to build a simple mobile app that sends commands to your robot. We will use MIT App Inventor, a beginner-friendly, drag-and-drop platform for making Android apps.

    • 📱 What is MIT App Inventor?

      • A free online tool that lets you build apps by dragging and connecting blocks.
      • Great for beginners and works directly from your browser.
      • Apps can be tested live using the MIT AI2 Companion app.
    • 🌐 Getting Started

      1. Go to MIT App Inventor
      2. Sign in with your Google account.
      3. Create a new project and name it something like BluetoothBot.

      📲 Designing the App Interface

      • Add Buttons for robot controls: Forward, Backward, Left, Right, Stop
      • Add a ListPicker to choose the Bluetooth device
      • Use a Label to show connection status

      🔧 App Blocks Logic

      Each button will send a letter or number via Bluetooth to the robot. For example:

      • Forward → Send "F"
      • Backward → Send "B"
      • Left → Send "L"
      • Right → Send "R"
      • Stop → Send "S"

      Use the BluetoothClient block to send these characters when the button is clicked.

    • 🤖 Arduino Code to Receive Commands

      char command;
      
      void setup() {
        Serial.begin(9600);
        pinMode(5, OUTPUT); // Left Motor
        pinMode(6, OUTPUT); // Right Motor
      }
      
      void loop() {
        if (Serial.available()) {
          command = Serial.read();
          if (command == 'F') {
            // Move forward
            digitalWrite(5, HIGH);
            digitalWrite(6, HIGH);
          }
          else if (command == 'S') {
            // Stop
            digitalWrite(5, LOW);
            digitalWrite(6, LOW);
          }
          // Add more conditions for B, L, R
        }
      }
      

      🛠️ Testing and Troubleshooting

      • Make sure your phone is paired with the HC-05 or HC-06.
      • Install the MIT AI2 Companion app to test your interface.
      • Ensure the baud rate in Serial.begin() matches the module (usually 9600).

      ✅ What You’ve Learned

      • How to build a simple Bluetooth control app using MIT App Inventor
      • How to send commands from phone to Arduino
      • How to receive and use Bluetooth commands in Arduino code