Blogger Themes

Search This Blog

www.embeddedstudy.com | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Popular KOZHI

Sponsor

Download

Blogger Tricks

FEATURED

What is an Embedded System?

An embedded system is a combination of hardware and software that is designed to carry out a certain task or tasks, meaning it has a s...

JOIN THE TEAM

Popular Posts

Wikipedia

Search results

Search This Blog

Social

More Links

Social

ad

ads

Featured Posts

Monday, 9 October 2017

Mind Magic Game in Arduino - Birthday Finder

- No comments
Hello Everyone....
In this Project i am going to show you ,How to make a simple magic game on Arduino(Nano or UNO).You can trick your friends using this project and be a star in front of them.



















Watch the video:


I have described in detail about the working of this project in this video
Watch it...

The Components Required:


​For doing this Project You essentially need components like
1 >> Arduino NANO or UNO.
2 >> HD44780 16x2 character LCD.
3 >>  4x4 keypad matrix.
4 >> Breadboard and jumper wires.











Arduino NANO-The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328; offers the same connectivity and specs of the UNO board in a smaller form factor.
The Arduino Nano is programmed using the Arduino Software (IDE), our Integrated Development Environment common to all our boards and running both online and offline.
HD44780 16x2 character LCD-The Hitachi HD44780 LCD controller is an alphanumeric dot matrix liquid crystal display (LCD) controller developed by Hitachi that was commonly used during the MCS-51 era. It was made commercially available around year 1987.The character set of the controller includes ASCII characters, Japanese Kana characters, and some symbols in two 28 character lines. Using an extension driver, the device can display up to 80 characters.
4x4 keypad matrix - 
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},   
  {'*','0','#','D'}   };
The pattern of key pad is as shown above.

The Connection Diagram:



The Code:

Or copy the code below:
/*

   Demonstrates the use a 16x2 LCD display and
  4x4 LCD display.  T

   The  Arduino circuit connection for LCD:

   * LCD RS  pin to analog pin A0

   * LCD  Enable pin to analog pin A1

   * LCD D4  pin to analog pin A2

   * LCD D5  pin to analog pin A3

   * LCD D6  pin to analog pin A4

   * LCD D7  pin to analog pin A5

   The  Arduino circuit connection for MAtrix Key Pad:

   * ROW1 pin  to digital pin 5

   * ROW2 pin  to digital pin 4

   * ROW3 pin  to digital pin 3

   * ROW4 pin  to digital pin 2

   * COLUMN1  pin to digital pin 6

   * COLUMN2  pin to digital pin 7

   * COLUMN3  pin to digital pin 8

   * COLUMN4  pin to digital pin 9

   */
   char month[12][10]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
   int stc=0,num1,age,mnt;
char str[10];
  // include the library code:
#include <Keypad.h>
#include <LiquidCrystal.h>
  LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
  const byte ROWS = 4; // Four rows
  const byte COLS = 4; // Four columns
  char keys[ROWS][COLS] = 
  { 
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
  };
  // Connect keypad ROW0, ROW1, ROW2 and ROW3 to
  byte rowPins[ROWS] = { 5, 4, 3, 2 };
  // Connect keypad COL0, COL1, COL2 and COL3 to
  byte colPins[COLS] = { 6, 7, 8, 9 }; 
 byte heart[8] = {
   0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

byte heart1[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00100,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte heart2[8] = {
  0b00000,
  0b00000,
  0b00100,
  0b01110,
  0b00100,
  0b00000,
  0b00000,
  0b00000
};
byte heart3[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
  0b00000
};
byte heart4[8] = {
  0b00000,
  0b00000,
  0b01110,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};



  Keypad kpd = Keypad( makeKeymap(keys), rowPins,
  colPins, ROWS, COLS );

  void setup() 
  {
  lcd.begin(16, 2);
  lcd.createChar(0, heart1);
   lcd.createChar(1, heart2);
   lcd.createChar(2, heart3);
   lcd.createChar(3, heart4);
   lcd.createChar(4, heart);
  }


  void loop() 
  {
    char key= kpd.getKey();
   lcd.setCursor(0, 0);
   rst:
    lcd.print("MAGIC GAME!!!");
  lcd.setCursor(0, 1);
  lcd.print("PRESS * TO BEGIN");
  
if(key=='*')  
  { 
  here:
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("THINK A MONTH NO");
  lcd.setCursor(0, 1);
  lcd.print("jan:1,feb:2...");
  delay(5000);
  lcd.clear();
      while(1)
          {
            lcd.setCursor(0, 0);
            lcd.print("Think 1 age also");
            lcd.setCursor(0, 1);
            lcd.print("now press #");
            char key= kpd.getKey();
            if(key=='#')  
               { 
                bere:
                lcd.clear();
                lcd.print("now do some math");
                lcd.setCursor(0, 1);
                lcd.print("((num*2)+5)*50");
                delay(8000);
                lcd.clear();
                  while(1)
                  {
                  lcd.setCursor(0, 0);
                  lcd.print("add reslt to age");
                   lcd.setCursor(0, 1);
                  lcd.print("and press #");
                  char key= kpd.getKey();
                     if(key=='#')
                      {
                        jere:
                        lcd.clear();
                        while(1)
                        {
                          
                         static int num=0;
                          lcd.setCursor(0, 0);
                        lcd.print("enter that num:");
                        lcd.setCursor(8, 1);
                        lcd.print("&Press *");
                         char key= kpd.getKey();
                        if(key=='1' || key=='2' || key=='3' || key=='4' || key=='5' || key=='6' || key=='7' || key=='8' || key=='9' || key=='0' )
                        {
                           lcd.setCursor(stc, 1);
                        lcd.print(key);
                        stc++;
                        num=(num*10)+(key-48);
                        
                        }
      
                        if(key=='*')
                        {
                          stc=0;
                          lcd.clear();
                          lcd.setCursor(0, 0);
                        lcd.print("calculating");
                        for(int i=0,index=0;i<10;i=i+2)
                        {
                        lcd.setCursor(i, 1);
                        lcd.write(byte(index++));
                        delay(1500);
                        }
                        delay(1500);
                        lcd.clear();
                        lcd.print("Now I will read..");lcd.setCursor(0, 1);lcd.print("ur Mind & say..");delay(3000);lcd.clear();
                          num1=num-250;age=num1%100;mnt=num1/100;
                                  while(1)
                                  {
                                  lcd.setCursor(0, 0);
                                lcd.print("AGE=");lcd.setCursor(5, 0);lcd.print(String(age));lcd.print(" years");
                                lcd.setCursor(0, 1);
                                   lcd.print("MONTH=");
                                   if(mnt>0 && mnt<12)
                                  {
                                   lcd.setCursor(7, 1);lcd.print(String(month[mnt-1]));
                                  }
                                   else
                                            {
                                              lcd.clear();
                                             lcd.setCursor(5, 0);
                                             lcd.print("You Cheated");
                                             lcd.setCursor(6, 1);
                                              lcd.print("Bitch!!");delay(4000);
                                              goto here;
                                            }
                                   
                                                                       
                                    char key= kpd.getKey();
                                    if(key =='A')
                                    goto rst;
                                    else if(key=='B')
                                    {lcd.clear();num=0;stc=0;goto jere;}
                                   
                                  }      
                        }
                         if(key=='A')
                          goto here;
                          else if(key=='B')
                          {lcd.clear();stc=0;num=0;goto jere;}
                        }      
    }    
    else if(key=='A')
    goto here;
    else if(key=='B')
    goto bere;
    }
    
    }
      }
    }  

  }


The Code Explanation:

This code essentially works on a linear mathematical equation ..
in loop function i have written many hirarcheal while (1) loops for each stages.
I have also coded A to work as reset and B to go back to the previous step,

In the innermost loop of the code i have written the math logic
num=(num*10)+(key-48); -------means that each key press the ascii value is converted to the integer format and converting in to a final whole number until star key is pressed
and (num - 250) will give you age and birth month.To know that see the video.
ie num%100 = age, num/100 gives you the month.
That is it for the code
if you have any doubt feel free to contact me my mail id is nithinpradeep786@hotmail.com

Thank you,and visit my website daily for more of these kinds of projects and training

Thursday, 5 October 2017

SMART WEATHER SYSTEM On RASPBERRY PI

- No comments
In this Project I am going to show you how to make a Remote Weather monitoring system using Raspberry Pi3
I am using PubNub Cloud service for this,it is free...PubNub is a global Data Stream Network (DSN) and realtime infrastructure-as-a-service (IaaS) company based in San Francisco, California. The company makes products for software and hardware developers to build realtime web, mobile, and Internet of Things(IoT) applications.
PubNub's primary product is a realtime publish/subscribe messaging API built on their global data stream network which is made up of a replicated network of at least 14 data centers located in North America, South America, Europe, and Asia. The network currently serves over 300 million devices and streams more than 750 billion messages per month.
To understand how to use PubNub's cloud service see my YouTube Videos(I have included Link)  


THINGS YOU NEED

1.Raspberry Pi
2.LCD 16x2 (I used HD44780 LCD)
3. Temprature Sensor.(I have Used DS18B20 Temperature sensor probe which follows one wire protocol)
4.LED for indication
5.Bread Board
6.Jumper Wires (M-M,M-F)
7.An Android Phone and a PubNub account

This Project coding is completely done in Python (If you don't know python don't worry I have included the code),You can also learn Python from http://www.embeddedstudy.com/p/learn-python.html ..... it's very easy
​You have to install Os on Raspberry pi before you do this project please check my website on how to do so.


Connection Diagram


​SEE THE VIDEO ON HOW THIS WORKS





CLICK HERE TO DOWNLOAD THE CODE

If you have any doubt regarding this project implementation ,Please feel free to contact me i will guide you my support  through mail.Send your message from the contact form which is present in the right side tab.Happy Making....:)

Wednesday, 13 September 2017

IoT Based Smart Irrigation Project on Raspberry Pi

- No comments


Hello all...
In this project I am going to discuss ,how to build a Smart irrigation Project using Raspberry Pi



Smart Irrigation system essentially means to measure the water content in the soil continuously and with the help of  a Soil Moisture sensor,

(The Soil Moisture Sensor is used to measure the volumetric water content of soil. This makes it ideal for performing experiments in courses such as soil science, agricultural science, environmental science, horticulture, botany, and biology.)

This Project has 2 modes Automatic as well as manual,In Automatic mode after comparing with a threshold if the soil moisture is less ,it will turn ON a solenoid valve,for watering and vice versa.In Manual mode the user has the right to turn ON/OFF voluntarily.Semaphores concept in Linux OS is used in this project in order to avoid the overlapping of Manual and Auto modes .In this project i have also maintained a log file to monitor the activity of my project.(Time of ON/OFF,Status and the Mode).The time and date fetched using ctime() function .A solenoid valve is also connected in order to control the flow of water.All these components are connected to a Raspberry pi .

This is how the log looks like,




Use the Soil Moisture Sensor to:

 • Measure the loss of moisture over time due to evaporation and plant uptake.
 • Evaluate optimum soil moisture contents for various species of plants.
 • Monitor soil moisture content to control irrigation in greenhouses.
 • Enhance your Bottle Biology experiments.


 How to use the Soil Moisture Sensor

 The prongs should be oriented horizontally, but rotated onto their side – like a knife poised to cut food – so that water does not pool on the flat surface of the prongs. The horizontal orientation of the sensor ensures the measurement is made at a particular soil depth. The entire sensor can be placed vertically, but because soil moisture often varies by depth, this is not usually the desired orientation. To position the sensor, use a thin implement such as a trenching shovel to make a pilot hole in the soil. Place the sensor into the hole, making sure the entire length of the sensor is covered. Press down on the soil along either side of the sensor with your fingers. Continue to compact the soil around the sensor by pressing down on the soil with your fingers until you have made at least five passes along the sensor. This step is important, as the soil adjacent to the sensor surface has the strongest influence on the sensor reading. 



CHECK OUT MY REVIEW ABOUT THE SOIL MOISTURE SENSOR 






 You will get every products at cheap rate at our store, check the link below:
http://www.embeddedstudy.com/p/shop-gadgets.html


Components Required

  1. Raspberry Pi 3

The Raspberry Pi 3 is the third-generation Raspberry Pi. It replaced the Raspberry Pi 2 Model B in February 2016. Quad Core 1.2GHz Broadcom BCM2837 64bit CPU. 1GB RAM. BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board.

2.Soil Sensor Module

I used a 86062 humidity and soil moisture sensor.Controlling the potentiometer we can adjust the sensitivity of the sensor .it has also got led indications over it.




3.JUMPER WIRES

We require Male-Female and Female-Female Jumper wires for connection.

4.MCP 3204(ADC)

MCP3204/3208 devices are successive approximation 12-bit Analog- to-Digital (A/D) Converters with on-board sample and hold circuitry. ... Differential Nonlinearity (DNL) is speci- fied at ±1 LSB, while Integral Nonlinearity (INL) is offered in ±1LSB (MCP3204/3208-B) and ±2LSB (MCP3204/3208-C) versions.



We have already said how to set up the Raspberry Pi and create the pubnub accountin the IoT Based Smart Home on Raspberry Pi
if you have missed that go through it.

CONNECTION DIAGRAM:

check pinout.xyz for Raspberry Pi pins,All pins mentioned here are WiringPi pins.
Connect everything as follows:




PROJECT CODE SNIPPET:

The Project Code is divided in to 2 files you need to make another file other than listen.c  ie adc.h for adc interfacing to soil sensor(I use MCP 3204 ADC) this is for getting precise analog sensor values.

So first create adc.h and include it in the listen.c file.
you can also download whole code zip files
DOWNLOAD 

here is the adc.h file code
#include<stdint.h>
#include<wiringPiSPI.h>

float mcp3204_read(int ch_num)
{

uint8_t buff[3];
int adc;
float vol=0;
if((ch_num>3)||(ch_num<0))
 return -1;

buff[0]=0x06;
buff[1]=ch_num<<6;
buff[2]=0;

wiringPiSPIDataRW(0,buff,3);
adc=((buff[1]&0x0f)<<8)+buff[2];

//printf("%d adc val\n,",adc);
vol=((float)adc*5)/4096;
return vol;
}

code explanation

mcp 3204 uses spi protocol to communicate with Raspberri Pi,mcp3204_read()returns float values of measured moisture.


listen.h file code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include<wiringPi.h>
#include"adc.h"

#include<sys/sem.h>
#include<sys/ipc.h>
#include<sys/types.h>

#include <json.h>

#include "pubnub.h"
#include "pubnub-sync.h"

#define PUBLISH_KEY "pub-c-c30824bb-bc31-463b-a395-XXXXXXXXXXXX"
#define SUBSCRIBE_KEY "sub-c-cfa511de-660a-11e7-b272-XXXXXXXXXXXX"     //use your Publish and Subscribe keys 
#define IR 1
#define LED 2
#define CHAN 0
#define LED1 25

struct pubnub_sync *_sync;
struct pubnub *p;
json_object *msg;
char *buff;

int flag=0;

char * readPubnub ()
{
 /* Subscribe */
/* 1 */  const char *channels[] = { "ch1", "ch2" };
/* 2 */  pubnub_subscribe_multi(
    /* struct pubnub */ p,
    /* list of channels */ channels,
    /* number of listed channels */ 2,
    /* default timeout */ -1,
    /* callback; sync needs NULL! */ NULL,
    /* callback data */ NULL);
  if (pubnub_sync_last_result(_sync) != PNR_OK)
   return EXIT_FAILURE;
  msg = pubnub_sync_last_response(_sync);
  if (json_object_array_length(msg) == 0) {
   printf("pubnub subscribe ok, no news\n");
  } else {
   char **msg_channels = pubnub_sync_last_channels(_sync);
   
   for (int i = 0; i < json_object_array_length(msg); i++) {
    json_object *msg1 = json_object_array_get_idx(msg, i);
     if(strcmp(channels[i],msg_channels[i])==0)
      printf("%s\n",msg_channels[i]);
     else
      printf("%s\n",msg_channels[i]);
    printf("pubnub subscribe [%s]: %s\n", msg_channels[i], buff = (char *)json_object_get_string(msg1));

   }
  }
  return buff;
        
}


void PubNubInit ()
{
        _sync = pubnub_sync_init();

        p = pubnub_init(
                        /* publish_key */ PUBLISH_KEY,
                        /* subscribe_key */ SUBSCRIBE_KEY,
                        /* pubnub_callbacks */ &pubnub_sync_callbacks,
                        /* pubnub_callbacks data */ _sync);

}

void main(void)
{
 char *on="MOTOR ON";
 char *off="MOTOR OFF";
 FILE *fp;
 
 wiringPiSetup();
 pinMode(LED,OUTPUT);
 digitalWrite(LED,LOW);
 fp=fopen("log","a+");
 
 if(fp<0)
 {
 perror("fopen");
 
 }
 fprintf(fp,"%s\t%s\t\t%s\n","Mode","Status","Time");
 fclose(fp); 
 
 
 struct sembuf v;

 char *readbuff;
 int id=semget(5,1,IPC_CREAT|0644);
 if(id<0)
 {
  perror("semget");
  return;
 }
 semctl(id,0,SETVAL,0);
 time_t t1;
 

 if(fork()==0)
 {
  //manual code
  float f;
  PubNubInit ();
  v.sem_num=0;
  v.sem_op=0;
  v.sem_flg=0;
  if(wiringPiSPISetup(0,1000000)<0)
   printf("no\n");
  else
   printf("done");

  while(1){
   readbuff = readPubnub (); 
   printf ("readbuff = %s\n",readbuff);


   if(strstr(readbuff,"MOTOR ON"))
   {

    f=mcp3204_read(CHAN);
    printf("Manual :%f\n",f);

    semop(id,&v,1);

    if(f>3.8)
    {
     fp=fopen("log","a+");
     semctl(id,0,SETVAL,1); 
     digitalWrite(LED,LOW);//low moisture on the motor
     printf("Manual On \n");
     t1=time(0);
     fprintf(fp,"%s\t%s \t %s \n","Manu:  ",on,ctime(&t1));
     
     fclose(fp);
    }
    else 
    {
     printf("no need\n");  
    }
   }  

   else if(strstr(readbuff,"MOTOR OFF"))
   {
    fp=fopen("log","a+");
    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Manu:  ",off,ctime(&t1));

    digitalWrite(LED,HIGH);
    printf("Manual off\n");
    sleep(5); 
    fclose(fp);
    semctl(id,0,SETVAL,0);
   }
  }

 } 

 else
 {

  float f;
  if(wiringPiSPISetup(0,1000000)<0)
   printf("ADC Enabled in auto mode \n");

  struct sembuf v;
  v.sem_num=0;
  v.sem_op=0;
  v.sem_flg=0;


  while(1)
  {
   f=mcp3204_read(CHAN);
   printf("Auto mode detection :: voltage level : %f\n",f);
   delay(2000);
    
   
   semop(id,&v,1);

   if(f>3.8)
   {
    fp=fopen("log","a+");
    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Auto:  ",on,ctime(&t1));
     
    semctl(id,0,SETVAL,1);
    digitalWrite(LED,LOW);
    printf("Automatic mode motor is switching on fr 40 sec\n");
 
    delay(40000);

    digitalWrite(LED,HIGH);

    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Auto:  ",off,ctime(&t1));
    fclose(fp);

    printf("Auto mode is switching off\n");
    semctl(id,0,SETVAL,0);
   }
   else
   ;

  }

 }
}

//end of main

Read Pubnub,Write Pubnub ,Pubnub Init and declarations are explained in the smart home project (it is almost same..go through it...),so we are only discussing about the main() code.
#include"adc.h"

#include<sys/sem.h>
#include<sys/ipc.h>
#include<sys/types.h>
are added additionally for adc and semaphore operations
#define LED 2
#define CHAN 0
#define LED1 25

Main Function

        char *on="MOTOR ON";
 char *off="MOTOR OFF";
 FILE *fp;
 
 wiringPiSetup();
 pinMode(LED,OUTPUT);
 digitalWrite(LED,LOW);
 fp=fopen("log","a+");
 
 if(fp<0)
 {
 perror("fopen");
 
 }
 fprintf(fp,"%s\t%s\t\t%s\n","Mode","Status","Time");
 fclose(fp);
Declaring 2 strings one for Motor ON and one for OFF,Declaring a file pointer for log
Declaring LED pin and definig it as output(wiring pi pin 2).check pinout.xyz
Writing MODE Status and Time to Log file.


struct sembuf v;

 char *readbuff;
 int id=semget(5,1,IPC_CREAT|0644);
 if(id<0)
 {
  perror("semget");
  return;
 }
 semctl(id,0,SETVAL,0);
 time_t t1;
 

 if(fork()==0)
 {
  //manual code
  float f;
  PubNubInit ();
  v.sem_num=0;
  v.sem_op=0;
  v.sem_flg=0;
  if(wiringPiSPISetup(0,1000000)<0)
   printf("no\n");
  else
   printf("done");

  while(1){
   readbuff = readPubnub (); 
   printf ("readbuff = %s\n",readbuff);


   if(strstr(readbuff,"MOTOR ON"))
   {

    f=mcp3204_read(CHAN);
    printf("Manual :%f\n",f);

    semop(id,&v,1);

    if(f>3.8)
    {
     fp=fopen("log","a+");
     semctl(id,0,SETVAL,1); 
     digitalWrite(LED,LOW);//low moisture on the motor
     printf("Manual On \n");
     t1=time(0);
     fprintf(fp,"%s\t%s \t %s \n","Manu:  ",on,ctime(&t1));
     
     fclose(fp);
    }
    else 
    {
     printf("no need\n");  
    }
   }  

   else if(strstr(readbuff,"MOTOR OFF"))
   {
    fp=fopen("log","a+");
    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Manu:  ",off,ctime(&t1));

    digitalWrite(LED,HIGH);
    printf("Manual off\n");
    sleep(5); 
    fclose(fp);
    semctl(id,0,SETVAL,0);
   }
  }

 } 
Creating semaphore for resource locking and forking child to create MANUAL mode.
if(strstr(readbuff,"MOTOR ON"))
Comparing the string sent from Pubnub with "MOTOR ON",then moisture value is read from ADC to a float variable 'f' ,and if  value is greater than a threshold resource is locked (Auto can't access) LED gets ON ,and will print status to log file ,afterwards close the file that is opened in the append mode,In the else part if there is enough water content no action is taken and will print NO Need....Same for MOTOR OFF also LED gets off and will print the status  to log file..the resource is released only after Motor is OFF and is made available to AUTO Mode..(Resource here means the Status of Pi's pin connected to Solenoid valve).

else
 {

  float f;
  if(wiringPiSPISetup(0,1000000)<0)
   printf("ADC Enabled in auto mode \n");

  struct sembuf v;
  v.sem_num=0;
  v.sem_op=0;
  v.sem_flg=0;


  while(1)
  {
   f=mcp3204_read(CHAN);
   printf("Auto mode detection :: voltage level : %f\n",f);
   delay(2000);
    
   
   semop(id,&v,1);

   if(f>3.8)
   {
    fp=fopen("log","a+");
    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Auto:  ",on,ctime(&t1));
     
    semctl(id,0,SETVAL,1);
    digitalWrite(LED,LOW);
    printf("Automatic mode motor is switching on fr 40 sec\n");
 
    delay(40000);

    digitalWrite(LED,HIGH);

    t1=time(0);
    fprintf(fp,"%s\t%s\t %s \n","Auto:  ",off,ctime(&t1));
    fclose(fp);

    printf("Auto mode is switching off\n");
    semctl(id,0,SETVAL,0);
   }
   else
   ;

  }

 }
}
AUTO mode is written inside the Parent Code.Parent process has all time control and need to monitor the status every time.
Here also while running in the AUTO mode, MANUAL mode must not interfere so we are locking the resource using semaphores.As in Manual mode here also LED status and LOG file entry is changes.In else code we will do nothing.In Auto mode motor is pre-setted to switch On for 40 sec & then turned OFF.

Thats all for this project,Hope you all liked it... Enjoy....