IOT Basic Training with Cayenne
- Internet connected Computer/laptop Installed Arduino IDE Installed
- NodeMCU board manager
- LED, LDR, DHT, Resistor , Jumber Wires , Breadboard
- Mydevice Cayenne account.
- Libraries
- NodeMCU
- LDR
- 1K Ohm Resistor
- BreadBoard
int ldr = A0;
int ldr_data;
void setup()
{
pinMode(ldr,INPUT);
Serial.begin(9600);
}
void loop()
{
ldr_data = analogRead(ldr);
Serial.println(ldr_data);
delay(100);
}
- NodeMCU
- Cayenne account
- LDR
- 1K Ohm Resistor
- BreadBoard
#include <CayenneMQTTESP8266.h>
#include <ESP8266WiFi.h>
char ssid[] = "*****";
char password[] = "****";
char username[] = "****************";
char mqtt_password[] = "***********";
char client_id[] = "***************";
int ldr = A0;
int ldr_data;
void setup()
{
Cayenne.begin(username,mqtt_password,client_id,ssid,password);
pinMode(A0,INPUT);
}
void loop()
{
Cayenne.loop();
ldr_data = analogRead(ldr);
Cayenne.virtualWrite(0, ldr_data);
}
- NodeMCU
- Cayenne account
- Servo
- BreadBoard
#include <Servo.h>
#include <CayenneMQTTESP8266.h>
#include <ESP8266WiFi.h>
char ssid[] = "****";
char password[] = "****";
char username[] = "***********************";
char mqtt_password[] = "******************";
char client_id[] = "**********************";
Servo myservo;
void setup()
{
myservo.attach(D2);
Cayenne.begin(username,mqtt_password,client_id,ssid,password);
}
void loop()
{
Cayenne.loop();
}
CAYENNE_IN(1)
{
myservo.write(getValue.asInt());
}
- NodeMCU
- Cayenne account
- DHT11
- BreadBoard
#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
char ssid[] = "*****";
char password[] = "*********";
char username[] = "*****************";
char mqtt_password[] = "*************";
char client_id[] = "*****************";
DHT dht(7,DHT11);
void setup()
{
Cayenne.begin(username,mqtt_password,client_id,ssid,password);
}
void loop()
{
Cayenne.loop();
float temp = dht.readTemperature(true);
float hum = dht.readHumidity();
Cayenne.virtualWrite(1, temp, TYPE_TEMPERATURE , UNIT_FAHRENHEIT);
Cayenne.virtualWrite(2, hum, TYPE_RELATIVE_HUMIDITY , UNIT_PERCENT);
}