DAC (Digital-analog converter) MCP4725-Actuators

You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Dasduino and the basic code. Everything else is left to your imagination.


Microcontrollers, just like any other computer, work with digital signals for easy computing and saving data, and since most of these signals are actually analog, we need a circuit which will convert digital signal to analog. The desired effect will be obtained using this module which contains 12bit MCP4725 digital-analog converter (DAC). We will start by naming some characteristics of this module, and then we will explain how it works and how to connect it and use it with Dasduino.

Voltage: 2.7V – 5.5V
Resolution: 12 bita
Communication interface: I2C
Dimensions: 15 mm x 12 mm


The module is designed in a way that ensures easy use and compatibility with experimental boards and other modules and controllers in our offer. To this converter, we send a number from the 0-4095 interval, and on the output of the converter we get the voltage between 0V and VCC (power supply voltage). Due to conductor’s high resolution, we can get very nice signals on the output, because the difference between two adjacent values is merely 1.22mV. All digital-analog converters work by the following principle. We send a set of data to DAC, and it gradually turns them into voltage signal in a way that it converts one information into voltage equivalent to its output voltage which it keeps constant until it finds another information. For example, if we send 0->2048->0->2048->… data to the DAC, on the output we would get a rectangular signal between 0V and VCC/2. If we want to achieve a more complex analog signal, like sinusoidal, we must send a multitude of data to the DAC (numbers from the 0-4095 interval) which change by the sinusoidal function. In the image below, we see a sine waveform obtained by this module. If we reduce the time scale, i.e. zoom in on the signal, we will see how it is composed of a number of different values.

Screen Capture


gnd: ground
VCC: voltage 2.7V – 5.5V
SDA: serial data I2C
SCL: serial clock0
Vout: output voltage 

In order to use the module with Dasduino, it is necessary to connect it in a way shown in the picture. Module power supply can be obtained by connecting +5V pin on the Dasduino to VCC pin on the module. Gnd connector of the module is connected to one of the two gnd Dasduino pins. Communication is achieved by connecting the SDA pin on the module to A4 pin on the controller, and SCL to A5. Output connectors of the module are connected to an oscilloscope probe to show you the vaweform voltage.


To make the use of this module easier, we will use the adafruit mcp4725 library which you can find here. The instructions on how to install Arduino libraries can be found in this tutorial. The program code shows how using Dasduino and this DAC we can generate an analog sinusoidal signal whose frequency and amplitude we can change.

#include "Adafruit_MCP4725.h"                      //Library for the I2C communication
#include "Wire.h"       
Adafruit_MCP4725 dac;
#define DAC_RESOLUTION    (12)        //Selecting the converter's resolution
void setup(void) {
  dac.begin(0x64);             //the address must be adjusted to 0x64 because that is the way it is circuit-configured
  Serial.println("Generating a sine wave");
void loop(void) {
  float t = 0.0f;
  float f = 240;    //Selecting the frequency
  float A = 1;    //Selecting the amplitude in volts( from 0 to VCC/2 ), for 5V supply, select A between 0 and 2.5 V
  int wait;
  int out = 0;
  t = micros()/1000000.0;
  out = 2048 + 2048*A/2.5*sin(2*PI*f*t);
  if(out > 4095){
    out = 4095;   
  dac.setVoltage(out, false);
  wait = racunajdelay(f);
int racunajdelay (int frekvencija){
  float T;
  T = 1000000/(frekvencija*4096);
  return T;