Example Code for Arduino-Voltage Output

In this example, we will Demonstrates the variation of output voltage for the same input signal in two different states. Input signal value range: 0-255 - In the state of 0-5V: Input value of 176, resulting in an output voltage of 3.45V. - In the state of 0-10V: Input value of 176, resulting in an output voltage of 6.90V.

Hardware Preparation

Name Model/SKU Quantity Purchase Link
DFR1036 Gravity: GP8101S 1-Channel PWM to 0-5V/10V DAC Module DFR1036 1 Product Link
DFRobot arduino uno r3 DFR0216 1 Product Link

Software Preparation

Wiring Diagram

Sample Code

#include <DFRobot_GP8XXX.h>

//Output IO Port
int pwmPin = 9;
DFRobot_GP8101S GP8101S(pwmPin);
void setup() {

  GP8101S.begin();

  /**
   * @brief. Set the output DAC value.
   * @param data pwm 
   * @n. Optional parameters (0-255) correspond to voltage ranges of (0-5V) or (0-10V), and the specific voltage range is determined by the fluctuation switch selected based on the module voltage. 
   */
  GP8101S.setDACOutVoltage(176);//Output voltage of 3.45V under the 0-5V state and 6.90V under the 0-10V state.
}

void loop() {

}

Result

After downloading the program, the voltmeter was used to measure the actual output voltage of 3.45V under the 0-5V state and 6.90V under the 0-10V state.

Was this article helpful?

TOP