Example Code for Arduino-Sine Wave Output
Last revision 2025/12/27
This guide explains how to generate a 10Hz sine wave using Arduino and ESP32 with the GP8403 DAC module, including hardware setup, wiring, and code implementation.
Hardware Preparation
- FireBeetle 2 ESP32-E IoT Microcontroller (SKU: DFR0654) ×1
- 2-Channel I2C to 0-10V DAC Module (SKU: DFR0971) ×1
- Oscilloscope ×1
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE.
- Install SDK: click to enter FireBeetle ESP32-E IoT Microcontroller Wiki for SDK installation tutorial.
- Download and install the DFRobot_GP8403
- For Arduino IDE V1.8.19 (or earlier), install the library manually: How to Add a Library?
- For Arduino IDE V2.0.0 (or later), directly search for the "DFRobot_GP8403" in the Library Manager and install it.
Wiring Diagram

Wring Description
FireBeetle 2: 3V3 to DAC module: +
FireBeetle 2: GND to DAC module: -
FireBeetle 2: SCL to DAC module: SCL
FireBeetle 2: SDA to DAC module: SDA
Sample Code
Initialize GP8403 DAC, output 10Hz sine wave on OUT0.
#include "DFRobot_GP8403.h"
DFRobot_GP8403 dac(&Wire,0x58);
void setup() {
Serial.begin(115200);
while(dac.begin()!=0){
Serial.println("init error");
delay(1000);
}
Serial.println("init succeed");
//Set DAC output range
dac.setDACOutRange(dac.eOutputRange5V);
}
void loop(){
dac.outputSin(2500, 10, 2500, 0);//(voltage value, frequency (0~100Hz), voltage value, channel number)
}
Result
After downloading the code, a sine waveform with a frequency of 9.804Hz and an amplitude of ±2.5V can be observed on the oscilloscope display.

Was this article helpful?
