Arduino Cloud
Arduino Cloud
The following variables are automatically generated and updated when changes are
made to the Thing
CloudTemperatureSensor temperature;
CloudRelativeHumidity humidity;
String texto;
CloudLight led;
float ultrasonido;
Variables which are marked as READ/WRITE in the Cloud Thing will also have
functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "DHT.h"
#define DHTPIN 15
#define DHTTYPE DHT11
//Motor 1 izquierdo
#define PIN_MOTOR_L_1 18 // Pin 14 de L293
#define PIN_MOTOR_L_2 19 // Pin 10 de L293
//Motor 2 derecho
#define PIN_MOTOR_R_3 25 // Pin 7 de L293
#define PIN_MOTOR_R_4 26 // Pin 2 de L293
DHT dht(DHTPIN,DHTTYPE);
long duration;
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(PIN_MOTOR_L_1, OUTPUT);
pinMode(PIN_MOTOR_L_2, OUTPUT);
pinMode(PIN_MOTOR_R_3, OUTPUT);
pinMode(PIN_MOTOR_R_4, OUTPUT);
digitalWrite(PIN_MOTOR_L_1, LOW);
digitalWrite(PIN_MOTOR_L_2, LOW);
digitalWrite(PIN_MOTOR_R_3, LOW);
digitalWrite(PIN_MOTOR_R_4, LOW);
// Defined in thingProperties.h
initProperties();
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
if (millis()-lastMillis > 10000){
DHT_SENSOR_READ();
lastMillis = millis();
}
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
onTextoChange();
}
void DHT_SENSOR_READ(){
float h = dht.readHumidity();
float t = dht.readTemperature();
temperature = t;
humidity = h;
void onTextoChange() {
if(texto == "w"){
Serial.println("Forward");
digitalWrite(PIN_MOTOR_L_1, HIGH);// Al activar gira el motor A en sentido
de las agujas del reloj.
digitalWrite(PIN_MOTOR_L_2, LOW);// Al activar gira el motor A en sentido
contra las agujas del reloj.
digitalWrite(PIN_MOTOR_R_3, HIGH);// Al activar gira el motor B en sentido
de las agujas del reloj.
digitalWrite(PIN_MOTOR_R_4, LOW);// Al activar gira el motor B en sentido
contra las agujas del reloj.
}
if(texto == "b"){
Serial.println("Backward");
digitalWrite(PIN_MOTOR_L_1, LOW);
digitalWrite(PIN_MOTOR_L_2, HIGH);
digitalWrite(PIN_MOTOR_R_3, LOW);
digitalWrite(PIN_MOTOR_R_4, HIGH);
if(texto == "r"){
Serial.println("Right");
digitalWrite(PIN_MOTOR_L_1, LOW);
digitalWrite(PIN_MOTOR_L_2, HIGH);
digitalWrite(PIN_MOTOR_R_3, HIGH);
digitalWrite(PIN_MOTOR_R_4, LOW);
}
if(texto == "l"){
Serial.println("Left");
digitalWrite(PIN_MOTOR_L_1, HIGH);
digitalWrite(PIN_MOTOR_L_2, LOW);
digitalWrite(PIN_MOTOR_R_3, LOW);
digitalWrite(PIN_MOTOR_R_4, HIGH);
if(texto == "s"){
Serial.println("Stop ");
digitalWrite(PIN_MOTOR_L_1, LOW);
digitalWrite(PIN_MOTOR_L_2, LOW);
digitalWrite(PIN_MOTOR_R_3, LOW);
digitalWrite(PIN_MOTOR_R_4, LOW);
void onLedChange() {
// Do something
if (led == 1) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
}