Smart Home Automation Forum
PCF8574 IO Expansion i2c relay board -DO8 arduino demo code - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: Extender module (https://www.kincony.com/forum/forumdisplay.php?fid=57)
+--- Thread: PCF8574 IO Expansion i2c relay board -DO8 arduino demo code (/showthread.php?tid=4589)



PCF8574 IO Expansion i2c relay board -DO8 arduino demo code - admin - 02-23-2024

Code:
#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574(0x27,4,5);  //4 is SDA  5 is SCL  need replace by your board's pin define
/*
A0  A1  A2
0    0    0    =0x20
0    0    1    =0x21
0    1    0    =0x22
0    1    1    =0x23
1    0    0    =0x24
1    0    1    =0x25
1    1    0    =0x26
1    1    1    =0x27
*/
void setup()
{
    Serial.begin(115200);
//    delay(1000);
    // Set pinMode to OUTPUT
    pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, OUTPUT);
  pcf8574.pinMode(P2, OUTPUT);
  pcf8574.pinMode(P3, OUTPUT);
  pcf8574.pinMode(P4, OUTPUT);
  pcf8574.pinMode(P5, OUTPUT);
  pcf8574.pinMode(P6, OUTPUT);
  pcf8574.pinMode(P7, OUTPUT);
//    pcf8574.pinMode(P1, INPUT);
    Serial.print("Init pcf8574...");
    if (pcf8574.begin()){
        Serial.println("OK");
    }else{
        Serial.println("KO");
    }
}
void loop()
{
    pcf8574.digitalWrite(P0, HIGH);
  delay(300);
  pcf8574.digitalWrite(P0, LOW);
  delay(300);
}
arduino code download

.zip   DO8.zip (Size: 485 bytes / Downloads: 149)
PCF8574 arduino library ZIP file download:

.zip   PCF8574_library.zip (Size: 23.8 MB / Downloads: 148)


RE: PCF8574 IO Expansion i2c relay board -DO8 arduino demo code - Tadashi97 - 10-30-2024

I try this, but doens work, my arduino didnt recognize de product, dont find the i2c address in any position.. I try using a i2c scanner but doesnt connect.


RE: PCF8574 IO Expansion i2c relay board -DO8 arduino demo code - admin - 10-30-2024

make sure your arduino device have set correct i2c bus pins, check with SDA and SCL pin define.