# A Novel mHealth Approach for the Monitoring and Assisted Therapeutics of Obstructive Sleep Apnea
## 3 Materials and Methods
### Hardware  
It must be remembered that software and hardware are intrinsically connected, with the proper functioning of one depending on the proper functioning of the other.  
The circuit shown was divided into the following three main parts: the charging circuit part, the power circuit part, and the processing circuit part, as shown in Figure 11.  
Figure 10: Recording the number of apneic events on the database.  
Figure 9: Code 8—electrosimulation parameterization.  
Figure 11: Wiring diagram of the developed circuit.  
In the first part--the charging circuit--the schematic shows a USB port connected to the Qi charging system, more properly the Tx (transmitter) coil. In an idealized device, this circuit would be inside the charging base and be external to the device itself. This induction charging module operates on 5 V input. As such, it could be connected via USB to a conventional transformer in order to charge the circuit when it is nearby.  
The power supply circuit is a bit more complex, as some electronics are required for it to work properly.  
The Tx coil in the charging base transmits 5 V to the Rx coil in the device to charge the battery. The battery, in turn, has a maximum charging voltage of 4.2 V, and it is not possible to supply it with the 5 V received by the Rx coil. For this power supply to be possible, it is necessary to use a buck converter. This converter converts the input voltage to a specific output voltage so that the battery can be safely charged. In this circuit this converter has the function of lowering the input voltage from 5 V to a voltage of 3.3 V.  
Next in this circuit is an LED. This has a visual purpose so as to be perceptible during the testing phase, when the system is charging (LED on), and when it is being powered by the battery (LED off).  
A diode is placed between the charging system and the battery. This will allow current from the charging source to flow to the battery; however, it prevents the flow of energy in the opposite direction. This diode is present in the system so that when the circuit is not in the charging base, the battery does not power the Tx coil or the LED.  
When the system is running, it is entirely dependent on the battery, since it is a portable device. However, the battery, if used when fully charged, usually has a nominal voltage of 3.7 V. During the first few charging cycles it can reach 4.2 V, which is well above the maximum limit supported by the ESP32.  
In order for the system's input voltage to be in the ideal parameters for the microcontroller to work properly, it is necessary, once again, to use a buck converter to lower the voltage to 3.3 V, which is ideal for powering the circuit.  
Finally, the processing circuit is where the hardware and software merge in order to make the system work as desired.  
The ESP32 pin D2, which is connected to the output of the charging system, is used to control the start-up of the circuit. Whenever this pin is being powered up, this reports to the system that the device is in the charging base and does not need to be running. As soon as this pin stops receiving a signal, it means that the device has been removed from the charging base, which causes the microcontroller to wake up and check the requirements described in the code.  
The temperature sensor, powered by the ESP32 via pins 3v3 and GND, provides the required readings via pin D4.  
When all the constraints in the code are met, the EMG sensor can start collecting data through the surface electrodes. It is powered by the same pins as the DHT11 sensor and transmits the data to the ESP32 via pin D34.  
Whenever a possible apneic event is detected through the ESP32, an electrical stimulus is sent through the RX2 pin, with the parameters defined in the programming through the stimulation electrode. The LED, again, has a visual function, so that during the tests it could be seen when the stimulus was applied.