Week 9
Hook Me Up... To The Internet!: Bluetooth, Internet, Radio
Topics Covered:
  1. How To
    • Connect to Internet, Bluetooth, Radio
  2. Explorations
    • Group Project: Boomba


The assignment:
  1. Work with a partner or group of 3. Program one or more microcontroller(s) to obtain and respond to information from the internet or radio. Your project should include at least one input and one output.



1. Group Project: Boomba
This week, I teamed up with my dear tablemates Connor and Jackson. :D

Since I want to use RFID sensing in my final project and Connor wanted to create a physical robot that would listen to directions for his final project, we decided to create a robot on wheels who moves in response to corresponding RFID tags. Thus, RFID sensing was our input, movement of the robot was our output, and we decided to use Internet as the connection.

We split it up so that I would handle the RFID sensing, Connor the robot, and Jackson the connection from one to the other via Internet. To get a better sense of our project, check out Connor's and Jackson's websites for a better look at the cool things they did, including creating the Roomba-like robot, sending the motor commands, and a prototype that used 4 buttons instead!

RFID: I used the RFID RC522 Module! To ensure that we could send signals to the Internet, I hooked it up to an ESP32.
The RFID setup and tags: Circuit RFID Tags (Note the fine soldering work)


It took me a while to properly interface with the RFID sensor since I didn't have the exact ESP32-WROOM-32 model that most tutorials used, and the ESP32-S2-SOLO I was using was missing some of the necessary pins for these tutorials. I tried 4-5 different tutorials and studied the spec sheets of the ESP32-S2-SOLO2 and the ESP32-WROOM-32 to appropriately replace one GPIO pin for another. Finally, by simply replacing using the ESP32-Mini (thanks Nathan!) instead, I was able to find all of the pins I needed and got the reader to scan tags.

After finally getting the RFID Reader to sense the presence of RFID tags and display their UIDs with the help of the excellent "MFRC522.h" Arduino library package, I modified Connor's code for connecting to the NodeJS server and POSTing commands as well as code from tutorials on esp32.io.com and Random Nerd Tutorials to create code that would POST either forward, backward, left, or right commands online depending on the unique tag that it scanned. The final code for the input to the ESP32-Mini microcontroller (with my notes about specific pin wiring):

            #include 
            #include 
            
            //#include "Constants.h"
            #include 
            #include 
            #include 
            
            //ESP32-SOLO-S2
            //SDA --> ESP32 5 GPIO5
            //SCK --> ESP32 11 GPIO18
            //MOSI --> 21 GPIO21 (altered)
            //MISO --> 19 GPIO19
            //IRQ attached to nothing
            //GND --> GND
            //RST --> 20 GPIO20 (altered)
            //VCC --> 3.3V
            
            //ESP32-Mini
            //SDA --> ESP32 5 GPIO5
            //SCK --> ESP32 11 GPIO18
            //MOSI --> 23 GPIO23
            //MISO --> 19 GPIO19
            //IRQ attached to nothing
            //GND --> GND
            //RST --> 27 GPIO27
            //VCC --> 3.3V
            
            const char* ssid = "MAKERSPACE";
            const char* password = "12345678";
            
            const String speedUrl = "https://ps70-api.vercel.app/speed";
            const String directionUrl = "https://ps70-api.vercel.app/direction";
            
            #define SS_PIN  5  //ESP32 pin GIOP5 
            #define RST_PIN 27 //ESP32 pin GIOP20
            
            MFRC522 rfid(SS_PIN, RST_PIN);
            
            void setup() {
              
              Serial.begin(9600);
              // Connect to the wifi
              WiFi.begin(ssid, password);
              while (WiFi.status() != WL_CONNECTED) {
                delay(1000);
                Serial.println("Connecting to WiFi");
              }
              Serial.println("Connected to the WiFi network");
              
              SPI.begin(); // init SPI bus
              rfid.PCD_Init(); // init MFRC522
            
              Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");
            }
            
            void loop() {
              if (rfid.PICC_IsNewCardPresent()) { // new tag is available
                if (rfid.PICC_ReadCardSerial()) { // NUID has been readed
                  
                  // print Tag Type
                  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
                  Serial.print("RFID/NFC Tag Type: ");
                  Serial.println(rfid.PICC_GetTypeName(piccType));
            
                  // print UID in Serial Monitor in the hex format
                  Serial.print("UID:");
                  String content = "";
                  byte letter;
                  for (byte i = 0; i < rfid.uid.size; i++) {
                    Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
                    Serial.print(rfid.uid.uidByte[i], HEX);
                    content.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
                    content.concat(String(rfid.uid.uidByte[i], HEX));
                  }
                  Serial.println();
                  content.toUpperCase();
            
                  // Forward Tag
                  if (content.substring(1) == "A1 7C 8D 1D") {
                    Serial.println("Forward Tag Recognized!");
                    Serial.println();
                    String direction = "forward";
                    Serial.println("direction=" + direction + "&time=" + millis());
                    if ((WiFi.status() == WL_CONNECTED)) {
                      HTTPClient http;
                      http.begin(directionUrl + "?direction=" + direction + "&time=" + millis());
                      int httpResponseCode = http.POST("");
                      String payload = http.getString();
                      Serial.println(payload);
                      Serial.println(httpResponseCode);
                      Serial.println("POSTED :D");
                      http.end();
                    }
                    else {
                      Serial.println("Wifi not detected.");
                    }
                  }
                  // Backwards Tag
                  else if (content.substring(1) == "2A 2A 75 17") {
                    Serial.println("Backward Tag Recognized!");
                    Serial.println();
                    String direction = "backward";
                    Serial.println("direction=" + direction + "&time=" + millis());
                    if ((WiFi.status() == WL_CONNECTED)) {
                      HTTPClient http;
                      http.begin(directionUrl + "?direction=" + direction + "&time=" + millis());
                      int httpResponseCode = http.POST("");
                      String payload = http.getString();
                      Serial.println(payload);
                      Serial.println(httpResponseCode);
                      Serial.println("POSTED :D");
                      http.end();
                    }
                    else {
                      Serial.println("Wifi not detected.");
                    }
                  }
            
                  // Left Tag
                  else if (content.substring(1) == "37 23 27 7B") {
                    Serial.println("Left Tag Recognized!");
                    Serial.println();
                    String direction = "left";
                    Serial.println("direction=" + direction + "&time=" + millis());
                    if ((WiFi.status() == WL_CONNECTED)) {
                      HTTPClient http;
                      http.begin(directionUrl + "?direction=" + direction + "&time=" + millis());
                      int httpResponseCode = http.POST("");
                      String payload = http.getString();
                      Serial.println(payload);
                      Serial.println(httpResponseCode);
                      Serial.println("POSTED :D");
                      http.end();
                    }
                    else {
                      Serial.println("Wifi not detected.");
                    }
                  }
            
                  // Right Tag
                  else if (content.substring(1) == "F7 08 2A 7B") {
                    Serial.println("Right Tag Recognized!");
                    Serial.println();
                    String direction = "right";
                    Serial.println("direction=" + direction + "&time=" + millis());
                    if ((WiFi.status() == WL_CONNECTED)) {
                      HTTPClient http;
                      http.begin(directionUrl + "?direction=" + direction + "&time=" + millis());
                      int httpResponseCode = http.POST("");
                      String payload = http.getString();
                      Serial.println(payload);
                      Serial.println(httpResponseCode);
                      Serial.println("POSTED :D");
                      http.end();
                    }
                    else {
                      Serial.println("Wifi not detected.");
                    }
                  }
            
                  else {
                    Serial.println("Tag not recognized.");
                  }
            
                  rfid.PICC_HaltA(); // halt PICC
                  rfid.PCD_StopCrypto1(); // stop encryption on PCD
                }
              }
            }
        
  • Download my Arduino Code


  • The Final Result! Boomba

    Demo!: