Aquarium iot is not working


#1

Hello all. I just finished one project to control my aquarium I am using an arduino Uno and an ethernet shield W5100. I control 2 relays to control my pump and filter, and I control 4 servos towerpro to control an automatic feeder. I was making trials with the code separately I mean I tested relays at the begin then 1 servo then 2 servos and everything was OK. However once I put all the code together it does not work anymore cayenne says the device is offline and my ethernet shield only turn on one red led. This is my code:

/*
Cayenne Servo Motor Example

This sketch sample file shows how to connect a Servo Motor with CayenneMQTT Library.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. Install the Servo library from the Arduino Library Manager.
  2. In the Cayenne Dashboard add a new Servo Motor widget.
  3. Select a virtual channel number for the widget.
  4. Set min value to 0 and max value to 1.
  5. Set the VIRTUAL_CHANNEL value below to the virtual channel you selected.
  6. Connect the Servo’s legs to GND, VCC (5.0), and a digital pin.
  7. Set the ACTUATOR_PIN value below to the digital pin number you selected.
  8. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  9. Compile and upload this sketch.
  10. Once the Arduino connects to the Dashboard you can use the slider to change the servo position.
    */

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “2df4fc80-c9d4-11e8-ac9c-271082632120”;
char password = “1276fc458e1e689d9e35efa7d15cf33c5795a5e2”;
char clientID = “50fb2450-c9e5-11e8-90bb-9f05022e95b7”;

#define VIRTUAL_CHANNEL 1
#define ACTUATOR_PIN 4
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 5
#define VIRTUAL_CHANNEL 3
#define ACTUATOR_PIN 6
#define VIRTUAL_CHANNEL 4
#define ACTUATOR_PIN 7
#define VIRTUAL_CHANNEL 5
#define ACTUATOR_PIN 8
#define VIRTUAL_CHANNEL 6
#define ACTUATOR_PIN 9
#define SENSOR_PIN 10
#define VIRTUAL_CHANNEL 7

Servo s1;
Servo s2;
Servo s3;
Servo s4;

OneWire oneWire(10);
DallasTemperature sensors(&oneWire);

void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Cayenne.begin(username, password, clientID);
s1.attach(6);
s2.attach(7);
s3.attach(8);
s4.attach(9);
sensors.begin();
}

void loop()
{
Cayenne.loop();
}

CAYENNE_OUT(7)
{
//
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Channel.
Cayenne.celsiusWrite(7, sensors.getTempCByIndex(0));

}

CAYENNE_IN(1)
{
// Encender y apagar el rele numero 1 conectado a un ventilador
if (getValue.asInt() == 0) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
}

CAYENNE_IN(2)
{
// Encender y apagar rele numero 2 cobectado al calentador.
if (getValue.asInt() == 0) {
digitalWrite(5, HIGH);
}
else {
digitalWrite(5, LOW);
}
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(3)
{
// Varia el angulo del servo para dimmear las luces amanecer.
int position = getValue.asDouble() * 90;
// Move the servo to the specified position.
s1.write(position);
}
CAYENNE_IN(4)
{
// Varia el angulo del servo para dimmear las luces de día.
int position = getValue.asDouble() * 90;
// Move the servo to the specified position.
s2.write(position);
}

CAYENNE_IN(5)
{
// Varia el angulo del servo para dimmear las luces anochecer.
int position = getValue.asDouble() * 90;
// Move the servo to the specified position.
s3.write(position);
}

CAYENNE_IN(6)
{
// Varia el angulo del servo para accionar el alimentador autmatico.
int value = getValue.asInt();
int position4 = value * 180;
s4.write(position4);
}


#2

Please also see this image:

image


#3

Does someone believe that I can replace the arduino uno and the shield for a mkr 1010??


#4

This because the is digital pins 10, 11, 12, and 13 are used by the ethernet shield shield for communication with arduino uno.

you can give it try thought this board is 3.3v and you will need a external power and a voltage divider.
Also you will need to change the code and follow the steps from https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/ESP32/ESP32.ino


#5

I changed the sensor to the pin 3 instead of 10 but I have the same problem also when I removed 1 servo the other 3 started working do you think I have a wiring trouble or a code trouble?? I believe the code is ok now that I am not using pin 10.


#6

can you try powering the servo from an external power supply.