Friday, April 29, 2016

Control Devices by Voice Recognition

This post will serve questions like, How to control devices by voice commands , speech recognition available in android.

All the android devices comes with the inbuilt speech recognition. This can be used to convert speech to text, by calling bluetooth function these text can be sent to device in this case the text were transferred to an arduino. The app can made with ease in MIT app inventor Without any experience in programming. 
If you are looking to control devices by your voice, this is the best post for you. MIT app inventor provides space to make android app by building blocks. you can control all your gadgets robots and this app will be perfect for your home automation and control projects. 

How to control Electrical appliances from android mobile

Hi , do you want to control all your electrical devices at your home controlled from your android mobile, do you want to create your own app to achieve this task, This post explains step by step procedure to create android app for controlling electrical appliances using MIT app inventor. you don't need to rely on 3rd party to control your home devices. This simply act as a Home automation where you can control everything from your phone. all you need is an android phone , an arduino , bluetooth module ( I've used HC-05) and a Relay.

You don't need to use particularly arduino to make this project, you can use any micrcontroller to make this project. I've controlled only 3 devices for this project, it can be extended to many devices. all you need to do is create extra buttons in the app and have more I/O's in the microcontroller side. I used Arduino because there are many shields available for this particular controller in the market and more tutorial and community to help you out. 



check the link for transfer of android apps to your phone here



Arduino Program
____________________________________________________________________________________

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); //TX, RX respetively
String device;

void setup() {
 BT.begin(9600);
 Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);


}
//-----------------------------------------------------------------------// 
void loop() {
  while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable
  char c = BT.read(); //Conduct a serial read
  device += c; //build the string.
  } 
  if (device.length() > 0) {
    Serial.println(device);

  if(device == "doneon")
  {
    digitalWrite(3, HIGH);
  }

  else if(device == "doneoff")
  {
    digitalWrite(3, LOW);
  }

  else if (device == "dtwoon")
  {
    digitalWrite (4,HIGH);
  }

 else if ( device == "dtwooff")
 {
   digitalWrite (4, LOW);
 }

 else if (device == "dthreeon")
 {
   digitalWrite (5, HIGH);

 }

 else if (device == "dthreeoff")
 {digitalWrite (5, LOW);}

device="";}} //Reset the variable

How to Make android app for controlling RGB LED



Here's a step by step tutorial for controlling an RGB LED from android mobile using android app created with the help of MIT app inventor.

This example is simple easy to do android app with the help of MIT app inventor to use with arduino. this will serve the newbie and novice who wants to play with android and arduino. without going much deeper in the programming side.

We all start with microcontroller by lighting some LED's. Here we going to light up an RGB LED through arduino. 

what are the components we need to achieve this? 
arduino uno or any other microcontroller
Bluetooth Module (HC-05)
RGB LED.
Anroid Phone.
check this post here to know How to transfer MIT app to your mobile phone.
Arduino Program
_____________________________________________________________________________________

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); //TX, RX respetively
String color;

void setup() {
 BT.begin(9600);
 Serial.begin(9600);
  pinMode(2, OUTPUT); // blue
  pinMode(3, OUTPUT); // green
  pinMode(4, OUTPUT); // red

}
//-----------------------------------------------------------------------//  
void loop() {
  while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = BT.read(); //Conduct a serial read
  color += c; //build the string- "blue, red and green"
  }  
  if (color.length() > 0) {
    Serial.println(color); 

  if(color == "blue") 
  {
    digitalWrite(2, HIGH);
    digitalWrite (3, LOW);
    digitalWrite(4,LOW);
    delay(20);
  } 
  
  else if(color == "green") 
  {
    digitalWrite(2, LOW);
    digitalWrite (3, HIGH);
    digitalWrite(4,LOW);
    delay(20);
  }
  
  else if (color == "red")
  {
    digitalWrite(2, LOW);
    digitalWrite (3, LOW);
    digitalWrite(4,HIGH);
    delay(20);
    
  }
  
    else if (color == "stop")
  {
    digitalWrite(2, LOW);
    digitalWrite (3, LOW);
    digitalWrite(4,LOW);
    delay(20);
    
  }
  
  
color ="";}} //Reset the variable

Course on MIT app inventor Arduino



I have made many tutorials for creating apps using MIT app inventor and connected the app with arduino to make things work, I often get email stating something went missing when they follow my tutorial, Here's a step by step tutorial on getting started with creating MIT app inventor and control things with arduino. To complete this tutorial you need a Bluetooth module HC-05 or HC-06 to connect with arduino and send or receive data to and from other Bluetooth device. 
Lets Make our first app to control an LED
              Can make their own app and control a LED connected to arduino without any prior experience, if they have components with that's more enough to make this tutorial. Blinking an LED is the first thing we do when we getting started with electronics in this tutorial you will TURN ON and TURN OFF the LED, this is the Hello world example in this tutorial, you don't need any prior coding experience to make this application work. To test the app that created during this tutorial, you need an Android mobile or android supported devices to test your app. creating an app with MIT app inventor is very simple, you won't be doing any coding process during creating your app, you will be assembling blocks together to make your app. if you don't have any prior experience with Arduino control, make sure you follow some basics like connecting Arduino to your computer and upload example code to Arduino from Arduino IDE, this would be more sufficient to follow this tutorial.  
-------------------------------------------------------------------------------------------------------------------------- 
#include <SoftwareSerial.h>
String state;// string to store incoming message from bluetooth
void setup() {
  Serial.begin(9600); // serial communication started
  pinMode(13, OUTPUT); // LED connected to 13th pin


}
//-----------------------------------------------------------------------//  
void loop() {
  while (Serial.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = Serial.read(); //Conduct a serial read
  state += c; //build the string- either "On" or "off"
  }  
  if (state.length() > 0) {
    
  if(state == "on") 
  {
    digitalWrite(13, HIGH);
    
      } 
  
  else if(state == "off") 
  {
    digitalWrite(13, LOW);
     }

state ="";} //Reset the variable
}
 2. Android Arduino Speech recognition app.  
In this tutorial you will know how to create a speech recognition app that will convert your speech to text and send command to your arduino and do certain task that matches your command, you don't have any control over the speech to text conversion process, it is entirely depend on the google speech to text conversion engine, we will be making use of the speech to conversion process in this app, when the process of getting converting the text is over we will be sending the converted command to Arduino. You also need internet connectivity to do this process because google speech to conversion engine depends on Internet connectivity to do this you cannot do this process offline, you need to be connected with internet when following and working this tutorial. once you complete this app you can use this for many applications including Home Automation, Controlling a Bluetooth robot, sending voice command to do a process there are many possibilities with this application. The same hardware what you have created previous tutorial is enough for this tutorial you don't need to change your hardware connection to make this work. keep your hardware same connect this app to your arduino and start to send your command.
3. Servo Motor control using Arduino and Android  
In this tutorial you will be creating an app for controlling a servo motor, you will be using slider in your app to move your servo from 0-180, You need a servo motor to be connected on arduino side, make sure you also connecting external powersupply so that your Arduino will not restart during this process,
 --------------------------------------------------------------------------------------------------------------------------
#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library 
Servo myservo; // servo name

int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  myservo.attach(9); // attach servo signal wire to pin 9
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()> 0 ) // receive number from bluetooth
  {
    int servopos = bluetooth.read(); // save the received number to servopos
    Serial.println(servopos); // serial print servopos current number received from bluetooth
    myservo.write(servopos); // roate the servo the angle received from the android app
  }


}
4. Make a Android Arduino Robot  
In this tutorial you will be learning on how to make an app for controlling an robot by android app, you will be using android phone as remote controller to control the robot. You need 2 gear motor with wheels A motor driver, you can use any of the motor driver you want, I used L293D motor driver for this project. You also need a battery and connecting wires, apart from that as usual a Bluetooth and Arduino board is needed to complete this tutorial. 

-------------------------------------------------------------------------------------------------------------------------- 
#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); //TX, RX respetively
String readdata;

void setup() {
 BT.begin(9600);
 Serial.begin(9600);
  pinMode(3, OUTPUT); // connect to input 1 of l293d
  pinMode(4, OUTPUT); // connect to input 4 of l293d
  pinMode(5, OUTPUT); // connect to input 3 of l293d
  pinMode(6, OUTPUT); // connect to input 2 of l293d

}
//-----------------------------------------------------------------------// 
void loop() {
  while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable
  char c = BT.read(); //Conduct a serial read
  readdata += c; //build the string- "forward", "reverse", "left" and "right"
  } 
  if (readdata.length() > 0) {
    Serial.println(readdata); // print data to serial monitor
// if data received as forward move robot forward
  if(readdata == "forward") 
  {
    digitalWrite(3, HIGH);
    digitalWrite (4, HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    delay(100);
  }
  // if data received as reverse move robot reverse

  else if(readdata == "reverse")
  {
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(6,HIGH);
    delay(100);
  }
// if data received as right turn robot to right direction.
  else if (readdata == "right")
  {
    digitalWrite (3,HIGH);
    digitalWrite (4,LOW);
    digitalWrite (5,LOW);
    digitalWrite (6,LOW);
    delay (100);
   
  }
// if data received as left turn robot to left direction
 else if ( readdata == "left")
 {
   digitalWrite (3, LOW);
   digitalWrite (4, HIGH);
   digitalWrite (5, LOW);
   digitalWrite (6, LOW);
   delay (100);
 }
 // if data received as stop, halt the robot

 else if (readdata == "stop")
 {
   digitalWrite (3, LOW);
   digitalWrite (4, LOW);
   digitalWrite (5, LOW);
   digitalWrite (6, LOW);
   delay (100);
 }

  


readdata="";}} //Reset the variable

-------------------------------------------------------------------------------------------------------------------------- 
5. Know your Home Temperature and Humidity creating an Android app 

There are many app and widget floating market for knowing outside temperature and humidity, but there are no app that can provide your Temperature and Humidity inside your home, by creating this app you can retrieve temperature and humidity data from arduino. 
By following the above tutorial you can make your own app that display temperature and humidity data as well as this app will make you hear what is the current temperature and humidity at your home. for this project I used DHT11 sensor with arduino to export temperature data to my android app, similarly you can use any Temperature sensor like DHT22 or DHT23 or DHT33 or one wire ds180b20 type of sensor can be used to replicate the same project. 
6. Android Arduino Speech recognition bot.
This app combines tutorial 2 and 4 to make a new project, as we discussed earlier that speech to text conversion app can be used for many projects, this is one of the application of that app, we using the same for the robot we created during our 4th lesson. This follows same hardware and all the codes are same make the robot and have fun. 
if you had so much during all your learning and want to explore additional things you can check the book here
please leave your suggestion and queries to this mail id periyeriveeramaniayya7@gmail.com
Thanks for stopping by. 

Thursday, April 28, 2016

RGB Slider Color Selector RGB LED | Android and Arduino

This post is about choosing color for the RGB LED light from the android app, I used slider to control the LED colors.
Circuit Diagram for common anode RGB LED:

Circuit Diagram for common cathode RGB LED:


components needed for this project:
Arduino Uno
RGB LED
Bluetooth Module
Connecting Wires
Breadboard 

Android app created using MIT app inventor, which is very simple, 3 sliders had created to assign values of primary colors RGB, when these sliders are moved these different colors are mixed and shown in the canvas, same color code will be send to the arduino. 

Android app: 

android app can be download from this link

Blocks to create Android app:








Arduino Program to control Common anode LED: 

#include <SoftwareSerial.h>

int bluetoothTx = 7;
int bluetoothRx = 8;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(3,OUTPUT); // blue pin of RGB LED
 pinMode(5,OUTPUT); // Green pin of RGB LED
 pinMode(6,OUTPUT); // Red pin of RGB LED

 digitalWrite(3,HIGH);
 digitalWrite(5,HIGH);
 digitalWrite(6,HIGH);
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255){
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    int blue1 = 255-blue;
    analogWrite(6,blue1);
    Serial.println(blue1);
    delay(10);

    }
   
    if (color >=2000 && color <2255){
      int green = color;
      green = map(green,2000,2255,0,255);
      int green1 = 255 - green;
      analogWrite(5,green1);
      Serial.println(green1);
      delay(10);
     
    }
   
    if (color >=3000 && color < 3255){
      int red = color;
      red = map(red, 3000, 3255,0,255);
      int red1 = 255 - red;
      analogWrite(3,red1);
      Serial.println(red1);
      delay(10);
    }
   

  }


}


Arduino program for common cathode RGB LED:

#include <SoftwareSerial.h>

int bluetoothTx = 7;
int bluetoothRx = 8;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(3,OUTPUT); // blue pin of RGB LED
 pinMode(5,OUTPUT); // Green pin of RGB LED
 pinMode(6,OUTPUT); // Red pin of RGB LED

 digitalWrite(3,LOW);
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255){
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    analogWrite(6,blue);
    Serial.println(blue);
    delay(10);

    }
   
    if (color >=2000 && color <2255){
      int green = color;
      green = map(green,2000,2255,0,255);
      analogWrite(5,green);
      Serial.println(green);
      delay(10);
     
    }
   
    if (color >=3000 && color < 3255){
      int red = color;
      red = map(red, 3000, 3255,0,255);
      analogWrite(3,red);
      Serial.println(red);
      delay(10);
    }
   

  }


}