Fady Tarek
Published © MIT

Aquarium Assistant

Control your fish tank, feed your fish, and more from anywhere in the world with the help of WIZ750SR and Google Assistant.

IntermediateFull instructions provided4 hours5,893
Aquarium Assistant

Things used in this project

Hardware components

WIZ750SR
WIZnet WIZ750SR
×1
Arduino Nano R3
Arduino Nano R3
×1
WIZ750SR-TTL-EVB Kit
WIZnet WIZ750SR-TTL-EVB Kit
×1
NeoPixel strip
NeoPixel strip
×1
Android device
Android device
×1
Servos (Tower Pro MG996R)
×1
Relay Module (Generic)
×1

Software apps and online services

MQTT
MQTT
IFTTT iftt
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Aquarium Assistant Connection

Schematic for connecting the Wiz750sr with arduino , Relay and servo

Code

w750sr

C/C++
Wiznet w750sr mbed.org main.c file
#include "mbed.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"
#include <sstream>
#include <string>

Serial s(PA_13,PA_14); // Communication with the Arduino Board

Serial out(USBTX,USBRX);  // Debuging through USB

void messageArrived(MQTT::MessageData& md)
{
    MQTT::Message &message = md.message;
    out.printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id);
    out.printf("Payload %.*s\n", message.payloadlen, (char*)message.payload);
    s.printf("%.*s\n", message.payloadlen, (char*)message.payload);//To send serial data to arduino
    int    i = atoi((char*)message.payload);
    switch(i) {
        case 0:   //start servo to feed the fish
            out.printf("Feeding");
            s.printf("Feed");
            break;
        case 1:    //turn lights on
            out.printf("Lights on");
            s.printf("ON");

            break;
        case 2:    //turn lights off
            out.printf("Lights off");
            s.printf("OFF");

            break;
        case 3:    //turn Dancing led strip on
            out.printf("Led Flashing");
            s.printf("Dance");

            break;
        case 4:    //turn Dancing led strip off
            out.printf("Led Not Flashing");
            s.printf("NoDance");

            break;

    }
}

void baud(int baudrate)
{

    s.baud(baudrate);
}




int main(void)
{

    char* topic1 = "******/feeds/welcome-feed";       //******  type your username on IFTT instead of the stars 


    printf("starting...\n");


    MQTTEthernet ipstack = MQTTEthernet();

    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);

    char* hostname = "io.adafruit.com";//your MQTT broker host
    int port = 1883; // broker port number

    int rc = ipstack.connect(hostname, port);

    out.printf("rc from TCP connect is %d\n", rc);

    if (rc != 0)
        out.printf("rc from TCP connect is %d\n", rc);

    char MQTTClientID[30];
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.MQTTVersion = 3;
    sprintf(MQTTClientID,"WIZwiki-%d",rand()%1000);

    data.clientID.cstring = MQTTClientID;
    data.username.cstring = "*******";   //******  type your username on IFTT instead of the stars
    data.password.cstring = "************************";   //******  type your Password on IFTT instead of the stars
    if ((rc = client.connect(data)) != 0)
        printf("rc from MQTT connect is %d\n", rc);


    if ((rc = client.subscribe(topic1, MQTT::QOS0, messageArrived)) != 0) {
        out.printf("rc from MQTT subscribe is %d\n", rc);


    }

    while (true) {



        client.yield(6);

    }
}

Adruino Code

C/C++
Adruino Code to control lights , led strip and servo motor
#include <SoftwareSerial.h>
#include <Servo.h>

Servo myservo;
int pos = 0;

SoftwareSerial mySerial(8, 9); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  myservo.attach(A5); //analog pin 0
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Welcome to Aquaruim Assistant");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  // mySerial.println("Hello, world?");

  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

}

void loop() { // run over and over
  if (mySerial.available()) {
    String res = mySerial.readString();
    if (res == "Feed") {
      Serial.println("Feeding ur fish NOW");
      rotateServo(3);
    }
    else if (res == "ON") {
      Serial.println("Lights ON");
      //realy 1 on
      digitalWrite(10, LOW);   // turn the Relay on
      delay(1000);                       // wait for a second

    }
    else if (res == "OFF") {
      Serial.println("Lights OFF");
      //realy 1 off
      digitalWrite(10, HIGH);   // turn the Relay on 
      delay(1000);                       // wait for a second

    }
    else if (res == "Dance") {
      Serial.println("Dancing Lights ON");
      //realy 2 on
      digitalWrite(11, LOW);   // turn the Relay on 
      delay(1000);                       // wait for a second

    }
    else if (res == "NoDance") {
      Serial.println("Dancing lights OFF");
      //realy 2 off
      digitalWrite(11, HIGH);   // turn the Relay on 
      delay(1000);                       // wait for a second

    }

  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

void rotateServo(int rotations) {
  for (int i = 0; i < rotations; i++) {
    for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
  }
}

Credits

Fady Tarek

Fady Tarek

5 projects • 17 followers

Comments