So i have a motor connected to a blind with an ultrasonic range sensor. It works fine but when it disconnects from the cloud and reconnects it will turn on again causing it to go above the measured distance and nearly breaking the blind. Is there a way for Alexa to set the on input (which is up) so if it disconnects and reconnects it's still set as on and doesn't re-activate?
UPDATE-- When the Blind==TRUE the ultrasonic range finder stops measuring the distance which causes the blind to not stop. This seams to be my problem?
Thanks in advanced
#include "thingProperties.h"
#include <Arduino_MKRENV.h>
#define ledr 2
#define ledb 3
#define trig 5
#define echo 6
#define Red 0
#define Green 1
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
pinMode(ledr, OUTPUT);
pinMode(ledb, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, OUTPUT);
pinMode(Red, OUTPUT);
pinMode(Green, OUTPUT);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
digitalWrite(ledr, HIGH);
digitalWrite(ledb, HIGH);
}
void loop() {
ArduinoCloud.update();
float duration, distance;
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = (duration / 2) * 0.0344;
if (distance > 0 && distance < 5)
digitalWrite(ledb, HIGH), digitalWrite(Red, LOW);
if (distance > 70 && distance < 95)
digitalWrite(ledr, HIGH), digitalWrite(Green, LOW);
}
void onBlindChange(){
if(Blind==true)
{
Blind = "HIGH";
delay(200);
digitalWrite(ledb, HIGH);
digitalWrite(ledr, LOW);
digitalWrite(Green, HIGH);
delay(8000);
}digitalWrite(ledr, HIGH), digitalWrite(Green, LOW);
if(Blind==false)
{
Blind="LOW";
delay(200);
digitalWrite(ledr, HIGH);
digitalWrite(ledb, LOW);
digitalWrite(Red, HIGH);
delay(8000);
digitalWrite(ledb, HIGH), digitalWrite(Red, LOW);
}
Serial.println(Blind);
}