Netchaieff Alexandre
Created March 28, 2016

Automated Fish Tank

An autonomous fish tank including : - Heat - Light - fish food - water cleaning - water oxygenation

IntermediateWork in progress12 hours126
Automated Fish Tank

Things used in this project

Hardware components

peristaltic pump
×1
Arduino Pro Mini 328 - 3.3V/8MHz
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1
Microsoft Windows Virtual Shields for Arduino
×1
Microsoft Azure IoT Suite
×1
Microsoft Azure IoT Hub
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
hot air soldering station
wire

Story

Read more

Schematics

Schematic Rotary encoder

Code

Interface

C/C++
Encodeur Rotatif et fading Led
/*
Encodeur rotatif et Fading LED
*/

int led1 = 8;
int led2 = 9;
int led3 = A0;
int led4 = 10;
int led5 = 11;
int led6 = 12;
int led7 = 13;
int encoderA = 4;
int encoderB = 5;

int crans = 1;
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int nb = 0;
int n = LOW;
int encoder0PinALast = LOW;
int encoder0Pos = 0;
int oldnb = 0;

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin (9600);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode (encoderA, INPUT_PULLUP);
  pinMode (encoderB, INPUT_PULLUP);
}

// the loop routine runs over and over again forever:
void loop() {

  n = digitalRead(encoderA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoderB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
  }
  encoder0PinALast = n;

  if (encoder0Pos > (7 * crans))
  {
    encoder0Pos = (7 * crans);
  }

  if (encoder0Pos < 0)
  {
    encoder0Pos = 0;
  }
  nb = encoder0Pos / crans;

  Serial.print(encoder0Pos);

  Serial.print ("-");

  Serial.print (nb);

  // set the brightness of pin 9:
  //  analogWrite(led1, brightness);
  //  analogWrite(led2, brightness);
  //  analogWrite(led3, brightness);
  //  analogWrite(led4, brightness);
  //  analogWrite(led5, brightness);
  //  analogWrite(led6, brightness);
  //  analogWrite(led7, brightness);

  Serial.print ("=");

  Serial.print(oldnb);

  Serial.print ("-");

  Serial.println (nb);

  
  if (oldnb < nb)
  {
    fadein(nb);
    oldnb = nb;
  }

  if (oldnb > nb)
  {
    fadeout(oldnb);
    oldnb = nb;
  }
  
  // change the brightness for next time through the loop:
  // brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
//  if (brightness == 0 || brightness == 255) {
//    fadeAmount = -fadeAmount ;
//  }
  // wait for 30 milliseconds to see the dimming effect
  // delay(30);
}

void fadein(int nb)
{
  int brightness = 0;
  while (brightness < 256)
  {

      if (nb == 1) {
      digitalWrite(led1, 0);
    }
    if (nb == 2) {
      digitalWrite(led2, 0);
    }
    if (nb == 3) {
      digitalWrite(led3, 0);
    }
    if (nb == 4) {
      digitalWrite(led4, 0);
    }
    if (nb == 5) {
      digitalWrite(led5, 0);
    }
    if (nb == 6) {
      digitalWrite(led6, 0);
    }
    if (nb == 7) {
      digitalWrite(led7, 0);
    }


    delay(16 - brightness / 16);
    
    if (nb == 1) {
      digitalWrite(led1, 1);
    }
    if (nb == 2) {
      digitalWrite(led2, 1);
    }
    if (nb == 3) {
      digitalWrite(led3, 1);
    }
    if (nb == 4) {
      digitalWrite(led4, 1);
    }
    if (nb == 5) {
      digitalWrite(led5, 1);
    }
    if (nb == 6) {
      digitalWrite(led6, 1);
    }
    if (nb == 7) {
      digitalWrite(led7, 1);
    }

    delay(brightness / 16);



  
    brightness = brightness + fadeAmount;

  }

}

void fadeout(int nb)
{
  int brightness = 255;
  while (brightness > 0)
  {

    
    if (nb == 1) {
      digitalWrite(led1, 1);
    }
    if (nb == 2) {
      digitalWrite(led2, 1);
    }
    if (nb == 3) {
      digitalWrite(led3, 1);
    }
    if (nb == 4) {
      digitalWrite(led4, 1);
    }
    if (nb == 5) {
      digitalWrite(led5, 1);
    }
    if (nb == 6) {
      digitalWrite(led6, 1);
    }
    if (nb == 7) {
      digitalWrite(led7, 1);
    }

    delay(brightness / 16);



      if (nb == 1) {
      digitalWrite(led1, 0);
    }
    if (nb == 2) {
      digitalWrite(led2, 0);
    }
    if (nb == 3) {
      digitalWrite(led3, 0);
    }
    if (nb == 4) {
      digitalWrite(led4, 0);
    }
    if (nb == 5) {
      digitalWrite(led5, 0);
    }
    if (nb == 6) {
      digitalWrite(led6, 0);
    }
    if (nb == 7) {
      digitalWrite(led7, 0);
    }


    delay(16 - brightness / 16);
  
    brightness = brightness - fadeAmount;

  }

}

Credits

Netchaieff Alexandre

Netchaieff Alexandre

1 project • 0 followers
Electronics engineer

Comments