PCF8591 Module Test Sketch

/*This sketch provides a demontration of the ADC feature of the PCF8591 Module.
A light dependent resistor (ldr), thermistor and potentiometer are provided on-board
and connected to ADC0, ADC2 and ADC3 respectively. ADC1 is unconnected. The
output from each ADC channel is shown via the serial monitor. You should see the
outputs change as you adjust the pot, warm or cool the thermistor and cover the

#include "Wire.h" //the I2C comms library
#define address 0x48 // the module's I2C address is 0x48
int dt = 3000; // loop delay duration in ms.
byte value0, value1, value2, value3; //byte variables to hold the received data.

void setup()
    Wire.begin(); // wake up I2C bus.
    Serial.begin(9600);//initialise the serial monitor

void loop()
    Wire.beginTransmission(address); // wake up PCF8591
    Wire.write(0x04); //send the control byte, setting auto-increment flag (bit 2)

    Wire.requestFrom(address, 5); //Request 5 bytes of data - these will be
    //ADC0 previous state, ADC0 current state, followed by current readings for 
    //ADC1, ADC2 & ADC3
    value0 = Wire.read(); //Ignore this one
    value0 = Wire.read(); //The LDR on the module.
    value1 = Wire.read(); //Unconnected on the module
    value2 = Wire.read(); //The thermistor on the module
    value3 = Wire.read(); //The potentiometer on the module.

    //Display the received ADC values.
    Serial.print("LDR - ");
    Serial.print("Thermistor - ");
    Serial.print("Pot - ");

Your IP Address is:
Copyright © 2022 Bitsbox. Powered by Zen Cart