Tuesday, December 1, 2015

Introduction to Matlab Simulink and Arduino

We can use MATLAB to communicate with an Arduino board using installing the support package for Arduino in MATLAB. If you want to program an Arduino that can  be possible by using Simulink and support package for Arduino should be installed in order to use MATLAB Simulink to program our Arduino boards. The support package wills automatically generate the code from Simulink model that then runs on the arduino board. 



check the above video to know about what is video is series is about , what all you can learn from this video series. 



check the above Video know how to install the support package for Arduino for Matlab where you will be given a details about how to start and where to start, all the information need to get install the package successful has been shown in the above video. 


Set up MATLAB and Simulink support package for Arduino

Start MATLAB
Open MATLAB and click the Add-Ons drop down menu on the top right


Start Support Package Installer
Click on Get Hardware Support Packages in the drop down menu to start the installer. Select
'Install from Internet' as the source for installing the support package





Select Arduino from a list of support packages
Click Next to see a list of support packages and select Arduino from the list for MATLAB Support
Package and Arduino Due for the Simulink Support Package.




MathWorks Account
Click next and log in to your MathWorks account. If you don't have a MathWorks account, you can
create one during the install process



Continue and Complete the Installation
Accept the license agreement on the next screen and click Next through the following screens to
finish the installation for both MATLAB and Simulink Support Package for Arduino.







Sunday, May 31, 2015

Export Temperature data to Thingspeak using ESP8266 and DHT11

Hi all , If you want to make a simple and less cost IOT (Internet Of Things)  which transfer temperature and humidity data to a website and stores your real time data for monitoring , then this post will full fill all your requirement.

All you need for this project is a esp8266 esp-12 WiFi module and a DHT11 temperature and humidity sensor, no need for arduino or any other microcontroller to support this WiFi module for this project , esp8266 esp-12 can work standalone without using a microcontroller to support it.


Step by Step instruction to make this work is explained in the video below:







How to upload nodemcu firmware and other details can be find in the link here

1) Register in Thingspeak.com and create a new channel with 2 fields namely, Temperature and humidity.

2) download the lua program here

3) connect dht11 to the gpio2 of the esp8266 WiFi module.

4) connect esp8266 to your PC

5) extract dht11.rar file that downloaded

6) Open the downloaded file in the Esplorer window

7) Copy the Write key provided from the thingspeak and paste into the dht11.lua program (refer to the video if you are not sure about this)

8) Edit your Wifi SSID and password in the Init.lua Program.

9) Firslty save the dht11.lua to the esp8266 , Secondly save the Init.lua file to the WiFi module.

10) you can check the program successfully uploaded in the esplorer window, once it connected to your Home WiFi network, you can see the IP address assigned to the WiFi module, and you can also see the current temperature and humidity in the Esplorer window.

11) check your channel in the thingspeak.com, you can see the real-time data from your WiFi moudle.





Monday, May 11, 2015

Automating CD Driver Stepper Motor Using IR Sensor





Take a look at this video you know what is project is all about.



I had a CD driver which has not been used for a very long time with me, I removed the case and opened the lens carriage, I thought of using it for a portable plotter before going for the exact idea I wanted to operate the motor automatically with IR sensors , that's how this project was started. It was so much of fun doing this, where you can easily do this project less than $10 if you have arduino with you.



I started it by removing the upper case of the CD driver, which is really easy to do, in the bottom of the driver it had some 4 screws to remove, you don't need to be a professional for doing this kind of job, anyone can do it. 




This lens carriage is the only part that required for this project, apart from this lens carriage there are also a CD Open and closer mechanism and a motor also present inside this CD driver which I can use for some other project. 


If possible remove the stepper motor from the lens carriage, which would allow us to easily solder the stepper motor, or you can also solder without removing it. 



connect the stepper motor to the L293d Motor driver , complete the circuit with the help of the above fritzing .

Arduino Program: 
// I have modified the stepper one revolution program, you can also write your own version for this, programming a stepper with arduino is really easy with the available library, If you are using this project Easy stepper driver Please note this program will not work for it, you need modification for it, please leave a comment , I can also upload the program for easy drive if you really need it.


------------------------------------------------------------------------------------------------------------------------------
#include <Stepper.h>

int motor = 1;

const int stepsPerRevolution = 180;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  int sensor1 = digitalRead(2);
  int sensor2 = digitalRead(3);
  
  if(sensor1 == HIGH && sensor2 == LOW){
    motor = 1;
  }
  
  if (sensor1 == LOW && sensor2 == HIGH){
   motor = 2;}
  
   
    if(motor ==1){
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(5);
  }
  // step one revolution in the other direction:
  else
{
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(5);}
}

--------------------------------------------------------------------------------------------------------------------------------

alternatively you can download the same program here

You can also make your own IR sensor following the video below: 


IR sensors are easily available in all the online electronics and hobbyist shops, you can also make your own IR sensor with just a dollar. 

Sunday, May 10, 2015

Temperature Indicator using LM35, Arduino and display temperature using LCD 16x2


Temperature Indicator is a simple easy to do project, which I did it in less than 10 minutes, If you want to build your own temperature display for your home, you can choose this project, or you can use this project to submit in your school too, to get some extra credit. 

What are the components Used :
1.Arduino
2.LM35 (temperate sensor) very less cost compare to any other temperature sensor
3.LCD 16x2 
4.10k Pot , breadboard and connecting wires.


You can check the above video to know How this circuit works


Arduino Program:

-----------------------------------------------------------------------------------------------------------------------------

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Tempsensor = A0;


void setup() {
  lcd.begin(16, 2);
  pinMode(5, OUTPUT);
}

void loop() {
  
  float temp = analogRead(Tempsensor);
  temp = temp * 0.48828125; // (5*1000)/1024 = 0.48828125
  delay(100);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Temperature");
  lcd.setCursor(0, 1);
  lcd.print(temp);
  lcd.print((char)223); // degree symbol for displaying temperature in arduino LCD
  lcd.print("C");
  delay(200);
}

-----------------------------------------------------------------------------------------------------------------------------


LM35 Pin diagram



Wednesday, May 6, 2015

Automatic Water level controller with Level display on LCD





previously I made an automatic water level controller , you can check this link here, Please check the link which I have given to know more about the detail of this project. This is an upgrade version to the previous one, I've added an LCD display to the project to display the water level.

Arduino Code:

/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Echo to Arduino pin 9 
 Trig to Arduino pin 8*/
 /* LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)*/

#include<LiquidCrystal.h> // include the library code for lcd
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //  
#define echopin  9 // echo pin
#define trigpin 8 // Trigger pin

int maximumRange = 50;
long duration, distance;

void setup() {
  lcd.begin(16,2);
  Serial.begin (9600);
  pinMode (trigpin, OUTPUT);
  pinMode (echopin, INPUT );
  pinMode (4, OUTPUT);
  pinMode (13,OUTPUT);
}
  
void loop ()
{
  {
    digitalWrite(trigpin,LOW);
    delayMicroseconds(2);
    
    digitalWrite(trigpin,HIGH);
    delayMicroseconds(10);
    
    duration=pulseIn (echopin,HIGH);
    
    distance= duration/58.2;
    delay (50);
    Serial.println(distance);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("water level :");
    lcd.print(distance);
    delay(100);
    
  }
  
 if (distance >= 25 ){
   digitalWrite (7,HIGH);// connect to relay(motor)
   digitalWrite (13,HIGH);
   lcd.setCursor(0,1);
   lcd.print("Motor Started");
   delay(100);
 }

 else if (distance <=5) {
   digitalWrite (7,LOW); // connect to relay(motor)
   digitalWrite (13,LOW);
   lcd.setCursor(0,1);
   lcd.print("Tank is full");
   delay(100);
   
 }

}

----------------------------------------------------------------------------------------------------------------------------

Arduino file can be downloaded from this link here

Thursday, April 30, 2015

Esp8266 Control Electrical Devices From your browser.


WiFi web server:

This program connected to the wifi home server that is specified by the user, Once it connected to the homeserver, you can check the IP address assigned to the esp8266 by logging into your WIFI modem and check for the DHCP Clients List. Open a broswer and type in the IP address that your esp8266 has associated with, you will see the webpage returned by the module and wait for the command from the user. 


check the video below to know how to do this project











Make sure you are connecting to the correct pin, whatever the pin number you are assigned in your lua program , the same pin has to be connected with the relay module.check the GPIO table.


Download the nodemcu flasher from here

Download the latest lua firmware from here

Download ESPlorer from here

Download the Lua program here (Make sure you are uploading the file in the name init.lua )


Hi, in this tutorial we will see how to control electrical devices like fan, light, etc., to turn on and off using esp8266 from a web browser. if you are bored with a dedicated device controller like an app or an remote which will be available for only one particular device but using this method all the device which support web browsing will be act as a  controller for us.

Make sure all the devices are connected to the same router, this example doesn't include a port forwarding function which will not allow us to control the device from outside the home network. 

Components that you need for completing this project are very simple, you need to have an esp8266 wifi module and a relay, make sure you buying a 5v relay which very easy to use with esp chips doesn't require external supply too. we can make use of the Vin pin of the nodemcu or if you are using a generic chip, you need to supply an external 5v to the relay.


For this example project I have used only 2 relay circuit, but the actual program wrote for connecting four relay module. 


You can check the above video on how this thing works and how to connect your browser to the ip address returned from esp and all the details are included in this video.





Copy the below arduino code and paste into your Arduino IDE and upload the program to your nodemcu or any other esp devices that you are using, make sure to choose the correct port and device name from the board. also don't forget to change the SSID and password to your Wi-fi settings.

This program for the esp8266 wrote to return the status of the device , which will in turn notify us with the device state in the browser which will also make the user to know which device has currently turned on or off. 

----------------------------------------------------------------------------------------------------------------------------



#include <ESP8266WiFi.h>
 
const char* ssid = "Magesh";
const char* password = "jayakumar";
 
; // 
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  digitalWrite(0, LOW);
  digitalWrite(13, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
 
  if (request.indexOf("/light1on") > 0)  {
    digitalWrite(5, HIGH);
   
  }
  if (request.indexOf("/light1off") >0)  {
    digitalWrite(5, LOW);
   
  }

   if (request.indexOf("/light2on") > 0)  {
    digitalWrite(4, HIGH);
   
  }
  if (request.indexOf("/light2off") >0)  {
    digitalWrite(4, LOW);
   
  }
    if (request.indexOf("/light3on") >0)  {
    digitalWrite(0, HIGH);
   
  }
  if (request.indexOf("/light3off") > 0)  {
    digitalWrite(0, LOW);
   
  }
   if (request.indexOf("/light4on") > 0)  {
    digitalWrite(13, HIGH);
   
  }
  if (request.indexOf("/light4off") > 0)  {
    digitalWrite(13, LOW);
   
  }
// Set ledPin according to the request
//digitalWrite(ledPin, value);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.println("<head>");
  client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
  client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
 client.println("</head>");
  client.println("<body bgcolor = \"#f7e6ec\">"); 
  client.println("<hr/><hr>");
  client.println("<h4><center> Esp8266 Electrical Device Control </center></h4>");
  client.println("<hr/><hr>");
  client.println("<br><br>");
  client.println("<br><br>");
  client.println("<center>");
  client.println("Device 1");
  client.println("<a href=\"/light1on\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/light1off\"\"><button>Turn Off </button></a><br />");  
  client.println("</center>");   
  client.println("<br><br>");
   client.println("<center>");
   client.println("Device 2");
  client.println("<a href=\"/light2on\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/light2off\"\"><button>Turn Off </button></a><br />");  
client.println("</center>"); 
  client.println("<br><br>");
    client.println("<center>");
   client.println("Device 3");
  client.println("<a href=\"/light3on\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/light3off\"\"><button>Turn Off </button></a><br />");  
client.println("</center>"); 
  client.println("<br><br>");
   client.println("<center>");
   client.println("Device 4");
  client.println("<a href=\"/light4on\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/light4off\"\"><button>Turn Off </button></a><br />");  
client.println("</center>"); 
  client.println("<br><br>");
  client.println("<center>");
  client.println("<table border=\"5\">");
 client.println("<tr>");
  if (digitalRead(5))
         { 
           client.print("<td>Light 1 is ON</td>");
        
         }
          else
          {
            client.print("<td>Light 1 is OFF</td>");
      
        }
     
        client.println("<br />");
             
         if (digitalRead(4))
          { 
           client.print("<td>Light 2 is ON</td>");

         }
          else
          {

            client.print("<td>Light 2 is OFF</td>");

          }
          client.println("</tr>");


          client.println("<tr>");

          if (digitalRead(0))

          { 
           client.print("<td>Light 3 is ON</td>");

          }

          else

          {
            client.print("<td>Light 3 is OFF</td>");
          }


          if (digitalRead(13))


          { 


           client.print("<td>Light 4 is ON</td>");

          }


          else


          {


            client.print("<td>Light 4 is OFF</td>");


          }

          client.println("</tr>");


          client.println("</table>");

          client.println("</center>");
  client.println("</html>"); 
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}
---------------------------------------------------------------------------------------------




Copy the above code and complete the process. Share and let others know about this tiny chip which can do dozens of magic.





if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Friday, April 24, 2015

ESP8266 ESP12 LOW COST HOME AUTOMATION



Would you like to control your electrical devices (minimum devices upto 9) without spending much and not using microcontrollers? Here we go , this is a perfect solution for someone who love to turn On and Off some of your electrical devices from your chair through your android mobile. all you have to do is buy a esp8266 wifi module from the ai-thinker which preloaded with the firmwire and it comes with an android application which we can use to control the wifi module. 

If you don't have the ai-thinker android app click this link here to download the app.



Here's the block diagram for the Home automation circuit 


Refer the above video which is pretty much similar you can understand from it. 

This project is really a easy to do and fun simple home automation, where you can control your electrical devices from through your android mobile. It has not involved any programming or complex circuit to make the device get working. a simple plug and play hardware can be used to make it work. This is really cheap you don't need to spend more than $20 to control some electrical devices. Have fun and get started.