/* Cayenne WiFi Example This sketch connects to the Cayenne server using an Arduino WiFi shield and runs the main communication loop. The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager. Steps: 1. Set the token variable to match the Arduino token from the Dashboard. 2. Set the network name and password. 3. Compile and upload this sketch. For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data should be sent to those pins using virtualWrites. Examples for sending and receiving Virtual Pin data are under the Basics folder. www.carloskwiek.com.br */ #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include "CayenneDefines.h" #include "BlynkSimpleEsp8266.h" #include "CayenneWiFiClient.h" // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "Token here"; // Your network name and password. char ssid[] = "Here"; char password[] = "Here"; //Programa: Conectando Sensor Ultrassonico HC-SR04 ao Arduino //Autor: Carlos Kwiek //Carrega a biblioteca do sensor ultrassonico #include //Define os pinos para o trigger e echo #define pino_trigger 4 #define pino_echo 2 #define VIRTUAL_PIN V1 #define VIRTUAL_PIN V2 word Tempo = 0; // variavel para guardar o valor inicial de millis word Intervalo = 0; // variavel para guardar o valor do intervalo //Inicializa o sensor nos pinos definidos acima Ultrasonic ultrasonic(pino_trigger, pino_echo); void setup() { Serial.begin(9600); Cayenne.begin(token, ssid, password); //Serial.println("Lendo dados do sensor..."); } void loop(){ { //Le as informacoes do sensor, em cm e pol float cmMsec, inMsec; long microsec = ultrasonic.timing(); cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM); inMsec = ultrasonic.convert(microsec, Ultrasonic::IN); //Exibe informacoes no serial monitor //Serial.print("Distancia em cm: "); //Serial.print(cmMsec); //Serial.print(" - Distancia em polegadas: "); //Serial.println(inMsec); Cayenne.virtualWrite(V1,cmMsec); Cayenne.virtualWrite(V2, inMsec); } { Cayenne.run(); } }