Talal Ashraf Khokhar
Published © GPL3+

Aquarium Automation

The goal of this project is to build an aquarium’s device that is connected to a GSM so that we can control & monitor it through SMS.

IntermediateShowcase (no instructions)21 days18,179
Aquarium Automation

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Arduino UNO
×1
SmartThings Shield for Arduino
SmartThings Shield for Arduino
SIM900 GSM/GPRS Shield
×1
Jumper wires (generic)
Jumper wires (generic)
Jumpers for Arduino (Male-Male & Male-Female)
×1
Temperature Sensor
Texas Instruments Temperature Sensor
Underwater Temperature Sensor DALLAS DS18B20
×1
Water Heater
×1
Breadboard (generic)
Breadboard (generic)
×1
Solid State Relay
Solid State Relay
2 Relays used
×1
Oxygen Pump for Aquarium
×1
DC motor (generic)
5V DC Stepper Motor with Driver ULN2003
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
5V-1A & 12V=2A DC Power Adapters
×1
LED (generic)
LED (generic)
Lighting components are used in which many LEDs are used.
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Pin Map of Arduino

Pin Mapping of Arduino UNO used in this project

Relay Circuit

Schematic of Relay circuit used for control and switch AC appliances like Heater & Oxygen Pump

Block Diagram of the Project

This block diagram shows complete operations take place in this project.

Schematic of SIM900 GSM/GPRS Sheid

Schematic of SIM900 GSM/GPRS Sheid

Code

Aquarium Automation Program

Arduino
It is fine & working.
#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
#include <OneWire.h>
SoftwareSerial SIM900(7, 8);
OneWire  ds(2);  // on pin 2 (a 4.7K resistor is necessary)

int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;

void setup()
{
  Serial.begin(19200);
  // set up the digital pins to control
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  
  SIM900.begin(19200);
  SIM900power();  
  delay(20000);  // give time to log on to network. 
  
  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
  Serial.println("Ready...");
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}
 
void sendSMS()
{
  SIM900.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+923032810399\"");                                     // recipient's mobile number, in international format
  delay(100);
  SIM900.println(" The Aquarium Automation is ON now. Thanks to Talal Khokhar, Usama Bin Najam & Ghulam Rasool.");        // message to send
  delay(100);
  SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(100); 
  SIM900.println();
  delay(5000);                                     // give module time to send SMS
  SIM900power();                                   // turn off module
}

 
void loop()
{

  //If a character comes in from the cellular module...
  if(SIM900.available() >0)
  {
    inchar=SIM900.read(); 
    if (inchar=='#')
    {
      delay(10);

      inchar=SIM900.read(); 
      if (inchar=='a')
      {
        delay(10);
        inchar=SIM900.read();
        if (inchar=='0')
        {
          digitalWrite(led1, LOW);
        } 
        else if (inchar=='1')
        {
          digitalWrite(led1, HIGH);
        }
        delay(10);
        inchar=SIM900.read(); 
        if (inchar=='b')
        {
          inchar=SIM900.read();
          if (inchar=='0')
          {
            digitalWrite(led2, LOW);
          } 
          else if (inchar=='1')
          {
            digitalWrite(led2, HIGH);
          }
          delay(10);
          inchar=SIM900.read(); 
          if (inchar=='c')
          {
            inchar=SIM900.read();
            if (inchar=='0')
            {
              digitalWrite(led3, LOW);
            } 
            else if (inchar=='1')
            {
              digitalWrite(led3, HIGH);
            }
            delay(10);
            inchar=SIM900.read(); 
            if (inchar=='d')
            {
              delay(10);
              inchar=SIM900.read();
              if (inchar=='0')
              {
                digitalWrite(led4, LOW);
              } 
              else if (inchar=='1')
              {
                digitalWrite(led4, HIGH);
              }
              delay(10);
            }
          }
          SIM900.println("AT+CMGD=1,4"); // delete all SMS
        }
      }
    }
  }
  
 
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
   if ( !ds.search(addr)) {
  SIM900.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+923032810399\"");                                     // recipient's mobile number, in international format
  delay(100);
  SIM900.println(" Thank You ");        // message to send
  delay(100);
  SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(100); 
  SIM900.println();
  delay(5000);                                     // give module time to send SMS
  SIM900power();    // turn off module
  
   ds.reset_search();
    delay(10000);
    return;
}
  switch (addr[0]) {
    case 0x28:
      SIM900.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+923032810399\"");                                     // recipient's mobile number, in international format
  delay(100);
  SIM900.println(" The Water Temperature Report by TALAL, USAMA, GHULAM");        // message to send
  delay(100);
  SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(100); 
  SIM900.println();
  delay(5000);                                     // give module time to send SMS
  SIM900power();    // turn off mod
      type_s = 0;
      break;
       return;
  }
ds.reset();
  ds.select(addr);
  ds.write(0x44);        // start conversion, use ds.write(0x44,1) with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

 
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();   
  }
   int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  
 SIM900.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+923032810399\"");                                     // recipient's mobile number, in international format
  delay(100);
  SIM900.println(" Temp= ");  // message to send
  SIM900.println(celsius);
   SIM900.println(" Cel, ");  // message to send
  SIM900.println(fahrenheit);
  SIM900.println(" Fah");
  delay(100);
  SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(100); 
  SIM900.println();
  delay(10000);                                     // give module time to send SMS
  SIM900power();   
  
 }

Credits

Talal Ashraf Khokhar

Talal Ashraf Khokhar

1 project • 11 followers
An Engineer, Researcher of 5G Technology, Maker of SMART AQUARIUM.

Comments