Smart Home Automation Forum
【Sensor series program】-#01-Arduino code of KC868-A6 and Hall Sensor - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A6 (https://www.kincony.com/forum/forumdisplay.php?fid=22)
+--- Thread: 【Sensor series program】-#01-Arduino code of KC868-A6 and Hall Sensor (/showthread.php?tid=1935)



【Sensor series program】-#01-Arduino code of KC868-A6 and Hall Sensor - KinCony Support - 05-20-2022

【Sensor series program】-#01-Arduino code of KC868-A6 and Hall Sensor

Code:
/*【Sensor series program】Arduino code of KC868-A6 and Hall Sensor*/
/*When the Hall sensor is triggered, Turn on relay 1; Otherwise turn off relay1*/
#include "Wire.h"
#include"PCF8574.h"

PCF8574 pcf8574_RE(0x24,4,15);
int rawValue;

void setup(){

  pinMode(32,INPUT);
  Serial.begin(115200);
  pcf8574_RE.pinMode(P0,OUTPUT);
  pcf8574_RE.pinMode(P1,OUTPUT);
  pcf8574_RE.pinMode(P2,OUTPUT);
  pcf8574_RE.pinMode(P3,OUTPUT);
  pcf8574_RE.pinMode(P4,OUTPUT);
  pcf8574_RE.pinMode(P5,OUTPUT);
  pcf8574_RE.begin();
  for(int i=0;i<6;i++)
  {
   pcf8574_RE.digitalWrite(i,HIGH);
  }
}

void loop(){
  rawValue=analogRead(32);
  Serial.println(rawValue);
  if(rawValue==0)
  {
     
      pcf8574_RE.digitalWrite(P0,LOW);
  }
  else {
      pcf8574_RE.digitalWrite(P0,HIGH);
  }
}