Tuesday, May 20, 2014

Helping with other projects - 16/05

I'm helping Nut with his project. We are cleaning and modifying old computers. We are planning to install a new OS, probably it will be Linux.

Project news - 05/15

I'm steel waiting for pump for my project. I started helping other guys with their projects.

Sunday, May 11, 2014

Arduino Project - Pump logic

Hello everyone, today I'm going to tell you how I'm going to realise pump work in my project. After selecting an option on LCD Arduino Screen it will measure an amount of water in earth and if earth is dry it will water a plant.

Wednesday, April 30, 2014

Arduino RELAY

Also I got an Arduino relay module. I'll need it for switching different modules in my program, which will activate something.

Arduino LCD board

Hello everyone! I got an LCD board for my Arduino! It is very simple to use it, because they have their own library for working with LCD board.

Arduino relay code

OK, I'm publishing Arduino code, which allows you to control relay:
#define RELAY1  0                      
#define RELAY2  1                    
#define RELAY3  2                        
#define RELAY4  3

void setup()
{    
// Initialise the Arduino data pins for OUTPUT
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
}

void loop()
{
   digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY1,HIGH);          // Turns Relay Off

   digitalWrite(RELAY2,LOW);           // Turns ON Relays 2
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY2,HIGH);          // Turns Relay Off

   digitalWrite(RELAY3,LOW);           // Turns ON Relays 3
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY3,HIGH);          // Turns Relay Off

   digitalWrite(RELAY4,LOW);           // Turns ON Relays 4
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY4,HIGH);          // Turns Relay Off        

 }

Arduino LCD Menu code

As I promised, I'm publishing my LCD screen menu code for Arduino.

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// Main menu array
String mainMenu[10]; 
// Main menu default choice
int mainSwitch = 0;  
// Amount of items in our main menu.
// Can be found by formula:
// (Amount_of_items - 1)
#define mainMenuItems 2

// Water menu array
String waterMenu[10];
// Water menu default choice
int waterSwitch = 0;
#define waterMenuItems 1

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);

 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 195)  return btnUP; 
 if (adc_key_in < 380)  return btnDOWN; 
 if (adc_key_in < 555)  return btnLEFT; 
 if (adc_key_in < 790)  return btnSELECT;   

 return btnNONE;  // when all others fail, return this...
}

void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Main menu:     "); // print a simple message

 // Filling our main menu items
 mainMenu[0] = "Light           ";
 mainMenu[1] = "Water           ";
 mainMenu[2] = "Stop            ";

 // Filling our water menu items
 waterMenu[0] = "item1          ";
 waterMenu[1] = "item2          ";

 lcd.setCursor(0,1);
 lcd.print(mainMenu[0]);
}

void cleanScreen()
{
  lcd.setCursor(0,0);
  lcd.print("                "); 
  lcd.setCursor(0,1);
  lcd.print("                ");
}

void light()
{
  lcd.setCursor(0,0);
  lcd.print(mainMenu[0]); // print a simple message
  lcd.setCursor(0,1);
  
  // Loop for reading buttons
  while(true)
  {
    lcd_key = read_LCD_buttons();
    
    switch (lcd_key)
    {
       case btnRIGHT:
       {
         break;
       }
       // back to main menu on the left button press
       case btnLEFT:
       {
         goto exit;
         break;
       }
    }
  }
  
  exit:
  lcd.setCursor(0,0);
  lcd.print("Main menu:     ");
  lcd.setCursor(0,1);
  lcd.print(mainMenu[0]);
  return;
}

void water()
{
  lcd.setCursor(0,0);
  lcd.print(mainMenu[1]);
  lcd.setCursor(0,1);
  
  while(true)
  {
    lcd_key = read_LCD_buttons();
    
    switch (lcd_key)
    {
       case btnRIGHT:
       {
         break;
       }
       // back to main menu on the left button press
       case btnLEFT:
       {
         goto exit;
         break;
       }
    }
  }
  
  exit:
  lcd.setCursor(0,0);
  lcd.print("Main menu:     "); // print a simple message
  lcd.setCursor(0,1);
  lcd.print(mainMenu[1]);
  return;
}

void aStop()
{
  lcd.setCursor(0,0);
  lcd.print(mainMenu[2]);
  lcd.setCursor(0,1);
  
  while(true)
  {
    lcd_key = read_LCD_buttons();
    
    switch (lcd_key)
    {
       case btnRIGHT:
       {
         break;
       }
       // back to main menu on the left button press
       case btnLEFT:
       {
         goto exit;
         break;
       }
    }
  }
  
  exit:
  lcd.setCursor(0,0);
  lcd.print("Main menu:     ");
  lcd.setCursor(0,1);
  lcd.print(mainMenu[2]);
  return;
}

// Main loop
void loop()
{  
  // move to the begining of the second line
  lcd.setCursor(0,1); 
  lcd_key = read_LCD_buttons();  // read the buttons

 // depending on which button was pushed, 
 // we perform an action
 switch (lcd_key)
 {
   // Enter a sub menu on Right button press
   case btnRIGHT:
     {
       cleanScreen();
       
       if(mainSwitch == 0)
       {
         light();
       }
       else if(mainSwitch == 1)
       {
         water();
       }
       else if(mainSwitch == 2)
       {
         aStop();
       }
       break;
     }

   // Move to the next sub menu (UP)
   case btnUP:
     {
       if(mainSwitch == 0)
       {
         mainSwitch = mainMenuItems; 
       }
       else
       {
         mainSwitch = mainSwitch - 1;
       }
       
       lcd.print(mainMenu[mainSwitch]);
       delay(300);
       
       break;
     }

   // Move to the next sub menu (DOWN)
   case btnDOWN:
     {
       if(mainSwitch > mainMenuItems - 1)
       {
         mainSwitch = 0; 
       }
       else
       {
         mainSwitch = mainSwitch + 1;
       }
       
       lcd.print(mainMenu[mainSwitch]);
       delay(300);
       
       break;
     }
 }

}