Dhananjay Khairnar @. Powered by Blogger.

24 May 2017

ATTiny85 with OLED Display interfacing and upload custom image in Displa...

ATTiny85 with OLED Display interfacing and upload custom image in Display:


Published: By: DK - 23:34

1 April 2017

Start making IoT based product:




Internet is the virtual world where users are interested in accessing,editing and controlling data.Everyone is eyeing the next big thing in the internet.Now days market booming with the IoT. Internet of Things is the extended form of internet. Real world is connected through virtual world. In an era of electronics based civilization there is always a demand for more better,cheaper and faster electronics devices. These are the key points for the IoT based products development. Main feature of IoT based product is to give remote access of device to the user. Even device which is controllable from Bluetooth is also a IoT device. The end to end form of IoT make that device controllable from any corner of the world.

How to step in IoT market ?

Product design Flow:
Design and Specification finalization:
The very first step in product development is to define aspects and specification of product which can not be change through the end of production. If their is any changes in product it can only reflect in phase 2 or version 2 of product.
 Ex. I am thinking of designing box which having WiFi connectivity and control home equipment from any where in world. 

Specifications: 
*device for consumer application
*costing of product manufacturing and selling
*small box,nice color,LED indications,proper terminals for external connections, having 5v power supply
*WiFi connectivity
*controls 3 equipment. you can make variant of same device based of capacity of handling equipment.

Prototyping and Development phase:

*Hardware : 
Hardware is directly related with costing of product. Its very necessary to choose proper hardware that can satisfy device working needs. Its wast of money to choose higher end processors and Industrial grade hard ware because we are developing Consumer Electronics device.

*Software :
For reducing development cost here we have to choose mostly free ware development tools and compilers mostly GCC considering GNU licenses or IDE like Arduino is ok.
need to read some of the license documents like if you use Arduino in product development.
 http://www.postscapes.com/forum/arduino/47-if-arduino-is-for-prototyping-how/when-do-you-make-the-actual-product/

Selection:
doing some market survey I choose cheap WiFi module ESP8266 which can work with Node MCU. It reduce my need of any other micro controller to be used. And ESP8266 can program easily with free tool provided my manufacturer.

Validation Phase:
This is step after product design cycle. Design that was finalized in the lab for testing, to ensure that all products specifications are met. Required certification should be obtained for product, depending on where it is going to be launch.

Validation :
depends on your region like here in India we have to certify our products with ISI mark.




Production phase:
Its time to turn your prototype into product. In this phase we have to introduce some third party suppliers for manufacturing PCB,Component soldering,device housing and packing. following points should be considering while allocating third part suppliers.
*go with reliable vendors.
*make proper agreements and  legal documents.
*consider Time to Market then negotiate with vendors.
*before giving direct order demand for samples.
*consider cost of manufacturing.

Sales and marketing:
Without knowing you no one is going to buy your product here marketing helps you. reach to your customer and market your product.
*Online marketing is easy way to reach customers.
*Make proper website with product descriptions.
*Sell on online websites like amezon and ebay.
Published: By: DK - 13:46

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

      1 February 2017

      ESP 8266 OTA(Over The Air) Update Firmware Demo :

       


      My friend Sanket encourage me to do some stuff on ESP8266OTA.
      No need of wire to upload Arduino sketch in ESP8266. OTA give you advantage of uploading sketch or upgrade firmware over the WiFi without any wired connection.
      *Program uploading is Faster than regular arduino upload.

      Requirement:
      1) Go through previous tutorials of ESP8266on my blog
      2) ESP8266

      3) python27 installed on System from where your going to upload firmware.\

      Step 1:
      Download The library and tools required for OTA click here

      Step 2:
      Extract downloaded file and install arduino OTA library in Arduino IDE.

      Step 3:
       Complile and Upload following sketch in ESP by our regular method through serial terminal. Its necessary to upload first time sketch with OTA suppot.
       #include < esp8266wifi.h >
      #include < esp8266mdns .h >
      #include < wifiudp .h >
      #include < arduinoota .h >

      const char* ssid = "WIFI ROUTER NAME";
      const char* password = "WIFI ROUTER PASSWORD";

      void setup() {
        Serial.begin(115200);
        Serial.println("Booting");
        WiFi.mode(WIFI_STA);
        WiFi.begin(ssid, password);
        while (WiFi.waitForConnectResult() != WL_CONNECTED) {
          Serial.println("Connection Failed! Rebooting...");
          delay(5000);
          ESP.restart();
        }
        ArduinoOTA.onStart([]() {
          String type;
          if (ArduinoOTA.getCommand() == U_FLASH)
            type = "sketch";
          else // U_SPIFFS
            type = "filesystem";

          // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
          Serial.println("Start updating " + type);
        });
        ArduinoOTA.onEnd([]() {
          Serial.println("\nEnd");
        });
        ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
          Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
        });
        ArduinoOTA.onError([](ota_error_t error) {
          Serial.printf("Error[%u]: ", error);
          if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
          else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
          else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
          else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
          else if (error == OTA_END_ERROR) Serial.println("End Failed");
        });
        ArduinoOTA.begin();
        Serial.println("Ready v1.0"); //Change version for every new modification in firmaware
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());

        pinMode(2,OUTPUT);
      }

      void loop() {
        ArduinoOTA.handle();
        digitalWrite(2,HIGH);
        delay(500);
        digitalWrite(2,LOW);
        delay(500);
      }



      Step 4 : 
      Now your ESP8266is ready for OTA support.
      How to test OTA is working ?
      first you need new firm ware file OTA support two types of file i.e 1) .bin, 2 ) SPIFF
      Here we are dealing with only .bin file.

      modify above sketch withc some changes like
      Serial.println("Ready v2.0"); //Change version for every new modification in firmaware
      .

      void loop() {
        ArduinoOTA.handle();
        digitalWrite(2,HIGH);
        delay(2000);
        digitalWrite(2,LOW);
        delay(2000);
      }

      here we change version of firmware and make some changes in program. That can be reflect after OTA update.


      Now only Verify/Compile program in Arduino IDE do not Upload.

      goto run > %temp% in temp folder find out your arduino build folder

      Locate build folder
        
      Locate .bin file 

       

      copy .bin file path which is use in espota tool.

      Step 5:
       Now prepare system which can access ESP8266in network.
      In download rar file you will find espota.py script that can upload firmware in esp.

      Open command prompt in espota.py file location by pressing shift key and right click > open command window here.

      give this command
      python espota.py -i 10.19.30.40 -p 8266 -f "C:\User\INDIA\AppData\Local\\Temp\builda0eb11f6003a2bd55895c96acd777afe.tmp\BasicOTA.ino.bin" -d -r

      firmware upgradation will start

       

      You can observe blinking speed of LED get changed.

      If you have any questions please comment below.
      Thank You.
      Published: By: DK - 04:27