Bem-vindo ao Projeto TOFFEE :: O Canal Linux

The Linux Channel an Youtube Linux channel for advance Linux users, systems and network software programmers and tech enthusiasts. The Linux Channel is a part of The TOFFEE Project research.


/* The Linux Channel
 * Code for Video Episode: 0x1eb Arduino UNO - RO Water Purifier Controller
 * Author: Kiran Kankipati
 * Updated: 03-Mar-2020
 * Version: 02
 */

//before writing to Arduino, do:
//sudo chmod 777 /dev/ttyACM0

//Debug/Test
//unsigned long SECOND = 10;

unsigned long HALFSECOND = 500;
unsigned long SECOND = 1000;

unsigned long MIN = SECOND*60;
int PIN8_SW1_ROFILTER = 8;
int PIN4_SW4_BELL = 4;
int PIN2_SW3_HEATER = 2;
int RELAY_ON=LOW;
int RELAY_OFF=HIGH;

int cycle=0;

void setup() 
{
  pinMode(PIN8_SW1_ROFILTER, OUTPUT);
  pinMode(PIN4_SW4_BELL, OUTPUT);
  pinMode(PIN2_SW3_HEATER, OUTPUT);
}


void loop() 
{ 

  digitalWrite(PIN8_SW1_ROFILTER, RELAY_OFF);
  digitalWrite(PIN4_SW4_BELL, RELAY_OFF);
  digitalWrite(PIN2_SW3_HEATER, RELAY_OFF);

  if(cycle==0)
  {   digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
      digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
          
      //RO Filter Cycle
      for(int i = 0; i < 8; i++) 
      { if(i<=6)
        {
          digitalWrite(PIN8_SW1_ROFILTER, RELAY_ON); delay(MIN*10);
          digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
        }
        else if(i==7)
        {
          digitalWrite(PIN8_SW1_ROFILTER, RELAY_OFF);
          digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
          digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
          digitalWrite(PIN4_SW4_BELL, RELAY_ON); delay(HALFSECOND); digitalWrite(PIN4_SW4_BELL, RELAY_OFF); delay(HALFSECOND);
        }
      }
      digitalWrite(PIN8_SW1_ROFILTER, RELAY_OFF);
  } 
  else 
  { delay(MIN*1000); } //long indefinite wait
  
  cycle++;  


}

NOTE: I have modified, and removed that calling bell with a tiny low-voltage Active buzzer which can work as it is with Arduino output pins without relay. And as well modified the code accordingly and refined existing code and fixed couple of bugs. I did my first field-test, seems to be working fine. I have to do couple of more times and see.
Here is my updated code:

/* The Linux Channel
 * Code for Video Episode: 0x1eb Arduino UNO - RO Water Purifier Controller
 * Author: Kiran Kankipati
 * Updated: 05-Mar-2020
 * Version: 03
 */



//before writing to Arduino, do:
//sudo chmod 777 /dev/ttyACM0

//Debug/Test
//unsigned long _SECOND = 8;

unsigned long HALFSECOND = 500;
unsigned long SECOND2 = 2000;
unsigned long SECOND = 1000;
unsigned long _SECOND = 1000;

unsigned long MIN = _SECOND*56; //adjusted for buzzer
int PIN8_SW1_ROFILTER = 8;
int PIN13_BUZZER = 13;
int PIN4_SW4_BELL = 4;
int PIN2_SW3_HEATER = 2;
int RELAY_ON=LOW;
int RELAY_OFF=HIGH;

int cycle=0;

void setup() 
{
  pinMode(PIN8_SW1_ROFILTER, OUTPUT);
  pinMode(PIN4_SW4_BELL, OUTPUT);
  pinMode(PIN2_SW3_HEATER, OUTPUT);
  pinMode(PIN13_BUZZER, OUTPUT);
}

void _buzzer_sequence(int count)
{
  for(int i=0; i < count;i++)
  {
    digitalWrite(PIN13_BUZZER, HIGH); delay(SECOND); digitalWrite(PIN13_BUZZER, LOW); delay(SECOND);
  }
}

void _end_buzzer_sequence()
{
  digitalWrite(PIN13_BUZZER, HIGH); delay(SECOND*5); digitalWrite(PIN13_BUZZER, LOW);
}

void loop() 
{ 
  
  digitalWrite(PIN8_SW1_ROFILTER, RELAY_OFF);
  digitalWrite(PIN4_SW4_BELL, RELAY_OFF);
  digitalWrite(PIN2_SW3_HEATER, RELAY_OFF);
  //digitalWrite(PIN1_BUZZER, LOW);
  delay(SECOND2);
  
  if(cycle==0)
  {   _buzzer_sequence(3);
          
      //RO Filter Cycle
      for(int i = 1; i <=7; i++) 
      { if(i<=7)
        {
          digitalWrite(PIN8_SW1_ROFILTER, RELAY_ON); delay(MIN*10);
          _buzzer_sequence(i);
        }
      }
      digitalWrite(PIN8_SW1_ROFILTER, RELAY_OFF);
      _end_buzzer_sequence();
  } 
  else 
  { delay(MIN*1000); } //long indefinite wait
  
  cycle++;  


}

Featured Video:



Suggested Topics:


Network Software Development:


Research and Projects:


Linux (user-space), Systems Architecture:


Linux Kernel Software Development:


Linux Kernel Internals (PDFs) - by Ramin Farajpour:


Software Development (Programming) Tools:


Embedded Projects:

Join The Linux Channel :: Facebook Group


Join a course:

💎 Linux, Kernel, Networking and Device Drivers: PDF Brochure
💎 PhD or equivalent (or Post Doctoral) looking for assistance: Details
💎 ... or unlimited life-time mentorship: Details


💗 Help shape the future: Sponsor/Donate


Tópicos recomendados:
Featured Video:


Trending Video:

Linux ioctl() API interface:



Recommended Video: