05-20-2022, 03:11 AM
(This post was last modified: 05-20-2022, 05:03 AM by KinCony Support.)
【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);
}
}