Hi Everyone,
Ive set up an aquarium IoT project. I have a pretty sophisticated inline heater in place that has lots of built in safeties. However, since I have a relay controlling its outlet, I wanted to add just a “watch dog” high limit safety in the event that the water temp reached an unsafe level, indicating a malfunction with the heater or its safeties.
I have a thermistor in place, giving me good data. But when I go to set up a trigger, it does not appear in my “IF” drop down. Is this a bug? Am I doing something wrong?
I integrated the sketch Cayenne produced when adding the widget with my my main code for the rest of the actuators which included the <Cayenne.Temperature.h>. It is just a generic 10k ohm thermistor, so in theory you dont need any special library as its just a true analog value being interpenetrated correct?
I have tried deleting and adding the same device as a generic analog input and also have had success with monitoring through the widget, but it still does not appear in my “IF” drop down. I am unaware it would re-add anything automatically though… could you explain that a little more please?
Here is my code if it helps
Thanks!
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTSerial.h>
#include <CayenneTemperature.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL_1 V1
#define DIGITAL_PIN_12 12 //LIGHT
#define VIRTUAL_CHANNEL_2 V2
#define ACTUATOR_PIN_11 11 //AIR PUMP
#define VIRTUAL_CHANNEL_3 V3
#define ACTUATOR_PIN_10 10 //WAVE MAKERS
#define VIRTUAL_CHANNEL_4 V4
#define ACTUATOR_PIN_9 9 //HEATER
#define VIRTUAL_CHANNEL_5 V5
#define ACTUATOR_PIN_8 8 // FILTER & PUMP
#define VIRTUAL_CHANNEL_6 V6
#define SENSOR_PIN A5
const float resistance = 9780;
Thermistor thermistor(SENSOR_PIN, resistance);
void setup()
{
//Serial.begin(9600);
pinMode(DIGITAL_PIN_12, OUTPUT);
pinMode(ACTUATOR_PIN_11, OUTPUT);
pinMode(ACTUATOR_PIN_10, OUTPUT);
pinMode(ACTUATOR_PIN_9, OUTPUT);
pinMode(ACTUATOR_PIN_8, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL_1)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(DIGITAL_PIN_12, HIGH);
}
else {
digitalWrite(DIGITAL_PIN_12, LOW);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN_11, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN_11, LOW);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL_3)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN_10, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN_10, LOW);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL_4)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN_9, LOW); // LOGIC IS INVERTED FOR NC WIRING
}
else {
digitalWrite(ACTUATOR_PIN_9, HIGH);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL_5)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN_8, LOW); // LOGIC IS INVERTED FOR NC WIRING
}
else {
digitalWrite(ACTUATOR_PIN_8, HIGH);
}
}
CAYENNE_OUT(VIRTUAL_CHANNEL_6)
{
// This command writes the temperature in Celsius to the Virtual Channel.
//Cayenne.celsiusWrite(VIRTUAL_CHANNEL, thermistor.getCelsius());
// To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL_6, thermistor.getFahrenheit());
//Cayenne.kelvinWrite(VIRTUAL_CHANNEL, thermistor.getKelvin());
}
Delete the temperature widget from the dashboard. Once you upload the code successfully, Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL_6, thermistor.getFahrenheit()); will create a green temporary widget on your dashboard with channel 6. Click on the + to make it permanent.