Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A8S ESP32 I/O pin define
#6
I'm trying to use the Digital Output but it doesn't work for the sensor HC-SR04 that I'm using.
I already tried to declarate the Digital Output through the IIC gpio expander PCF8074 with the adress 0x22 but it doesn't work.
I'm working with KC868-A8S.

This is the normal code for the HC-SR04:


const int Trigger = 2;  //Pin digital 2 para el Trigger del sensor
const int Echo = 3;  //Pin digital 3 para el Echo del sensor

void setup() {
  Serial.begin(9600);//iniciailzamos la comunicación
  pinMode(Trigger, OUTPUT); //pin como salida
  pinMode(Echo, INPUT);  //pin como entrada
  digitalWrite(Trigger, LOW);//Inicializamos el pin con 0
}

void loop()
{

  long t; //timepo que demora en llegar el eco
  long d; //distancia en centimetros

  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);          //Enviamos un pulso de 10us
  digitalWrite(Trigger, LOW);
 
  t = pulseIn(Echo, HIGH); //obtenemos el ancho del pulso
  d = t/59;            //escalamos el tiempo a una distancia en cm
 
  Serial.print("Distancia: ");
  Serial.print(d);      //Enviamos serialmente el valor de la distancia
  Serial.print("cm");
  Serial.println();
  delay(100);          //Hacemos una pausa de 100ms
}
Reply


Messages In This Thread
KC868-A8S ESP32 I/O pin define - by admin - 05-31-2022, 12:43 AM
RE: KC868-A8S ESP32 I/O pin define - by admin - 01-01-2023, 02:38 AM
RE: KC868-A8S ESP32 I/O pin define - by alsubhi - 03-17-2023, 02:57 PM
RE: KC868-A8S ESP32 I/O pin define - by admin - 03-18-2023, 01:10 AM
RE: KC868-A8S ESP32 I/O pin define - by Oscar Daza - 10-19-2023, 12:47 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)