akashsurvase
Published

Charge Mobile Using Timer

To charge mobile battery with in specified amount of time by setting timer.

IntermediateWork in progress69
Charge Mobile Using Timer

Things used in this project

Hardware components

RGB LCD Shield Kit, 16x2 Character Display
RGB LCD Shield Kit, 16x2 Character Display
×1
Relay (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
5V 2.5A Switching Power Supply
Digilent 5V 2.5A Switching Power Supply
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Story

Read more

Schematics

circuit diagram

Code

code

Arduino
#include <LiquidCrystal.h>
#include<EEPROM.h>
 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 int a=0,b=0;
 void timer();
 void checked();
 int S;
 int check;
 int value;
int M; 
int H; 
int pin=3;
int valueM;
int valueS;
int valueH;
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

int read_LCD_buttons()
{
 adc_key_in = analogRead(0);     
 value=adc_key_in;
 EEPROM.update(0,value);

 if (adc_key_in > 1500) return btnNONE; 
 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 < 500)  return btnLEFT; 
 if (adc_key_in < 700)  return btnSELECT;   
 return btnNONE; 
}
 
void setup()
{
 lcd.begin(16, 2);            
 pinMode(pin,OUTPUT);
 digitalWrite(pin,check);
 Serial.begin(9600);
 checked();
}
  
void loop()
{
 
  lcd.setCursor(1,0);
      lcd.print ("Set the timer");
 lcd.setCursor(0,1);            
 lcd_key = read_LCD_buttons(); 

 switch (lcd_key)              
 {
   case btnUP:  //for minute increment
     {
      
      lcd.setCursor(1,0);
      lcd.print ("Set the timer");
      lcd.setCursor(6,1);
      lcd.print(":");
      lcd.setCursor(9,1);
      lcd.print(":");
if(b<4)
{
           
            if(a>9){
              if(a<=59){
                 lcd.setCursor(7,1);
                  lcd.print(a);
                  a++;
                  Serial.println(a);
                    if(a==60){
                      a=0;
                             }
                  }
       }
             else{
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(a);
 a++;
 Serial.println(a);
 
             }

        
delay(500);
}
else
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("timer is limited");
   lcd.setCursor(2,1);
      lcd.print("for 3 hours");
  delay(2000);
  lcd.clear();
  a=0;
  b=0;
 
}
     break;
     }

 
   case btnLEFT:   //for hours 
    {
      lcd.setCursor(1,0);
      lcd.print ("Set the timer");
      lcd.setCursor(6,1);
      lcd.print(":");
      lcd.setCursor(9,1);
      lcd.print(":");

           
            if(b<4){
             
                 lcd.setCursor(4,1);
                 lcd.print("0"); 
                  lcd.setCursor(5,1);
                  lcd.print(b);
                   b++;
                  }
       
             else{
 
lcd.clear();
lcd.setCursor(0,0);
lcd.print("timer is limited");
 lcd.setCursor(2,1);
      lcd.print("for 3 hours");
delay(2000);
lcd.clear();
lcd.setCursor(1,0);
      lcd.print ("Set the timer");
      lcd.setCursor(6,1);
      lcd.print(":");
      lcd.setCursor(9,1);
      lcd.print(":");
 b=0;
             }
        
delay(500);
     break;
     }
  case btnSELECT:       // statring the timer
     {
     if(b==4  && (a>0 && a<59))
      {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("timer is limited");
      lcd.setCursor(2,1);
      lcd.print("for 3 hours");
      delay(2000);
      lcd.clear();
      a=0;
      b=0;
      }
      else{
      timer();
      }
  
     break;
     }
    
 }
 }


//timer code

 void timer(){
   int S=59;
   
 lcd.clear();
   M=a-2;
   H=b-1;
   
  while(1){
  EEPROM.write(104,M);
 valueM=EEPROM.read(104);
 EEPROM.update(1,valueM);
 Serial.print(valueM);
  EEPROM.write(103,S);
 valueS=EEPROM.read(103);
 EEPROM.update(0,valueS);
 Serial.print(valueS);
  EEPROM.write(105,H);
 valueH=EEPROM.read(105);
 Serial.print(valueH);
 EEPROM.update(3,H);
   lcd.setCursor(3,0); 
 lcd.print ("timer set");
 lcd.setCursor(12,0);
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(9,1);
 lcd.print(":");
 S--;
 delay(1000);
  int y= analogRead(0);     ///used for reset button
  if(y<700){
    digitalWrite(pin,LOW);

   EEPROM.write(S,0);
    EEPROM.write(M,0);
     EEPROM.write(H,0);
       lcd.setCursor(3,0); 
 lcd.print ("timer set");
 lcd.setCursor(12,0);
 lcd.setCursor(4,1);
 lcd.print("  ");
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(7,1);
 lcd.print("  ");
 lcd.setCursor(9,1);
 lcd.print(":");
  lcd.setCursor(10,1);
 lcd.print("  ");
    return loop();
  }
  
 digitalWrite(pin,check);
  EEPROM.update(1,check);


   digitalWrite(pin,HIGH);
 if(S<0)
 {
 M--;
 S=59;
 
 }
 if(M<0)
 {
 H--;
 M=59;
  
 }
 if(H<0)
 {
 H=23;
 M=59;
 S=59;
 digitalWrite(pin,check);
 EEPROM.update(0,check);
 lcd.clear();
 lcd.setCursor(2,1);
 lcd.print("timer is end");
   EEPROM.write(S,0);
    EEPROM.write(M,0);
     EEPROM.write(H,0);
       lcd.setCursor(3,0);
 delay(1000);
 lcd.clear();
  exit(0);
 }
 if(M>9)
 {
 lcd.setCursor(7,1);
 lcd.print(M);
 }
 else
 {
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(M);
 lcd.setCursor(9,1);
 lcd.print(":");
 }
  
 if(S>9)
 {
 lcd.setCursor(10,1);
 lcd.print(S);
 }
 else
 {
 lcd.setCursor(10,1);
 lcd.print("0"); 
 lcd.setCursor(11,1);
 lcd.print(S);
 lcd.setCursor(12,1);
 lcd.print(" ");
 }
 if(H>9)
 {
 lcd.setCursor(4,1);
 lcd.print (H);
 }
 else
 {
 lcd.setCursor(4,1);
 lcd.print("0"); 
 lcd.setCursor(5,1);
 lcd.print(H);
 lcd.setCursor(6,1);
 lcd.print(":");
 }
 }
  }
 
                                                 ///checked
  void checked()
  {
 if(check==0)
 {
    lcd.clear();

valueS=EEPROM.read(103);
Serial.print(valueS);

  valueM=EEPROM.read(104);
 Serial.print(valueM);

valueH=EEPROM.read(105);
 Serial.print(valueH);


  
  S=valueS;
   M=valueM;
   H=valueH;
   
  while(1){
   
 EEPROM.write(104,M);
 valueM=EEPROM.read(104);
 EEPROM.update(1,valueM);
 Serial.print(valueM);
  EEPROM.write(103,S);
 valueS=EEPROM.read(103);
 EEPROM.update(0,valueS);
 Serial.print(valueS);
  EEPROM.write(105,H);
 valueH=EEPROM.read(105);
 Serial.print(valueH);
 EEPROM.update(3,H);
 lcd.setCursor(3,0); 
 lcd.print ("timer set");
 lcd.setCursor(12,0);
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(9,1);
 lcd.print(":");

 
 S--;
 delay(1000);
  int x= analogRead(0); 
 if(x<700)
 {
  digitalWrite(pin,LOW);

 EEPROM.write(S,0);
    EEPROM.write(M,0);
     EEPROM.write(H,0);
       lcd.setCursor(3,0);

 lcd.setCursor(3,0); 
 lcd.print ("timer set");
 lcd.setCursor(12,0);
 lcd.setCursor(4,1);
 lcd.print("  ");
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(7,1);
 lcd.print("  ");
 lcd.setCursor(9,1);
 lcd.print(":");
  lcd.setCursor(10,1);
 lcd.print("  ");
  return loop();
  
 }
 digitalWrite(pin,HIGH);


 if(S<0)
 {
 M--;
 S=59;
 
 }
 if(M<0)
 {
 H--;
 M=59;
  
 }
 if(H<0)
 {
 H=23;
 M=59;
 S=59;
 digitalWrite(pin,LOW);

 lcd.clear();
 lcd.setCursor(2,1);
 lcd.print("timer is end");
 delay(1000);
   EEPROM.write(S,0);
    EEPROM.write(M,0);
     EEPROM.write(H,0);
       lcd.setCursor(3,0);
 lcd.clear();
 return loop();
 }
 if(M>9)
 {
 lcd.setCursor(7,1);
 lcd.print(M);
 }
 else
 {
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(M);
 lcd.setCursor(9,1);
 lcd.print(":");
 }
  
 if(S>9)
 {
 lcd.setCursor(10,1);
 lcd.print(S);
 }
 else
 {
 lcd.setCursor(10,1);
 lcd.print("0"); 
 lcd.setCursor(11,1);
 lcd.print(S);
 lcd.setCursor(12,1);
 lcd.print(" ");
 }
 if(H>9)
 {
 lcd.setCursor(4,1);
 lcd.print (H);
 }
 else
 {
 lcd.setCursor(4,1);
 lcd.print("0"); 
 lcd.setCursor(5,1);
 lcd.print(H);
 lcd.setCursor(6,1);
 lcd.print(":");
 }
 }
  }
  else if(check==1)
  {
    Serial.print("OFF");
    return loop();
    
  }
  

  }

Credits

akashsurvase

akashsurvase

2 projects • 0 followers

Comments

Add projectSign up / Login