Group Assignment

Send a message between two projects

Please for group assignment details visit Anderson Zelarayan Web Page.

Individual Assignment

Selecting Testing

With my instructor support, we review the components that I'm gonna need for my final project in order to decide which could require a wifi or bluethooth communication. So I decide to start with a Servo motor that I'll intent to use for opening the hidden shelve. The following picture show the potential devices that I would use for my final project. I would use 2 Servo Motors, so I decide to execute a bluethooth connection, using an app to activate the servomotor.

Servomotor Board Components

I used the board design and fabricated at week 9 ,the following are its components:

  1. One terminal block 2x1
  2. Regulator LDO 5V 1A
  3. Male connector header 2x3
  4. Male connector header 90° 1x3 (GND+2DIO)
  5. 2 Servo Motors
  6. Capacitor 1uf

This is the pcb design where you can see all the components. You can download design file and the SVG files here.

Xiao ESP32C3 Board Components

I used the board design and fabricated at week 8 , because its design includes a push bottom and a LED, and have DIO pins to connect the servo motor controller, and replaced the XIAO RP"=$= by XIAO ESP32C3. The following are its components:

  1. 01 Seeed Studio Xiao ESP32C3.
  2. 01 1kΩ resistor
  3. 01 499 Ω resistor
  4. 01 LED 1206
  5. 01 SW - Button >
  6. 01 Female horizontal row header
  7. 01 100 μf capacitor

This is the pcb fabricated where you can see all the components. You can download design file and the SVG files here.

Xiao ESP32C3 Requeriments for Arduino IDE

First prepare the Arduino IDE software to work with the board, following the steps suggested by Seeedstudio here . The steps that we need to apply, so you can be eable to upload any program using Arduino IDE are:

    Add ESP32 board package to your Arduino IDE by
  1. Navigating into File > Preferences, and fill "Additional Boards Manager URLs" with this url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  2. Navigating into Tools > Board > Boards Manager..., type the keyword "esp32" in the search box, select the latest version of esp32, and install it.

Testing Xiao ESP32C3 Board Components

First I decide to test the microcontroller following the steps suggested by Seeedstudio here.

  1. Scaning available WiFi networks around (Station Mode): This photo shows the code and at the right the scaning results
  2. Connect to a WiFi network: The image shows the programing to connect to a private wifi network and the final connection at the right
  3. Scan available Bluetooth devices around: The photo shows
  4. XIAO ESP32C3 as Bluetooth server: using a smartphone and send out strings to display on the serial monitor. The following photo shows the bluethooth connection on my cellphone.

    Thus, we need to install an app to exert control over the microcontroller. Like suggested by Seedstudio, I donwload LightBlue, because works with iphone

    This image shows how the message send using my celphone appears on Arduino IDE's serial monitor

LED Control by Bluetooth

I wanted to undertake a first simple control and generate a LED blink using a ESP32C3. Thus I'm going to explain the process behind it

  1. Connect a LED to the ESP32C3 using a board where a microcontroller's pin will be directly connect with the LED
  2. Decide how the the information is going to be transfered from the Cellphone to the microcontroller and then to the LED
  3. Generate the coding that allows LED control using the microcontroller and an app
  4. 			
    #include 
    #include 
    #include 
    #include 
    					
    #define LED_PIN D0 // Cambia el pin según la conexión de tu LED
    #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
    #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
    					
    BLEServer* pServer = NULL;
    BLECharacteristic* pCharacteristic = NULL;
    bool deviceConnected = false;
    					
    class MyServerCallbacks : public BLEServerCallbacks {
    	void onConnect(BLEServer* pServer) {
    	  deviceConnected = true;
    	};
    					
    	void onDisconnect(BLEServer* pServer) {
    	  deviceConnected = false;
    	}
    };
    					
    class MyCallbacks : public BLECharacteristicCallbacks {
    	void onWrite(BLECharacteristic *pCharacteristic) {
    	  std::string value = pCharacteristic->getValue();
    					
    	  if (value.length() > 0) {
    		if (value[0] == '1') {
    		  digitalWrite(LED_PIN, HIGH); // Encender el LED
    		} else if (value[0] == '0') {
    		  digitalWrite(LED_PIN, LOW); // Apagar el LED
    		}
    	  }
    	}
    };
    					
    void setup() {
      Serial.begin(115200);
      pinMode(LED_PIN, OUTPUT);
    					
      BLEDevice::init("LEDControl");
      pServer = BLEDevice::createServer();
      pServer->setCallbacks(new MyServerCallbacks());
    					
      BLEService *pService = pServer->createService(BLEUUID(SERVICE_UUID));
      pCharacteristic = pService->createCharacteristic(
    					  BLEUUID(CHARACTERISTIC_UUID),
    					  BLECharacteristic::PROPERTY_WRITE
    					);
    					
      pCharacteristic->setCallbacks(new MyCallbacks());
    					
      pService->start();
      BLEAdvertising *pAdvertising = pServer->getAdvertising();
      pAdvertising->start();
      Serial.println("Esperando la conexión Bluetooth...");
    }
    					
    void loop() {
      if (deviceConnected) {
    	// Puedes realizar otras tareas mientras está conectado
      }
      delay(1000); // Espera para no saturar el procesador
    }
    			
    			
  5. Open the LightBlue App and follow these steps
    • Select Led Control Network (Generated by ESP32C3 coding)
    • Click Properties Write
    • Once there, at the top right, click on Hex
    • A new window will open, you'll have four (04) options - Hex, Octal, Binary, UTF-8 String - you need to select the one according to your programing, in our case we select UTF-8 String
    • Then, the app will take you back to Properties write and there you'll must click on Write new value
    • And there you'll need to enter, in this case, 1 to turn the LED on, and 0 to turn it off

    In the following image you can observe the process

You can download the KiDCad library here.

In the follorwing video you can observe the final result when controlling the LED

SErvoMotor Control by Bluetooth

After LED controling, I decided to try ServoMotor Controling using a ESP32C3, because I will need that for my final project. The proces logic was the following:

  1. Connect a Servomotor using a board with his own controller, this board will requiered an AC to function
  2. Connect the servomotor board with ESP32C3's board using DIO and GND's pin
  3. The ESP32C3's board will be simultaneously connected to the servomotor board and the computer, like shown in the following picture
  4. Decide how the the information is going to be transfered from the Cellphone to the microcontroller and then to the servomotor
  5. Generate the coding that allows to control servomotor movement using the microcontroller and an app
    • For this step I asked Chat GPT using the following prompt
    • The coding requiered to install an Arduino IDE's library
    • 				
      #include 
      #include 
      #include 
      #include 
      #include 
      						
      #define SERVO_PIN D3 // Cambia el pin según la conexión de tu servo
      #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
      #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
      						
      BLEServer* pServer = NULL;
      BLECharacteristic* pCharacteristic = NULL;
      bool deviceConnected = false;
      Servo myServo;
      						
      class MyServerCallbacks : public BLEServerCallbacks {
      	void onConnect(BLEServer* pServer) {
      	  deviceConnected = true;
      	};
      						
      	void onDisconnect(BLEServer* pServer) {
      	  deviceConnected = false;
      	}
      };
      						
      class MyCallbacks : public BLECharacteristicCallbacks {
      	void onWrite(BLECharacteristic *pCharacteristic) {
      	  std::string value = pCharacteristic->getValue();
      						
      	  if (value.length() > 0) {
      		if (value[0] == '1') {
      		  myServo.write(90); // Mueve el servo a 90 grados (posición media)
      		} else if (value[0] == '0') {
      		  myServo.write(0); // Mueve el servo a 0 grados (posición mínima)
      		}
      	  }
      	}
      };
      						
      void setup() {
        Serial.begin(115200);
        pinMode(SERVO_PIN, OUTPUT);
        myServo.attach(SERVO_PIN);
      			
        BLEDevice::init("ServoControl");
        pServer = BLEDevice::createServer();
        pServer->setCallbacks(new MyServerCallbacks());
      				
        BLEService *pService = pServer->createService(BLEUUID(SERVICE_UUID));
        pCharacteristic = pService->createCharacteristic(
      					  BLEUUID(CHARACTERISTIC_UUID),
      					  BLECharacteristic::PROPERTY_WRITE
      					);
      						
        pCharacteristic->setCallbacks(new MyCallbacks());
      						
        pService->start();
        BLEAdvertising *pAdvertising = pServer->getAdvertising();
        pAdvertising->start();
        Serial.println("Esperando la conexión Bluetooth...");
      }
      						
      void loop() {
        if (deviceConnected) {
      	// Puedes realizar otras tareas mientras está conectado
        }
        delay(1000); // Espera para no saturar el procesador
      }
      						
      
      
    • Open the LightBlue App and follow these steps
      • Select Servo Control Network (Generated by ESP32C3 coding)
      • Click Properties Write
      • Once there, at the top right, click on Hex
      • A new window will open, you'll have four (04) options - Hex, Octal, Binary, UTF-8 String - you need to select the one according to your programing, in our case we select UTF-8 String
      • Then, the app will take you back to Properties write and there you'll must click on Write new value
      • And there you'll need to enter, in this case, 1 to move the servomotor's arm 90° clockwise, and 0 to move it back to the first position

      In the following images you can observe the process

You can download the KiDCad library here.

In the follorwing video you can observe the final result when controlling the ServoMotor