Thursday, 6 October 2016

AUTOMATIC E-BABY CRADLE SWING BASED ON BABY CRY




AUTOMATIC E-BABY CRADLE SWING BASED ON                                 BABY CRY.

My latest Arduino DIY project is Automatic E-Baby Cradle Swing based on Baby Cry.




Parents in the present world are busy in their professional life, so they do not get sufficient time to take care of their babies. It may be expensive for the household to afford a nanny.
Today’s woman has to manage home along with their office work simultaneously. After long working hours, they have to take care of the home along with the baby. They may not get enough time to swing the cradle manually and sooth the baby. Moreover, in today’s life style, it is very difficult even for the housewives to sit nearby their infants and sooth them whenever they cry. Enhancing sleep quality is an important research topic, as quality sleep is important for everyone, especially for infants . A comfortable electric cradle with a low power consumption that can letinfants fall asleep quickly is desired by many parents and numerous novel inventions based on swing mechanisms in the form of springs or rods have been developed .Hospitals have neonatal and maternity units. Nurses in these units have to take care of baby and sooth them whenever they cry. 

The system is designed to help parents and nurses in infants care. The design aims at following points: 
1.  Cradle starts swinging automatically when baby cry and swings till the baby stops crying. 
Sends message to mother’s mobile when  baby cries for more than a stipulated time indicating that baby needs attention.

HARDWARE EXPLANATION:-

GSM module
Audio sensor KY-038
SERVO MOTOR
Arduino uno
Cradle (model)
Resistors
capacitors




MORE IMAGES















POWER SUPPLY DESIGN



use;Arduino uno




Arduino ide; http://www.arduino.org/downloads



Arduino coding handled by :- PRANAV S NAIR (pranavsnair93@gmail.com)

Project helping courtesy:- Felix philip <felixphilip86@gmail.com>


                                                            CODE


#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
int sensorPin = A0; // select the input pin for the potentiometer // select the pin for the LED
int sensorValue = 0;
int count=0;// variable to store the value coming from the sensor
int motor=8;
int motor2=10;
void setup ()
{
Serial.begin (9600);
mySerial.begin(9600); // Setting the baud rate of GSM Module // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
pinMode(motor,OUTPUT);
pinMode(motor2,OUTPUT);
}
void loop ()
{ delay(200);
sensorValue = analogRead (sensorPin);
Serial.println (sensorValue, DEC);
if(sensorValue > 65)
{ digitalWrite(motor2,LOW);
digitalWrite(motor,HIGH);
delay(400);
digitalWrite(motor,LOW);
digitalWrite(motor2,HIGH);
delay(400);
}
else
{
digitalWrite(motor2,LOW);
digitalWrite(motor,LOW);
}
if(count>5)
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+919995856777\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("baby is crying..!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}






Wednesday, 5 October 2016

DEPARTMENT MANAGEMENT SYSTEM USING ARDUINO UNO.

DEPARTMENT MANAGEMENT SYSTEM                      USING ARDUINO UNO.


My latest Arduino DIY project is DEPARTMENT MANAGEMENT SYSTEM USING ARDUINO UNO.


The objective of this mini-project is to build a department management system .The management system includes a timetable, digital clock with temperature and a power saving module. This management system can be used in institutions such as Schools, Colleges, Universities, and Offices etc. It is even possible to store multiple timetables and switch between them. All of is achieved by integrating SENSORS and LCD to the ARDUINO MODULE. The proposed prototype system consists of a medium sized 20x8 LCD display, a 7 SEGMENT display, an LM35, a PIR sensor and an Array of Switches to switch between the days. All the device components are being powered by a 9V DC Supply adapter. In addition a DIGITAL THERMOMETER is also added to the digital timetable using LM35 module. A 4 digit 7 segment display shows the time. A PIR sensor connected with the Arduino checks for human presence and automatically saves power.



HARDWARE EXPLANATION;



ARDUINO UNO R3


PASSIVE INFRARED SENSOR (PIR)

HD44780 LCD DISPLAY

TEMPERATURE SENSOR LM 35

SWITCHES

LEDs

RESISTOR

CAPACITOR

Connection Diagram;


































MORE IMAGES;














POWER SUPPLY DESIGN







FINAL MODEL



use;Arduino uno


Arduino ide; http://www.arduino.org/downloads


Arduino coding handled by :- PRANAV S NAIR (pranavsnair93@gmail.com)

Project helping courtesy:- Felix philip <felixphilip86@gmail.com>


Code



#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(1,2,3,4,5,6);

const int buttonPin1 = 7;
const int buttonPin2 = 8;
const int buttonPin3 = 9;
const int buttonPin4 = 10;
const int buttonPin5 = 11;
const int buttonPin6 = 12;
const int inPin = A0;
int motion = 13;
int motionLed = 0;
unsigned long pervMillis=0;
const long interval=5000;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
void setup() {
lcd.begin(20,4);
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(motion, INPUT);
pinMode(motionLed, OUTPUT);
}
void loop() {
pgmbegin:
lcd.clear();
lcd.setCursor(4,1);
lcd.print("Enter a Day!");
lcd.setCursor(0,2);
lcd.print("--------------------");
int value = analogRead(inPin); // read the value from the sensor
lcd.setCursor(0,3);
lcd.print("Temperature:");
float millivolts = (value / 1024.0) * 5000;
float celsius = millivolts / 10;
lcd.setCursor(13,3);
lcd.print(celsius);
lcd.print("C");
delay(100);
unsigned long currenMillis= millis();
long sensor = digitalRead(motion);
if(sensor==HIGH)
{
digitalWrite(motionLed,HIGH);
if(currenMillis-pervMillis>=interval)
{ pervMillis=currenMillis;
digitalWrite (motionLed, LOW );}
else
{ digitalWrite(motionLed,HIGH);}
}
else
{
digitalWrite (motionLed, LOW);
}
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH)
{ digitalWrite (motionLed, HIGH);
monday: for(int i=0;i<=200;i++)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MONDAY");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(0,2);
lcd.print("-");
lcd.setCursor(0,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto pgmbegin;}
if(buttonState2 == HIGH){ goto tuesday;}
if (buttonState3 == HIGH){ goto wednesday;}
if (buttonState4 == HIGH){ goto thursday;}
if (buttonState5 == HIGH){ goto friday;}
if(buttonState6 == HIGH){ goto saturday;}
}
}
if (buttonState2 == HIGH)
{ digitalWrite (motionLed, HIGH);
tuesday: for(int i=0;i<=200;i++)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("TUESDAY");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(0,2);
lcd.print("-");
lcd.setCursor(0,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto monday;}
if (buttonState2 == HIGH){ goto pgmbegin;}
if (buttonState3 == HIGH){ goto wednesday;}
if (buttonState4 == HIGH){ goto thursday;}
if (buttonState5 == HIGH){ goto friday;}
if(buttonState6 == HIGH){ goto saturday;}
}
}
if (buttonState3 == HIGH)
{ digitalWrite (motionLed, HIGH);
wednesday: for(int i=0;i<=200;i++)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("WEDNESDAY");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(0,2);
lcd.print("-");
lcd.setCursor(0,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto monday;}
if(buttonState2 == HIGH){ goto tuesday;}
if (buttonState3 == HIGH){ goto pgmbegin;}
if (buttonState4 == HIGH){ goto thursday;}
if (buttonState5 == HIGH){ goto friday;}
if(buttonState6 == HIGH){ goto saturday;}
}
}
if (buttonState4 == HIGH)
{ digitalWrite (motionLed, HIGH);
thursday: for(int i=0;i<=200;i++)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("THURSDAY");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(0,2);
lcd.print("-");
lcd.setCursor(0,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto monday;}
if(buttonState2 == HIGH){ goto tuesday;}
if (buttonState3 == HIGH){ goto wednesday;}
if (buttonState4 == HIGH){ goto pgmbegin;}
if (buttonState5 == HIGH){ goto friday;}
if(buttonState6 == HIGH){ goto saturday;}
}
}
if (buttonState5 == HIGH)
{ digitalWrite (motionLed, HIGH);
friday: for(int i=0;i<=200;i++)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("FRIDAY");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(0,2);
lcd.print("-");
lcd.setCursor(0,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto monday;}
if(buttonState2 == HIGH){ goto tuesday;}
if (buttonState3 == HIGH){ goto wednesday;}
if (buttonState4 == HIGH){ goto thursday;}
if (buttonState5 == HIGH){ goto pgmbegin;}
if(buttonState6 == HIGH){ goto saturday;}
}
}
if (buttonState6 == HIGH)
{ digitalWrite (motionLed, HIGH);
saturday: for(int i=0;i<=200;i++)
{ lcd.clear();
lcd.setCursor(6,0);
lcd.print("saturday");
lcd.setCursor(0,1);
lcd.print("-");
lcd.setCursor(4,2);
lcd.print("-");
lcd.setCursor(6,3);
lcd.print("-");
delay(200);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
if (buttonState1 == HIGH){ goto monday;}
if(buttonState2 == HIGH){ goto tuesday;}
if (buttonState3 == HIGH){ goto wednesday;}
if (buttonState4 == HIGH){ goto thursday;}
if (buttonState5 == HIGH){ goto friday;}
if(buttonState6 == HIGH){ goto pgmbegin;}
}
}
else
{
goto pgmbegin;}
}

SELF BALANCING ROBOT USING ARDUINO

Tuesday, March 22, 2016

Self Balancing Robot using arduino.


My latest Arduino DIY project is a self balancing robot.
Arduino Uno R3 microcontroller board is used for this project. MPU6050, an 6DOF IMU (with accelerometer and gyroscope) is used to get the angle and L298N motor controller board controls the 2 motors. The motors are 12V 500rpm and the wheels are 8cm in diameter. Robot size is 17x10x30 cm. Three plexiglas plates are used to hold the frame and parts. Standard PID controller is used to control the robot. To tune the PID controller parameters 3 No, 10k potentiometers are used.
You may find the Arduino sketch and libs on GitHub.
First you download this zip file and then un-zip it. you will get main code and libraries.
Separate each libraries and zip it and add to Arduino  IDE Library.
Parts:1 x Arduino Uno R3
1 x MPU6050 (IMU)
1 x L298N Motor Driver Controller
2 x 12V 500 RPM Gear Motors + 80mm Wheels
3 x 10k Potentiometer

Connection Diagram

For Manual PID setting. 















PID vale selection by potentiometers. (this is much better than manual PID setting)















POWER SUPPLY DESIGN


Note:-you can manually adjust the voltage supply for get a better result,(we use 7v) ,it depend on model desing.
















 more images,








use;Arduino uno










Arduino ide; http://www.arduino.org/downloads



Arduino coding handled by :- PRANAV S NAIR (pranavsnair93@gmail.com)

Project helping courtesy:- Felix philip <felixphilip86@gmail.com>

Code

#include <PID_v1.h>
#include <LMotorController.h>
#include "I2Cdev.h"

#include "MPU6050_6Axis_MotionApps20.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif


#define LOG_INPUT 0
#define MANUAL_TUNING 0
#define LOG_PID_CONSTANTS 0 //MANUAL_TUNING must be 1
#define MOVE_BACK_FORTH 0

#define MIN_ABS_SPEED 30

//MPU


MPU6050 mpu;

// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars
Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector


//PID


#if MANUAL_TUNING
  double kp , ki, kd;
  double prevKp, prevKi, prevKd;
#endif
double originalSetpoint = 174.29;
double setpoint = originalSetpoint;
double movingAngleOffset = 0.3;
double input, output;
int moveState=0; //0 = balance; 1 = back; 2 = forth

#if MANUAL_TUNING
  PID pid(&input, &output, &setpoint, 0, 0, 0, DIRECT);
#else
  PID pid(&input, &output, &setpoint, 70, 240, 1.9, DIRECT);
#endif


//MOTOR CONTROLLER


int ENA = 3;
int IN1 = 4;
int IN2 = 8;
int IN3 = 5;
int IN4 = 7;
int ENB = 6;


LMotorController motorController(ENA, IN1, IN2, ENB, IN3, IN4, 0.6, 1);


//timers


long time1Hz = 0;
long time5Hz = 0;


volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady()
{
    mpuInterrupt = true;
}


void setup()
{
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // initialize serial communication
    // (115200 chosen because it is required for Teapot Demo output, but it's
    // really up to you depending on your project)
    Serial.begin(115200);
    while (!Serial); // wait for Leonardo enumeration, others continue immediately

    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();

    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXGyroOffset(220);
    mpu.setYGyroOffset(76);
    mpu.setZGyroOffset(-85);
    mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (devStatus == 0)
    {
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);

        // enable Arduino interrupt detection
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
        
        //setup PID
        
        pid.SetMode(AUTOMATIC);
        pid.SetSampleTime(10);
        pid.SetOutputLimits(-255, 255);  
    }
    else
    {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }
}


void loop()
{
    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    // wait for MPU interrupt or extra packet(s) available
    while (!mpuInterrupt && fifoCount < packetSize)
    {
        //no mpu data - performing PID calculations and output to motors
        
        pid.Compute();
        motorController.move(output, MIN_ABS_SPEED);
        
        unsigned long currentMillis = millis();

        if (currentMillis - time1Hz >= 1000)
        {
            loopAt1Hz();
            time1Hz = currentMillis;
        }
        
        if (currentMillis - time5Hz >= 5000)
        {
            loopAt5Hz();
            time5Hz = currentMillis;
        }
    }

    // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount == 1024)
    {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    }
    else if (mpuIntStatus & 0x02)
    {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        #if LOG_INPUT
            Serial.print("ypr\t");
            Serial.print(ypr[0] * 180/M_PI);
            Serial.print("\t");
            Serial.print(ypr[1] * 180/M_PI);
            Serial.print("\t");
            Serial.println(ypr[2] * 180/M_PI);
        #endif
        input = ypr[1] * 180/M_PI + 180;
   }
}


void loopAt1Hz()
{
#if MANUAL_TUNING
    setPIDTuningValues();
#endif
}


void loopAt5Hz()
{
    #if MOVE_BACK_FORTH
        moveBackForth();
    #endif
}


//move back and forth


void moveBackForth()
{
    moveState++;
    if (moveState > 2) moveState = 0;
    
    if (moveState == 0)
      setpoint = originalSetpoint;
    else if (moveState == 1)
      setpoint = originalSetpoint - movingAngleOffset;
    else
      setpoint = originalSetpoint + movingAngleOffset;
}


//PID Tuning (3 potentiometers)

#if MANUAL_TUNING
void setPIDTuningValues()
{
    readPIDTuningValues();
    
    if (kp != prevKp || ki != prevKi || kd != prevKd)
    {
#if LOG_PID_CONSTANTS
        Serial.print(kp);Serial.print(", ");Serial.print(ki);Serial.print(", ");Serial.println(kd);
#endif

        pid.SetTunings(kp, ki, kd);
        prevKp = kp; prevKi = ki; prevKd = kd;
    }
}


void readPIDTuningValues()
{
    int potKp = analogRead(A0);
    int potKi = analogRead(A1);
    int potKd = analogRead(A2);
        
    kp = map(potKp, 0, 1023, 0, 25000) / 100.0; //0 - 250
    ki = map(potKi, 0, 1023, 0, 100000) / 100.0; //0 - 1000
    kd = map(potKd, 0, 1023, 0, 500) / 100.0; //0 - 5
}
#endif