Dhananjay Khairnar @. Powered by Blogger.

26 December 2016

ESP8266(Arduino) interface with Firebase:


 Make such application in which LED can be control from mobile or website from any remote location where internet connectivity is available.

1 ) ESP8266-E12 WiFi module as shown in picture. You can get start and setup it with help of this post.
2) Download and install firebase-arduino-master  library in Arduino IDE.
3) Need gmail account for create Firebase project.

Step 1:
Go to https://console.firebase.google.com and create new project.

Step 2:
Click on Database now you will see the host name show in image

Copy that host name and past in Arduino code given below at line
 #define FIREBASE_HOST "fir-app-example.firebaseio.com"

Step 3:
Go to Setting>Project Setting>SERVICE ACCOUNTS>DATABASE Secretes.
Copy "Database Secrets" Shown in below image


Copy and paste Database Secrets at the line in code 
#define FIREBASE_AUTH "examplesd2asdasdasdasd2asd3asd2asd2as32das3d2as2da3" 

Step 6 :
Change line with your WiFi router name and password
#define WIFI_SSID "Wifi Router Name"
#define WIFI_PASSWORD "Router Password"

Step 5:
Download following code in arduino


// Set these to run example.
#define WIFI_SSID "Wifi Router Name"
#define WIFI_PASSWORD "Router Password"

#define LED 2

void setup() {

  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("connected: ");


void loop() {
  if (Firebase.failed())  // Check for errors
      Serial.print("setting /number failed:");

Step 6:
After reseting ESP8266check serial terminal whether the ESP is get connected with your router and got IP adress.
you can now see the new variable created in database. 

Step 7:  
Double click "LEDStatus" and edit it to 1. instantly (its depends on your internet connection) LED on ESP 8266 module get Turn off.

Step 8: 
If you have knowledge of Android you can create App for control LED from mobile. You need to read Firebase documentation and integration methods.

I created my android app for controlling LED from mobile. As Firebase can be assess from world wide so you have end to end IoT application.

For any question comment below. Thank You.
Published: By: DK - 07:15

14 December 2016

JHD12864E interfacing with Arduino Uno( 128x64 Bit MAp Graphics LCD) :

Requirement :
1 ) JHD12864E LCD
2 ) Arduino
3 ) Connecting wires

Aim: Convert and display JPEG image on Graphics LCD as Bitmap image

Step 1 : 
Download and put Glcd library in Documents/Arduino/library folder
GLCD library

Step 2 :
Download BMP-To-LCD software to convert JPEG image to BMP array

Step 3:  
Make connection of LCD to Arduino UNO as shown in figure.

Step 4:
 Download any image from internet.

Step 5: Open image in Paint

Step 6:

Step7 :


Step 8:

Step 9: 
Click on resize without selecting area

Step 10: 
Save image as 1.bmp 

Step 11 : open Image in BMP-LCD software

And click on Genarate code

Copy that genarated code in Arduino sketch

Step 12: Copy Paste code in bitmaps.h with some modification as shown in below image

Main sketch is as shown below image 

You can download it from here Arduino_GLCD_Sketch.rar

If You have any question comment below.

Published: By: DK - 06:21

29 November 2016

Download English Dictionary words for Microcontroller based Text to Speech (TTS) convertor:

What is TTS?
Speech synthesis is the artificial production of human speech. A computer system used for this purpose is called a speech computer or speech synthesizer, and can be implemented in software or hardware products. A text-to-speech (TTS) system converts normal language text into speech; other systems render symbolic linguistic representations like phonetic transcriptions into speech.
Basic architecture is explained in following block diagram.
Microcontroller feed with text data from any interface . microcontroller make tokens of that string into and compare appropriate soud file per word from data bases. After getting all index of each word of string micro controller play sound files one after another with proper delay in words.

As per post title I am going to use Python script to make my own speech files database(format in mp3).

Prerequisite :
1) Installed python 2.7 ( Download and install from https://www.python.org/download/releases/2.7/)
2) Internet

Step 1:
locate Python27\Scripts director

install requred python packages

press and hold shift key and rigth click > click open command window here

in command prompt type and enter

pip.exe install wget

this is package used by our script to download .mp3 files from internet

Step 2:

We are going to download all our .mp3 file from google database.
we need to replace “hello.mp3” with our word that we want to download.

Step 3:

Here I used the file words.txt that contains daily used English words. We take each word from file and replace in base URL to download it.

download this this file and keep it in same directory where following script is placed.

Step 4:

create new text file, copy and paste following code in it. Rename that file as script.py

import wget
import os
import os.path

with open("words.txt", "r") as ins:

def chomp(x):
if x.endswith("\r\n"): return x[:-2]
if x.endswith("\n"): return x[:-1]
return x[:]

for line in ins:
if False==os.path.isfile(line):
print "new file added\n"
file_url = "https://ssl.gstatic.com/dictionary/static/sounds/de/0/"
print file_url
file_name = wget.download(file_url)
else :
print "file exist"

open command prompt from director of script and run script as

> python script.py

Step 6:

Download will take time as their is load of words in text file. you can reduce them as per your requirement.

Now you have you mp3 database for text to speech converter. I have working prototype for it using microcontroller.
If you have any question please comment below or contact me.
Published: By: DK - 04:03

10 November 2016

Raspberry pi 3 kernel module compilation:


Raspberry pi 3 kernel module compile :

Step 1:
Update current kernel

$sudo apt-get update

$sudo apt-get upgrade

$sudo apt-get install bc

$sudo apt-get install gcc

Step 2:
Download linux headers for current kernel version

$uname -r

copy kernel version

and goto url https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/ and find your kernel version
here in my case
linux-headers-4.4.26-v7+_4.4.26-v7+-2_armhf.deb    20-Oct-2016 21:07             6891064

Download it

Now install the downloaded inux headers.

$sudo dpkg -i linux-headers-4.4.26-v7+_4.4.26-v7+-2_armhf.deb

it takes while let it be complete without interrupt process.

Step 4 :

$mkdir kmod

$cd kmod

$sudo nano hello-1.c

copy and past following programe in file then save it [^X]

/*hello−1.c − The simplest kernel module.*/
#include < linux/init.h >             //linux/init.h Macros used to mark up functions e.g., __init __exit
#include < linux/module.h >           //linux/module.h Core header for loading LKMs into the kernel
#include < linux/kernel.h >           //linux/kernel.h Contains types, macros, functions for the kernel

int init_module(void) 
    printk(KERN_INFO "Hello world 1.\n");
    /*A non 0 return means init_module failed; module can't be loaded.*/
    return 0;

void cleanup_module(void)
    printk(KERN_INFO "Goodbye world 1.\n");

Now for compile this module we need make file
$sudo nano Makefile

copy and past following code in make file

obj-m += hello-1.o

    make -C /lib/modules/4.4.26-v7+/build M=/home/pi/kmod modules
    make -C /lib/modules/4.4.26-v7+/build M=/home/pi/kmod clean

remember the there is Tab before make.

Save it

Step 5:

compile our hello world module

$sudo make
make -C /lib/modules/4.4.26-v7+/build M=/home/pi/kmod modules

make[1]: Entering directory '/usr/src/linux-headers-4.4.26-v7+'

CC [M] /home/pi/kmod/hello-1.o

Building modules, stage 2.

MODPOST 1 modules

CC /home/pi/kmod/hello-1.mod.o

LD [M] /home/pi/kmod/hello-1.ko

make[1]: Leaving directory '/usr/src/linux-headers-4.4.26-v7+'

Step 6:
insert module into kernel
$sudo insmod hello-1.ko

if there is noerror then your module get successfully installed

Step 7:
to verify it
$sudo dmesg

You get following result 

now to remove module 

$sudo rmmod hello-1.ko

to verify

$sudo dmesg

you see the kernel log as follows


Thank You . if you have any question comment below or email me.

Published: By: DK - 07:49

19 October 2016

2.4 Ghz channel scanner using NRF24L01 RF Transreceiver :

What is 2.4Ghz scanner:
My requirement behind this project is I want to make such device which can sniff 2.4Ghz ISM frequency band. But after some research its bit hard and trick to make such device. But I figure it out to made such a device which can locate the particular channel on which data is transmitted. their are some ready made examples for Arduino but none of with GUI that can be easy to understand. here I developed GUI base 2.4GHZ channel scanner( NOT SNIFFER :( ).
Here I used channel range from 1 - 126 means  NRF2401 having frequency range of 2.4Ghz - 2.529GHz which can be divided in 126 channels each one of 1Mhz. so if you want to find wifi channel frequency for particular standard you need to map NRF2401 channel with the standard channel. see the standard 802.11b/g/n below and map 2.4Ghz - 2.529GHz = 1 - 126 with this range

Required :
1) Arduino
2) NRF24L01
3) Microsoft Visual Studio 2015

Screen Shots and Explanation:
 Start NRF 2.4Ghz Channel Scanner application and attach arduino to your computer. You will see active COM port in application here I got "COM8" . Select baud rate 9600.
Step 2:
Now initialize communication with hardware by click on Init button

 application start communication with hardware. hardware send data and application arrange it channel wise. For testing purpose here i used simple RC plane Controller to find out which channel it use to broadcast its request package further I will work to extract data from its packet.

Step 3:
Whene the Controller switch is off the data chart is like this

Step 4:
Now Switch on Controller but without switching on receiver.

LED of controller start blinking means it start broadcast packet to find receiver

Step 5:
After some time Arduino send data which carrier signal is detected by it. The signal chart looks like this


In this image see the channel number 82,83,84 and 85 the scanner sense the carrier signals thats mean the RC controller sending request on these four channel ( The color indication :Dark is more packet strick).

Step 6:
Now test on some other RF devices here I used Bluetooth which also work on 2.4 Ghz band range.
See the diagram below put module in between two mobile which currently exchanging data. I send Mp3 file form one mobile to other . the result I get shown in Image

Result of this experiment as follows

If you want to go to deep of Bluetooth need to learn FHSS which does not use single channel to transmit data it. so here data sense at number of channel.
I am looking forward to make 2.4Ghz sniffer.  

If have any question please comment below or email me.

Published: By: DK - 08:19

8 October 2016

Working on scrolling display:

From long time I wish to have my own LED scrolling display now I got some time to work on it.
 Here some Photo of it working on simple LED scrolling display.
Further extension of this module is fetch Facebook notification using wifi and display on scrolling LED display and using Bluetooth display mobile messages on it.  ;).

Day1 :

Day 3:

Published: By: DK - 04:28

27 September 2016

ESP8266 AT firmware : 

As in previous post we have seen ESP8266 as stand alone but some time in some application we need only WiFi connectivity or simple WiFi module that can be controlled through AT commands. we can program ESP8266 for work on AT command.

1) ESP8266
3) USB to serial convertor

Step 1: 
Setup ESP8266 as given in this post.

Step 2:
 Download ESP8266 AT command firmware by AI Thinker.

Step 3:
press and hold Flash button(GPIO0 = GND) then press Reset button(RESET pin = GND)
release RESET button then Flash button now ESP8266 goes into Flash mode.

Step 4:
Extract downloaded rar file.
Step 5:
open "flash.cmd"  file and wait for complete flashing process.


Step 6: 
Setup local Server for receive data. I use TCPClientServe software which allow you to create local server and client to send and receive data over TCP
Download Here

 Enter port 6000 and start listening.

Step 7 : 
Open Serial terminal at baudrate 115200
Give Comman Sequence To send data to Server

1) AT
2) AT+CWAUTOCONN=0  ---> disable autoconnection
3) AT+CWMODE=1 ---> set station mode
4) AT+CWJAP="MyRouter","MyRouterPassword" --->connect to local WiFi router
5) AT+CIPSTA_DEF="" ---> set static IP
6) AT+CIPSTART="TCP","",6000 --->your local server IP adress
7) AT+CIPSEND=10 --> number of bytes to send
8) 12345678 ---> actual data to send

Console Output:

 Ai-Thinker Technology Co.,Ltd.











Recv 10 bytes


Published: By: DK - 04:03

Fetch and parse JSON on ESP8266 wifi module :

Use case:
 I want monitor particular json stored on server which can be modify by website from remote distance.
It can be useful where you can modify control bits from website and change GPIO status at ESP8266 side.

1) Home automation
2) Information parsing
3) Staus monitoring
4) non realtime notification

This system work on principle on monitoring files.

Feature :
  Stand alone operation of ESP8266.
  Uses JSON parsing so data extraction is very easy.

Required :
2)Arduino or any USB to serial converter with 3.3v or 5v power connection pin out.

Basic Working:
  • ESP8266 : 
It uses the local router to connect internet and fetch JSON from server using HTTP get request after every second parse it and display JSON variables on serial monitor(you can compare them and change GPIO for device control).

Shown in diagram it send GET request at server and server send back HEADER + JSON to ESP8266
HTTP request :
 client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host:" + host + "\r\n" +
                "User-Agent:Mozilla/5.0(Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0" +
                "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" +

 Server Responce:
HTTP/1.1 200 OK
Vary: Host,Accept-Encoding
P3P: CP="Not supported"
Set-Cookie: _xta_uid=4945816047688c1c34e113b0f9c163b0; expires=Thu, 27-Sep-2018 06:01:09 GMT; Max-Age=63072000; path=/; domain=.mobie.in; httponly
Content-Type: text/plain;charset=UTF-8
Content-Length: 530
Accept-Ranges: bytes
Date: Tue, 27 Sep 2016 06:01:17 GMT
X-Varnish: 644140890
Age: 0
Via: 1.1 varnish
X-Robots-Tag: Crawl-delay: 10

   "id": 1,
   "name": "Leanne Graham",
   "username": "Bret",
   "email": "Sincere@april.biz",
   "address": {
     "street": "Kulas Light",
     "suite": "Apt. 556",
     "city": "Gwenborough",
     "zipcode": "92998-3874",
     "geo": {
       "lat": "-37.3159",
       "lng": "81.1496"
   "phone": "1-770-736-8031 x56442",
   "website": "hildegard.org",
   "company": {
     "name": "Romaguera-Crona",
     "catchPhrase": "Multi-layered client-server neural-net",
     "bs": "harness real-time e-markets"

to separate only data and neglect header i used
    line = client.readStringUntil('\r');

this code store data in 'line'  untile received data ends with '\r' ,
we received data as  [ header + \r\n\r\n + data(json) + \r\n\r\n ]
so first instance "line" contain header, As next data received "line" override with data(json).

 this data is given to the JSON pacer along with user define structure to store in local variables.
  • Server :
          Stores the html page, json file and jsp scripts. Server gives access to the ESP8266 and remote client. Server can execute the jsp script as per remote client request to modify JSON file. this is not implemented yet.
  •  Remote Client : 
         Can access webpage that contain control panel or GUI for modify JSON file as per requirement here in this tutorial I have not implemented this.

Step 1:
Follow this post to setup ESP8266 programming environment with Arduino IDE.

Step 2 :
Register at any free web hosting site  or you can have your own domain or you can test it with your local server.
I used http://xtgem.com to host test.json file.
Register -
Create New Site - here i created "codersmagic.mobie.in"

Step 3:
Create JSON file
for create json file you can use any online json creator. Past json data in simple txt file and rename it as JSON.

Note : before save json file confirm that it don't contain any hidden '\r' in it.  '\n' is ok.

Here I used Notepad++ to replace '\r' with non-value means erase all '\r'
 save test.json file.

Step 4 :
Goto xtgem.com > login > click on your site > upload test.json file to '/' root directory
 here I alredy uploaded JSON file.
confirm that json file is accessible in web browser from URL given in right side corner link.

Step 5: 
 Downlod Arduino json parsing librabry from given url https://github.com/bblanchon/ArduinoJson . install it in Arduino IDE from Sketch > include library > Add .ZIP library...

Now upload following sketch in ESP8266.


const char* ssid     = "MyRouter";
const char* password = "MyRouterPassword";

const char* host = "codersmagic.mobie.in";
const int httpPort = 80;
char charVar[15];

struct UserData {
  int id;
  char name[32];
  char username[32];
  char email[32];
          char street[32];
          char suite[32];
          char city[32];
          char zipcode[32];
                 char lat[10];
                 char lng[10];
  char website[32];
  char company[32];

UserData userData;

void setup() {

  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

void loop() {
  String line;
  Serial.print("connecting to ");

  // Use WiFiClient class to create TCP connections
  WiFiClient client;

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");

  // We now create a URI for the request
  String url = "/test.json";

  Serial.print("Requesting URL: ");

  // This will send the request to the server.
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host:" + host + "\r\n" +
                "User-Agent:Mozilla/5.0(Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0" +
                "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" +
  // Read all the lines of the reply from server and print them to Serial
    line = client.readStringUntil('\r');
   // Serial.print(line);
  Serial.println("----------------------JSON PARSER-------------------------");

  char* charBuf = (char*)malloc(sizeof(char)*1024);  //dynamic memory allocation avoid most of ESP watch dog exeptions
      if (parseUserData(charBuf, &userData)) {
  free(charBuf); // remember to free dynamic memory

  Serial.println("closing connection");

bool parseUserData(char* content, struct UserData* userData) {
  // Compute optimal size of the JSON buffer according to what we need to parse.
  // This is only required if you use StaticJsonBuffer.
  const size_t BUFFER_SIZE =
      JSON_OBJECT_SIZE(8)     // the root object has 8 elements
      + JSON_OBJECT_SIZE(5)   // the "address" object has 5 elements
      + JSON_OBJECT_SIZE(2)   // the "geo" object has 2 elements
      + JSON_OBJECT_SIZE(3);  // the "company" object has 3 elements

  // Allocate a temporary memory pool on the stack
  StaticJsonBuffer jsonBuffer;
  // If the memory pool is too big for the stack, use this instead:
  // DynamicJsonBuffer jsonBuffer;

  JsonObject& root = jsonBuffer.parseObject(content);

  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  //root.prettyPrintTo(Serial);   //print raw JSON data
  // Here were copy the strings we're interested in
  userData->id = root["id"];
  strcpy(userData->name, root["name"]);
  strcpy(userData->username, root["username"]);
  strcpy(userData->email, root["email"]);
  strcpy(userData->address.street, root["address"]["street"]);
  strcpy(userData->website, root["website"]);
  strcpy(userData->company, root["company"]["name"]);
  // It's not mandatory to make a copy, you could just use the pointers
  // Since, they are pointing inside the "content" buffer, so you need to make
  // sure it's still in memory when you read the string

  return true;

void printUserData(const struct UserData* userData) {
  Serial.print("id = ");
  Serial.print("Name = ");

  Serial.print("User Name = ");

  Serial.print("Email = ");

  Serial.print("Adress = ");

  Serial.print("Suite = ");
  Serial.print("City = ");

  Serial.print("Zip Code = ");
  Serial.print("website = ");
  Serial.print("Company = ");
  "id": 1,
   "name": "Leanne Graham",
   "username": "Bret",
   "email": "Sincere@april.biz",
   "address": {
     "street": "Kulas Light",
     "suite": "Apt. 556",
     "city": "Gwenborough",
     "zipcode": "92998-3874",
     "geo": {
       "lat": "-37.3159",
       "lng": "81.1496"
   "phone": "1-770-736-8031 x56442",
   "website": "hildegard.org",
   "company": {
     "name": "Romaguera-Crona",
     "catchPhrase": "Multi-layered client-server neural-net",
     "bs": "harness real-time e-markets"

 Step 6:
 See the serial log for JSON data on baud rate 115200.

Connecting to MyRouter
........WiFi connected
IP address:
connecting to codersmagic.mobie.in
Requesting URL: /test.json

----------------------JSON PARSER-------------------------

id = 1
Name = Leanne Graham
User Name = Bret
Email = Sincere@april.biz
Adress = Kulas Light
Suite = Apt. 556
City = Gwenborough
Zip Code = 92998-3874
website = hildegard.org
Company = Romaguera-Crona
closing connection

some time you get error like
----------------------JSON PARSER-------------------------
JSON parsing failed!

It is due to frequently hinting the same URL, server ignore some request you can adjust delay between two request to avoid this issue. still it is not guaranty that the HTTP response will receive for every request.

If have any question please comment below.

Published: By: DK - 00:33