Soil Moisture Monitoring with Alexa

I'm trying to use an Arduino MKR wifi1010 to monitor soil moisture temperature, and I'd like to use the Amazon Alexa Arduino skill to send this data to my Alexa. After messing with it for a while, I've come to the realization that Alexa only plays nicely with certain devices and data types, and moisture sensors aren't one of them.
Is there a way I can get around this issue so that I can have my Alexa tell me my soil moisture percentage? I tried setting the percentage value as a long variable and then setting up the connection to Alexa using a temperature sensor value (which is listed as a long variable on the Alexa-compatible datatypes website) but this didn't work, and I ended up just getting no data sent to my Alexa. I'll paste my code here for reference:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/e4b4ee50-b7e5-4f2e-bae5-17fb775cbdb5 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudTemperatureSensor percentageHumidity;

  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"
#define moistIn A0

const long wet = 300;
const long dry = 780;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  while(!Serial);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here
  
long moisture= analogRead(moistIn); //Read sensor Val

float percentageHumidity = map(moisture, wet, dry, 100, 0); //Map to a percentage value

Serial.println(moisture);
Serial.print("Soil is at ");
Serial.print((percentageHumidity));
Serial.print("% moisture");
Serial.println();
delay(3000);       //Print soil moisture % every 3 seconds

}

Providing links to the datasheets of the temp and moisture sensors would likely help us.
The map function returns an integer. Why use a float variable? It adds nothing, changes nothing.
Read arduino/reference/map for learning about the map function.

I'm aware it generally maps to an int, I just created it as a float to try to pass it to my Amazon Alexa (you can't pass ints using Arduino IOT and Alexa for whatever reason).

I'm not using a temp sensor, and the moisture sensor itself isn't relevant. I'm just trying to figure out how to pass the value I get from the map function (some number 0-100) to the amazon alexa arduino IOT skill.

Here is link to the soil moisture sensor anyway:

chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://media.digikey.com/pdf/data%20sheets/dfrobot%20pdfs/sen0193_web.pdf

The float type variable percentHumidity is delared locally in loop and the IOT library can't see it, doesn't know about it.


I define the variable within the setup on Arduino IOT Cloud with the same name though, I just set it to a temp sensor because ints aren't an acceptable datatype

Then remove float in loop! That should work. Then loop will use the variable declared in setup.

I understand now, thanks for the help

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