Alexa Input IOT Cloud

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);
}

No direct answer, but I'm getting the disconnect from the IoT Cloud Authentication server reset issue too. Which in turn my roller shutter automation hardware triggers the shutter to close. I'm having to try and re-built my hardware to accomidate this service disruption (as it's not a power reset, which I can control).

Also this bit of code meant to be outside of your brackets?
digitalWrite(ledr, HIGH), digitalWrite(Green, LOW);

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.