Controlling Multiple Sensor with Bluetooth

why not capture all the ultrasonic stuff in a sub-function with the prints and all the IR stuff in a 2nd sub-function with the prints can just call them both from loop every second or so?

what the reason for the serial commands?

I am assuming = really not knowing it. A part of the projects requirements is to have remotely activating / deactivating sensor-readings

There are a lot of more things to define:

how many characters can you send from your smartphone over bluetooth
are you limited to a single character or can you SEND multiple characters?

If you can send multiple-characters the mode of operation ultrasonic-sensor AND IR-sensor
at the same time
can be activated through sending TWO characters "UI" U for ultra-sonic "I" for infrared

THis requieres to read in not only a single character but multiple characters.

If you don't want to do this approach another approach is to use different single characters for each mode of operation

	switch (data) {
      case 'A': 
        OperationMode = readOnlyUltraSonicSensor;
        break;


      case 'B': 
        OperationMode = readOnlyInfraRedSensor;
        break;

      case 'C': 
        OperationMode = read_UltraSonic_And_InfraRedSensor;
        break;

 
      case 'D': 
        // whatever else modes of operation are needed
        break;
void operateSensors() {

	switch (OperationMode) {
      case readOnlyUltraSonicSensor: 
        // code for that
        break;

      case readOnlyInfraRedSensor: 
        // code for that
        break;

      case read_UltraSonic_And_InfraRedSensor: 
        // code for that
        break;

}

Same philosophy as gcjr:
very good coding divides the code into functional sub-units where each subunit does ONE SINGLE thing

This means there is a function for

-reading distance from the ultraSonic-Sensor one time

-reading infraRed-Sensor one time

  • etc.

And bases on that the mode read_UltraSonic_And_InfraRedSensor

does a call to the two BASIC functions
-reading distance from the ultraSonic-Sensor one time
-reading infraRed-Sensor one time

best regards Stefan