1

Hardware:

Board ESP32 Dev Module

Version/Date today's master

IDE name Arduino IDE

Flash Frequency 80Mhz

PSRAM enabled no

Upload Speed 115200

Computer OS Windows 10

Description:

I am doing a project where I want to collect data from different sensors and then display it on my Adafruit IO Dashboard. I have created a separate config.h file where I have stored the WiFi Credentials (in my case I am using Mobile Hotspot as Wifi), and also my Adafruit IO Key.

The code is compiled and uploaded successfully, and in my phone I can see esp32-arduino is connected to my mobile hotspot, nut when I open the Serial Monitor it shows "Connecting....." and also no data is being published on the Adafruit Dashboard



#include "config.h"                
#include "max6675.h"              
#include "EmonLib.h"             


#define CURRENT_CAL 62.6     
EnergyMonitor emon1;          

#define sound_PIN 34        
#define vib_PIN 35        
#define smoke_PIN 33      
#define current_PIN 39   
#define alarm_PIN 25   



int thermoDO = 19; 
int thermoCS = 23;
int thermoCLK = 5; 
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);


float Normal_Sound_Level= 250;     
float Normal_Vib_Level = 5000;    
int Normal_Smoke_Level= 20;  
int Normal_Temp_Level = 50;    
float Normal_Current_Level= 20.00;    
float First_Current_Reading=70.00;   

    
boolean is_Relay_on=true;
boolean is_Machine_on=true;
String Machine_Power;
String Machine_Power_Status; 
String Alarm_State;
boolean AlarmState=false;
String reason;
int relay_PIN=32;    




AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *Vibration = io.feed("vibration-intensity");
AdafruitIO_Feed *Smoke = io.feed("smoke-intensity");
AdafruitIO_Feed *Current = io.feed("current");

AdafruitIO_Feed *power = io.feed("power");

void setup() {
pinMode(sound_PIN, INPUT);
pinMode(vib_PIN, INPUT);
pinMode(smoke_PIN, INPUT);
pinMode(current_PIN, INPUT);
pinMode(relay_PIN, OUTPUT);
pinMode(alarm_PIN, OUTPUT);

  
  Serial.begin(115200);

      
  
  while(! Serial);

 
  Serial.print("Connecting to Adafruit IO");
  io.connect();

power->onMessage(handleMessage);

  
  while(io.status() < AIO_CONNECTED) {
    Serial.println("Connecting.......");
    Serial.println("If it Takes a Long Time, Check WIFI Username/Password!");
    delay(500);
  }

  
  Serial.println();
  Serial.println(io.statusText());
  
  if (is_Relay_on==true){
  power->save(HIGH);
}
  
 emon1.current(current_PIN, CURRENT_CAL);     
}


void loop() {

   io.run();  
  
switch (is_Relay_on) {
    case true:
      digitalWrite(relay_PIN,HIGH);
      Machine_Power="ON"; 
      AlarmState=false;
      Alarm_State="OFF";
      
      break;
      
    case false:
      digitalWrite(relay_PIN,LOW); 
      is_Machine_on=false;
      Machine_Power="OFF";
      AlarmState=true;
      Alarm_State="Triggered";
           
       break;
       
    default:
      break;
  }

while (( is_Machine_on)==true) {


  float sound_intense = analogRead(sound_PIN);
 if (sound_intense>Normal_Sound_Level){
  is_Relay_on= false;
  reason="((((((Abnormal Sound Values))))))";
}
   

float Vib_intense = analogRead(vib_PIN);

  if (Vib_intense>Normal_Vib_Level){
  is_Relay_on= false;
  reason="((((((Abnormal Vibration Values))))))";
}
 

int smoke_intense = analogRead(smoke_PIN);

if (smoke_intense>Normal_Smoke_Level){
 is_Relay_on= false;
 reason="((((((Abnormal Smoke Values))))))";
}



if (thermocouple.readCelsius()>Normal_Temp_Level){
 is_Relay_on= false;
 reason="((((((Abnormal Temperature Values))))))";
}
 


  emon1.calcVI(20,100);         
  
  float currentDraw   = emon1.Irms-2;            
  int supplyVoltage   = 220;                    

  if (currentDraw<0){
    currentDraw=-currentDraw*0;
  }
else{
  currentDraw=currentDraw;
}

if (currentDraw>=First_Current_Reading){
  currentDraw=0;
} 

  if (currentDraw>Normal_Current_Level){
  is_Relay_on= false;
  reason="((((((Abnormal Current Withdrawal Values))))))";
}


Current->save(currentDraw);
temperature->save(thermocouple.readCelsius());
Vibration->save(Vib_intense);
Smoke->save(smoke_intense); 
         

 
  Serial.println(" ");
  Serial.println("..................................................");
  Serial.println(" ");
  Serial.print("Recieved Machine Power: ");
  Serial.println("ON");
  Serial.println(" ");
  Serial.println("----->Sending----->-----> (((WIFI)))");
  Serial.println(" ");
  Serial.print("Machine Power: "); // Print the voltage.
  Serial.println(Machine_Power); // Print the voltage.
  Serial.print("Alarm State: "); // Print the voltage.
  Serial.println(Alarm_State); // Print the voltage.
  Serial.print("Sound Intensity: "); // Print the voltage.
  Serial.println(sound_intense);
  Serial.print("Vibration Intensity: "); // Print the voltage.
  Serial.println(Vib_intense); // Print the voltage.
  Serial.print("Smoke Density: "); // Print the voltage.
  Serial.println(smoke_intense); // Print the voltage.
  Serial.print("Temperature: "); 
  Serial.println(thermocouple.readCelsius());
  Serial.print("Current: ");
  Serial.println(currentDraw);
  Serial.print("Voltage: ");
  Serial.println(supplyVoltage);
  Serial.print("Watts: ");
  Serial.println(currentDraw * supplyVoltage);
  //power->save(HIGH); 
 // wait one second (1000 milliseconds == 1 second)

 delay(5000);
 break;
}


if (AlarmState==true) {
 dacWrite(alarm_PIN, 255); // buzzer ON
  delay(600);
  dacWrite(alarm_PIN, 0);
}
else{
  dacWrite(alarm_PIN, 0);
}


while (( is_Machine_on)==false) {


  Serial.println(" ");
  Serial.println("..................................................");
  Serial.println(" ");
  Serial.println(">>>>>>>>>>Stopped Sending<<<<<<<<<<");
  Serial.println(" ");
  Serial.print("Recieved Machine Power: ");
  Serial.println("OFF");
  Serial.print("Machine Power: "); // Print the voltage.
  Serial.println(Machine_Power); // Print the voltage.
  Serial.print("Alarm State: "); // Print the voltage.
  Serial.println(Alarm_State); // Print the voltage.
  Serial.print("Reason: ");
  Serial.print(reason);
  Serial.println(" ");
 
power->save(LOW);
 delay(1000);
 break;
}

}


void handleMessage(AdafruitIO_Data *data) {
  if(data->toPinLevel() == HIGH){
    
    Serial.print("Recieved Machine Power: ");
    Serial.println("ON");
       is_Relay_on=true;
         is_Machine_on=true; 
       
  }else{
    Serial.print("Recieved Machine Power: ");
    Serial.println("OFF");
       is_Relay_on=false;
       reason="(((((( Manual Online Shut Down ))))))";
      
  }   
}



This is the config.h:

#define IO_USERNAME    "xyz"
#define IO_KEY         "xyz"
#define WIFI_SSID       "test"
#define WIFI_PASS       "pass"
#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
4
  • 2
    It would help to include all of your code in the question (obfuscate your WiFi and Adafruit credential), or, even better, the minimum code that reproduces the problem. Also, what firmware is running on the ESP? – JRobert May 12 at 12:03
  • collabedit.com/qfvkd - You can see the whole code here, cannot paste the whole code in comments because of character limit. – greatworldboss May 12 at 14:57
  • please no code in comments, ever ... add code to the post – jsotola May 12 at 15:07
  • Ok I have included the full code as well as that of config.h file. – greatworldboss May 12 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.