Dhananjay Khairnar @. Powered by Blogger.

25 March 2017

Bluetooth Controlled Home Equipments:


Basic about bluetooth:

Bluetooth is a wireless technology standard for exchanging data over short distances (using short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz) from fixed and mobile devices, and building personal area networks (PANs). Invented by telecom vendor Ericsson in 1994

Radio frequency communication (RFCOMM)

The Bluetooth protocol RFCOMM is a simple set of transport protocols, made on top of the L2CAP protocol, providing emulated RS-232 serial ports (up to sixty simultaneous connections to a Bluetooth device at a time). The protocol is based on the ETSI standard TS 07.10.

RFCOMM is sometimes called serial port emulation. The Bluetooth serial port profile is based on this protocol.

RFCOMM provides a simple reliable data stream to the user, similar to TCP. It is used directly by many telephony related profiles as a carrier for AT commands, as well as being a transport layer for OBEX over Bluetooth.

Many Bluetooth applications use RFCOMM because of its widespread support and publicly available API on most operating systems. Additionally, applications that used a serial port to communicate can be quickly ported to use RFCOMM

In the protocol stack, RFCOMM is bound to L2CAP.
In our project we are going to use RFCOM socket.


Requrments :
1) Arduino
2) Bluetooth module HC-05
3) Relay circuit
4) Connecting wires

Aim : Controll Device from bluetooth

Software Design:

Arduino code:
Here we design simple protocol between mobile device and microcontroller to agree on some data code like.
if mobile sends string 'START1' means turn on Device, if mobile sends string 'STOP1' then turn off device.
And 'GETSEN' for sensor readings
 following code is design for do that

/*
Arduino Turn LED On/Off using Bluetooth 
Created feb 6 2017
by Dhananjay
It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.

Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
*/
#include < softwareserial.h >
SoftwareSerial mySerial(10, 11); // RX, TX
char junk;
String str;

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 mySerial.begin(9600);
 mySerial.setTimeout(200);
 pinMode(13, OUTPUT);
 pinMode(A0, INPUT);
}

void loop()
{

  if(mySerial.available()){
    while(mySerial.available())
    {
      str = mySerial.readString();
    }
    Serial.print(str);
    if(str == "START1\r\n"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH); 
    }
    else if(str == "STOP1\r\n"){   //in case of 'b' turn the LED off
      digitalWrite(13, LOW);
    }
    else if(str == "GETSEN\r\n")// Send analogue sensor value
    {
      int anlgval = analogRead(A0)%100;
      mySerial.println(anlgval);
      Serial.println(anlgval);
    }


    str = "";
  }
}

In above code we are controlling one equipment which are connected to relay from Arduino pin 13.
You can increase count of equipment by adding extra if conditions .

Android code:
Now its some hard part of this project as electronics guys dont know android coding but dont worry is not so hard if you know some basics of OOPS and how to deal with Java. You need to install Arduino IDE with along proper Android SDK. If you SDK is latest and not supported by following code then you need to mange Android studio to compile following code.

Sreen shot given as:

Code in Android studio:
Download the rar file it contains source code of simple android app written by me. You can customize it. Open Android Studio and open project.
Structure of project:

method for write data to HC05:

Method for receive String from HC05

Gradal build settings:


Hardware Design:

HC-05 :

HC-05 PinOut (Right) :

 
  • KEY: If brought HIGH before power is applied, forces AT Command Setup Mode. LED blinks slowly (2 seconds)
  • VCC: +5 Power
  • GND: System / Arduino Ground
  • TXD: Transmit Serial Data from HC-05 to Arduino Serial Receive. NOTE: 3.3V HIGH level: OK for Arduino
  • RXD: Receive Serial Data from Arduino Serial Transmit
  • STATE: Tells if connected or not

COMMAND and DATA TRANSFER MODE:

The module has two modes of operation, Command Mode where we can send AT commands to it and Data Mode where it transmits and receives data to another bluetooth module.
The default mode is DATA Mode, and this is the default configuration, that may work fine for many applications:

COMMAND :
In some cases you may want to change some of the configuration setup values. There are two ways to get into Command Mode.
Connect the KEY/WAKEUP pin high before applying power to the module. This will put the module into command mode at 38400 baud. This is commonly used, and needed if you don't know the baud rate the module is set to.
AT+ROLE=0 : You can change role by 0 for SLAVE & 1 for Master. Leave it as 0 as we want this module to be SLAVE.
AT+NAME=DKS_BLUE : change name of device which is brodcast

DATA TRANSFER MODE:
Open KEY?WAKEUP pin  dont connect it anywhere then power up module it is in now Data Transfer mode. Whatever data you send to the module from serial terminal that get transfer to the connected device via RFCOM.
  • Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity : None, Handshake: None
  • Passkey: 1234
  • Device Name: HC-05
Connection Diagram:




make this connection to operate bulb from bluetooth.




Published: By: DK - 01:15

Line follower car :

Aim:
Create Arduino based Line follower robot from scratch.

It is a machine that follows a line, either a black line on white surface or vise-versa. For Beginners it is usually their first robot to play with. In this tutorial, we will teach you to make the line follower robot move on the line with a type of feedback mechanism. It’s the most basic example of adding small intelligence to a robot, but it’s actually the designer’s intelligence!!

Requirement:
1) Arduino Uno + Arduino IDE
2) DC geared motors x 2
3) Power bank or 9v or 12v Battery
4) IR sensors (ready made or You can make it by your own)
5) Connecting wires
6) Motor driver ready made or Your own.
Working of sensors:

IR light is invisible to human eyes it can be detected using IR sensore. As shown in picture below IR LED which is act as Transmitter and Photo Diode act as receiver. When Infrared Light strike on white surface its get reflect back and received by photo diode, while in other case IR Light is absorb by black surface so Photo diode is ideal stat.
We need to convert these signals to 0-5v so we use OPAM IC lm358 or ready made sensor.
Software Design:
We are designing algorithm for following  conditions detected by IR sensors.

 
In first condition left sensor detect black line so we need to turn lef so both IR sensors should be on white colour. same in other case if right sensor detect black line turn right to come back both sensor to white surface.
now decide the turn mechanism for robot. 

Truth Table:

For Half Turn:
Sensor Left | Sensor Right | Motor Left |  Motor Right
black             black                    off             off
black             white                   off             on
white             black                     on            off
white              white                   on             on

For Full Turn:
Sensor Left | Sensor Right | Motor Left  | Motor Right
black             black                    off             off
black             white                   reverse        forward
white             black                   forward     reverse
white              white                  forward    forward

In above cases
  • half turn: it is stable and less fluctuate robot while running
  • full turn : suitable for hard and narrow turns.
Here we write code for half turn mechanism you can modify code for full turn.
//motor A
#define M11 5
#define M12 6

//motor b
#define M23 7
#define M24 8

//Sensore
#define lSen 3
#define rSen 4

void setup()
{
  pinMode(M11, OUTPUT);
  pinMode(M12, OUTPUT);
  pinMode(M21, OUTPUT);
  pinMode(M22, OUTPUT);
  pinMode(lSen,INPUT);
  pinMode(rSen,INPUT);
   
  digitalWrite(M11,LOW);
  digitalWrite(M12,LOW);
  digitalWrite(M21,LOW);
  digitalWrite(M21,LOW);

  delay(1000);
}

void loop()
{
  readLsen = digitalRead(lSen);
  readRsen = digitalRead(rSen);

  if((readLsen == 0) && (readRsen == 0))//if both sensors on black colour then stop both motors
  {
     stop();
  }
  else if((readLsen == 1) && (readRsen == 0))//if left sensor on white and right sensor on black turn right
  {
    turnRight();
  }
  else if((readLsen == 0) && (readRsen == 1))//if left sensor on black and right sensor on white turn left
  {
    turnLeft(); 
  }
  else if((readLsen == 1) && (readRsen == 1))//if both sensor on white move forward
  {
     moveForward();
  }
}

void turnRight() {
  digitalWrite(M11, LOW);
  digitalWrite(M12, LOW);
  digitalWrite(M21, HIGH);
  digitalWrite(M22, LOW);
}
void stop () {
  digitalWrite(M11, LOW);
  digitalWrite(M12, LOW);
  digitalWrite(M21, LOW);
  digitalWrite(M22, LOW);
}
void turnLeft() {
  digitalWrite(M11, HIGH);
  digitalWrite(M12, LOW);
  digitalWrite(M21, LOW);
  digitalWrite(M22, LOW);
}
void moveForward() {
  digitalWrite(M11, HIGH);
  digitalWrite(M12, LOW);
  digitalWrite(M21, HIGH);
  digitalWrite(M22, LOW);
}
void reverse(){
  digitalWrite(M11, LOW);
  digitalWrite(M12,HIGH);
  digitalWrite(M21, LOW);
  digitalWrite(M22, HIGH);
}

Upload this sketch in Arduino and go through hardware design.

Hardware Design:


Components and Their use:

  • 12V DC motor: If a DC power is passed on a DC motor, it will produce torque. The torque created will lead to the rotation of the wheels. It will only operate on the direct current. Here, two 12V DC motors are used. -> 300rpm,12v,DC motor 

    • Zero PCB :  it is very rasy to beginners for creating their circuits on Zero PCB.->10x10cm
    • Battery: This robot is powered by a battery. One 9V battery is enough to perform this process. For more usages, four 9V batteries may be required.-> 9v or powerbank
     
    • IR sensor circuit: This process requires two IR sensor circuits. An IR sensor circuit will include an IC LM358N, potentiometer, IR receiver, and IR transmitter for sensing the black lines or go for Ready made sensor here I used one ready made and one is made by me on zero pcb .
     
    • Battery connector: It is used to connect the battery with the circuit.
     
    • IC LM358N: It is an operational amplifier or comparator used to evaluate the voltage current. The high amount of voltage gained will be considered as the output. It is one of the main components of an IR sensor circuit.
    • IC L293D: It allows the DC motor to run in both front and back directions. It consists of up to 16 pins.
    here mine is four motor driver but I am using only two motor driver.
    • Two plastic wheels: The plastic wheels will be connected to the DC motors. As soon as they create the torque, these wheels will help the robot to move.

    • Ball wheel: The castor wheel or ball wheel is used to make the movements easy and quick even it has large components on its top. In this process, a small stainless steel castor could be the best one to use. 
    • Wires (single-core-multi stand & single-core-single stand): single core multi stand wires are implemented for connecting the motor drives, and the single core single stand wires are used to connect on the zero PCB. Two meters of each wire will be required.

    • Chasee mounting :
     Chasee can be made with Metal,Hard Plastic, Plywood or Acrylic sheet. In image I made This chasee with acrylic sheet and drill it to fit L shape motor holding clips.

      Final Connection diagram with Arduino.
      Here I mount L293d motor driver on Arduino but you can use Arduino motor shield instead.



      Make all connections shown in figure and assemble it on chasee use double side tape for attach sensors and battery to chasee or use spacer and screw to tight all parts.

       

      Thank you. if you like post please like it

      Published: By: DK - 01:07