Dust density with a TTGO LoRa32 V2.1_1.6 and with a Sharp GP2Y1010AU0F sensor

Hello dears.
I am working on a prototype to measure the density of dust with a TTGO LoRa32 V2.1_1.6 and with a Sharp GP2Y1010AU0F sensor. The code compiles me and is loaded to the Lora32 without problems but when reading the data on the screen or on the serial monitor it marks zero in all the results "Voltage, density of dust" we think that we could be connecting the sensor wrong to the board "int ledPower = 12; // Digital pin for the IRED - int measurePin = 36; // Analog pin for the Vo pin of the GP2Y10 sensor" Please if you could help me to correctly define the pins that I should connect to the Lora32 .
Sorry if I write something wrong, I'm not that good with the English language.
Thanks for your help.


//TTGO ESP32 LoRa Sensor Node Code
//Libraries for LoRa
 #include <U8g2lib.h>
 #include <SPI.h>
 #include <LoRa.h>
 #include <GP2YDustSensor.h>
 //Declaracion de variables//
 int ledPower = 12;      // Pin digital para el IRED
 int measurePin = 36;    // Pin anal├│gico para el pin Vo del sensor GP2Y10 
 GP2YDustSensor dustSensor(GP2YDustSensorType::GP2Y1010AU0F, ledPower, measurePin);

//Definir los pines utilizados por el m├│dulo transceptor LoRa
#define SCLK 5
#define MISO 19
#define MOSI 27
#define CS 18
#define RST 23
#define DIO 26

//Definicion frecuencia
 #define BAND 915E6    //433E6 for Asia, 866E6 for Europe, 915E6 for North America

//Packet counter
  int readingID = 0;
  int  counter = 0;
  String LoRaMessage = "";


  int samplingTime = 280;
  int deltaTime = 40;
  int sleepTime = 9680;
 
  float voMeasured = 0;
  float calcVoltage = 0;
  float dustDensity = 0;
  float pm05 = 0;

  U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0); 

//Initialize LoRa module
  void startLoRA()
  {
  LoRa.setPins(CS, RST, DIO); //Setup LoRa transceiver module

  while (!LoRa.begin(BAND) && counter < 10) {
  Serial.print(".");
  counter++;
  delay(500);
  }
  if (counter == 30) 
  {
//Increment readingID on every new reading
  readingID++;
  Serial.println("Starting LoRa failed!"); 
  }
  Serial.println("LoRa Initialization OK!");
  delay(2000);
  }


    void startGP2YDustSensor(){

    digitalWrite(ledPower,LOW);
    delayMicroseconds(samplingTime);      //Retardo de 0,28ms
  
    voMeasured = analogRead(measurePin);  //Se muestra el valor de voMeasured a trav├ęs del pin anal├│gico 36

    delayMicroseconds(deltaTime); // Retardo de 0,04ms
    digitalWrite(ledPower,HIGH);  // LED desactivado
    delayMicroseconds(sleepTime); // Retardo de 9,68ms
  
    }
  
   void getReadings(){
   //Calcular Voltaje
   // 0-5 V asignado a 0-1023 valores enteros
      calcVoltage = voMeasured * (5.0 / 1024.0);

   // Calcular Densidad de particulas de polvo
    /*dustDensity = 0.17 * calcVoltage - 0.1;  // Utilizar esta escuaci├│n para unidad mg/m3*/
      dustDensity = (0.17 * calcVoltage - 0.1) * 1000; // Utilizar esta escuaci├│n para unidad ug/m3

   /* Calcular material particulado (PM)
      pm05 = (calcVoltage - 0.0356) * 120000; // PM 0.5(particulas/0.01 pie3)*/

   // Imprimir en monitor serial
     Serial.print(F("Voltaje: "));
     Serial.print(calcVoltage);
     Serial.print(F("%  Densidad de Polvo: "));
     Serial.print(dustDensity);
     Serial.println(F("ug/m3"));    
     
     }

  void sendReadings() {
  
   LoRaMessage = String(readingID) + "/" + String(calcVoltage) + "&" + String(dustDensity) ;
 //Enviar paquete LoRa al receptor
   LoRa.beginPacket();
   LoRa.println(LoRaMessage);
   LoRa.endPacket();

   Serial.print("Sending packet: ");
   Serial.println(readingID);
   readingID++;
   Serial.println(LoRaMessage);
   
   }

  void setup() {
//initialize Serial Monitor
    Serial.begin(115200);
    startGP2YDustSensor();
    startLoRA();
    
    u8g2.begin();
    u8g2.clearBuffer();                       //Limpiar la memoria interna
    u8g2.setFont(u8g2_font_logisoso24_tr);    //Elija una fuente adecuada en https://github.com/olikraus/u8g2/wiki/fntlistall
    u8g2.drawStr(8,29,"Welcome");             //Escribe algo en la memoria interna
    u8g2.sendBuffer();                        //Transferir la memoria interna a la pantalla
    delay(1000);
  //Se debe aprender a calibrar la pantalla

    }
  
  void loop() {
    
  getReadings();
  sendReadings();
  delay(500);
  
  u8g2.clearBuffer();                          //Limpiar la memoria interna
  u8g2.setFont(u8g2_font_pxplusibmvga9_tr);    //Elija una fuente adecuada en https://github.com/olikraus/u8g2/wiki/fntlistall
  u8g2.drawStr(0,15,"Dust Density ");          //Escribe algo en la memoria interna
  u8g2.setCursor(0, 31);
  u8g2.print(dustDensity); 
  u8g2.sendBuffer();                           //Transferir la memoria interna a la pantalla
  delay(1000);


  u8g2.clearBuffer();                          //Limpiar la memoria interna
  u8g2.setFont(u8g2_font_pxplusibmvga9_tr);    //Elija una fuente adecuada en https://github.com/olikraus/u8g2/wiki/fntlistall
  u8g2.drawStr(0,15,"Voltaje ");               //Escribe algo en la memoria interna
  u8g2.setCursor(0, 31);
  u8g2.print(calcVoltage); 
  u8g2.sendBuffer();                           //Transferir la memoria interna a la pantalla
  delay(1000);
  
  }

You may get a better response if the title is in English.

1 Like

Thanks for your comment, friend