Arduino projects

Connecting ADC/DAC PCF8591 Arduino

Analog to digital converters are a very important part in embedded electronics because most of the sensors provide output signals in the form of analog values ​​and the analog to digital converter feeds them into the microcontroller which can only understand binary values ​​and we have to convert these numbers into digital values. So to be able to process analog data, the microcontroller needs an analog to digital converter.

Some microcontrollers have inbuilt ADC like Arduino, MSP430, PIC16F877A but some microcontrollers don’t have it like 8051, Raspberry Pi etc. We have to use some external analog to digital converter IC like ADC0804, ADC0808. In this article, we will study how to interface PCF8591 ADC/DAC module to Arduino.

Required components

● Arduino UNO development board

● PCF8591 ADC module

● 100K potentiometer

● Connecting wire

PCF8591 ADC/DAC Module

The PCF8591 is an 8-bit analog-to-digital converter or 8-bit digital-to-analog converter module, which means each pin can read up to 256 analog values. It also has LDR and thermistor circuits provided on the board. The module has four analog inputs and one analog output. It is suitable for I2C communication, so the SCL and SDA pins are used for serial clock and serial data address. It requires a 2.5-6V supply voltage and has a low standby current. We can also control the input voltage by adjusting the knob of the potentiometer on the module. There are also three jumpers on the board. The J4 connection selects the thermistor access circuit, the J5 connection selects the LDR/photoresistor access circuit and the J6 connection selects the adjustable voltage access circuit. To access these circuits, you have to use the addresses of these jumpers: 0x50 for J6, 0x60 for J5 and 0x70 for J4. There are two LEDs on the board, D1 and D2 – D1 represents the output voltage intensity and D2 represents the supply voltage intensity. The higher the output or supply voltage, the higher the intensity of LED D1 or D2. You can also test these LEDs using a potentiometer on VCC or the AOUT pin.

Connecting ADC/DAC  PCF8591  Arduino

 

Connection Circuit of PCF8591 ADC/DAC Module with Arduino

The connection of PCF8591 with Arduino is very simple. In this connection example, we will read the analog values ​​from any analog pin and change those values ​​to the 100K potentiometer. First, connect VCC and GND to 5V and GND of Arduino. Next, connect SDA and SCL to A4 and A5 of Arduino. Now, connect the 100K potentiometer and AIN0 as shown in the figure. For LCD, the data pins (D4-D7) are connected to the digital pins D5-D2 of Arduino and RS and EN pin are connected to D12 and D11 of Arduino. V0 of LCD is connected to the potentiometer and 100k potentiometer for controlling the brightness of LCD.

Connecting ADC/DAC  PCF8591  Arduino

Connecting ADC/DAC PCF8591 Arduino

Arduino PCF8591 Analog-to-Digital Conversion (ADC) Programming

The complete program is given at the end of this article.

First, we need to define the libraries for I2C communication and LCD display.

  1. #include <Wire.h>
  2. #include <LiquidCrystal.h>

Copy code

Then define some macros. The first macro is used to define the data bus address of the IC and the second macro is used to define the address of the first input pin of the module where the input from the potentiometer is given.

  1. #define PCF8591 (0x90 >> 1)
  2. #define AIn0 0x00

Copy code

Next we define the pin connections for LCD with Arduino and initialize the value we get on the analog pin.

  1. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  2. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  3. int Value = 0;

Copy code

Now, let us get started with the setup() function. Here, we have initialized the I2C communication in the first line. In the second line, we have initialized the LCD display which is printing the analog values.

  1. void setup()
  2. {
  3. Wire.begin();
  4. lcd.begin(16,2);
  5. }

Copy code

In the loop function, the first line of code starts the transmission, i.e. it turns on the PCF8591. The second line tells the IC to make an analog measurement on the first analog input pin. The third line ends the transmission and the fourth line gets the measurement data from the analog pin.

  1. void loop()
  2. {
  3. Wire.beginTransmission(PCF8591);
  4. Wire.write(AIn0);
  5. Wire.endTransmission();
  6. Wire.requestFrom(PCF8591, 1);

Copy code

Next, we will place the value read from the analog pin into the value variable defined earlier. We will then print that value to the LCD.

  1. Value=Wire.read();
  2. lcd.print(“ADC Value=”);
  3. lcd.print(Value);
  4. delay(500);
  5. lcd.clear();}

Copy code

Finally upload the code to the Arduino development board and run it. The analog value will start to be displayed on the LCD display. Adjust the knob of the potentiometer and you will see the value change gradually.

Connecting ADC/DAC PCF8591 Arduino

Code

Here is the complete code used in this article: main

Back to top button