Things used in this project

Hardware components:
Nodemcu
NodeMCU ESP8266 Breakout Board
×1
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
×1
09590 01
LED (generic)
×2
Software apps and online services:
Cayenne logo hi
myDevices Cayenne
Ide web
Arduino IDE

Schematics

SEBi_Client
Sebi layout ifmz9ve7gk

Code

SEBI_Client NodeMCU codeC/C++
#include <CayenneMQTTESP8266.h> 

char ssid[] = "wifi name"; 
char password[] = "wifi password"; 

char username[] = "mqtt user name"; 
char mqtt_password[] = "mqtt password"; 
char client_id[] = "mqtt client id"; 

#define trigPin D2 
#define echoPin D5 

int green = D6; 

void setup()
{ 

 Cayenne.begin(username,mqtt_password,client_id,ssid,password); 

pinMode(green,OUTPUT); 
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
Serial.begin(115200);  

digitalWrite(green,HIGH); 

} 
void loop(){
 
 Cayenne.loop(); 

long duration, distance; 

digitalWrite(trigPin, LOW);  
delayMicroseconds(2);  
digitalWrite(trigPin, HIGH); 
delayMicroseconds(10);  
digitalWrite(trigPin, LOW); 
duration = pulseIn(echoPin, HIGH); 
distance = (duration/2) / 29.1; 

Serial.println(distance); 

Cayenne.virtualWrite(3,distance); 

delay(1000); 

} 

CAYENNE_IN(1)
{ 
  digitalWrite(green,!getValue.asInt()); 
}  

Credits

Dsc05679 xxk38knz8i
Salman Faris
10 projects • 191 followers
Maker | Hardware Hacker | Electronics Enthusiast
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog