Friday, 8 September 2017

DHT22 Temperature and humidity sensor interface with arduino


The DHT22 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.


Simply connect the first pin on the left to 3-5V power, the second pin to your data input pin and the right most pin to ground. Although it uses a single-wire to send data

TECHNICAL DETAILS



  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 80°C temperature readings ±0.5°C accuracy
  • No more than 0.5 Hz sampling rate (once every 2 seconds)
  • Body size 27mm x 59mm x 13.5mm (1.05" x 2.32" x 0.53")
  • 4 pins, 0.1" spacing
  • Weight (just the DHT22): 2.4g

Arduino DhT22 Wiring diagram 

PROGRAMME
//                   http://electronicshobbycorner.blogspot.in
//                   Rajeev TR
//                   rajeev.emb402@gmail.com
// PROGRAM TO INTERFACE DHT22 WITH ARDUINO


#include "DHT.h"
#define DHTPIN 2                                      // what pin we're connected to
#define DHTTYPE DHT22                                 // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);
float t;

float temprature();

void setup() 
{
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
  dht.begin();
}

void loop() 
{
  float k=  temprature();
  if(Serial.available())
  {
            char x;
            x=Serial.read();
            if(x=='a')
            {
                Serial.print("Temperature: "); 
                Serial.print(t);
                Serial.print(" *C ");
                Serial.println(); 
             }
  }

}
float temprature()
{
      float h = dht.readHumidity();
      t = dht.readTemperature();
      float f = dht.readTemperature(true);
      if (isnan(h) || isnan(t) || isnan(f)) 
      {
              Serial.println("Failed to read from DHT sensor!");
              return 0;
      }
      float hi = dht.computeHeatIndex(f, h);
      return t;
}

Download DHT22 Library from here
Download code from here

LM35 Temperature sensor interface with arduino

                    LM35 is a precision IC temperature sensor with its output proportional to the temperature ,The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than 0.1 oC.  temperature rise in still air. The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC.  rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC. 


PROGRAMME
//                   http://electronicshobbycorner.blogspot.in
//                   Rajeev TR
//                   rajeev.emb402@gmail.com
// PROGRAM TO INTERFACE LM35 WITH ARDUINO 

float temp;
int tempPin = 0;                        //LM35 sensor pin in A0
void setup()
{
    Serial.begin(9600);                 //Initilize serialport
}

void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;               //Calculating temprature 
Serial.print("TEMPRATURE = ");
Serial.print(temp);                     //Print temprature
Serial.print("*C");
Serial.println();
delay(1000);
} 






Download datasheet here
Download code here

Servo motor interface with arduino

                                             
                                Servo motors have been around for a long time and are utilized in many applications. They are small in size but pack a big punch and are very energy-efficient. These features allow them to be used to operate remote-controlled or radio-controlled toy cars, robots and airplanes. Servo motors are also used in industrial applications, robotics

                The servo circuitry is built right inside the motor unit and has a positionable shaft, which usually is fitted with a gear (as shown in fig). The motor is controlled with an electric signal which determines the amount of movement of the shaft. 

            Inside there is a pretty simple set-up: a small DC motor, potentio meter, and a control circuit. The motor is attached by gears to the control wheel. As the motor rotates, the potentio meter's resistance changes, so the control circuit can precisely regulate how much movement there is and in which direction. 

                When the shaft of the motor is at the desired position, power supplied to the motor is stopped. If not, the motor is turned in the appropriate direction. The desired position is sent via electrical pulses through the signal wire. The motor's direction is proportional to the difference between its actual position and desired position. 

           Servos are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM), through the control wire. There is a minimum pulse, a maximum pulse, and a repetition rate. A servo motor can usually only turn 90° in either direction for a total of 180° movement. The motor's neutral position is defined as the position where the servo has the same amount of potential rotation in the both the clockwise or counter-clockwise direction. The PWM sent to the motor determines position of the shaft, and based on the duration of the pulse sent via the control wire; the rotor will turn to the desired position. The servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn to the 90° position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0° position, and any longer than 1.5ms will turn the servo in a clockwise direction toward the 180° position. 

Interfacing Servo with Arduino


Program

PROGRAMME
//                   http://electronicshobbycorner.blogspot.in
//                   Rajeev TR
//                   rajeev.emb402@gmail.com
// PROGRAM TO INTERFACE SERVO MOTOR WITH ARDUINO  


#include <Servo.h>
Servo myservo;                          // create servo object to control a servo

int potpin = 0;                        // analog pin used to connect the potentiometer  A0
int val;                               // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);                   // attaches the servo on pin 9 to the servo object
}

void loop() 
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}
Click here to download code

Interfacing 162*2 LCD with arduino


                          A Liquid Crystal Display commonly abbreviated as LCD is basically a display unit built using Liquid Crystal technology. The most basic form of electronic display available is 7 Segment display – which has its own limitations. The next best available option is Liquid Crystal Displays, 16×2 LCD Module can display 32 ASCII characters in 2 lines ,16 characters in each line. 


16×2 LCD Module Pin Out 















Download datasheet here

                        

                      LCD modules are very important part in many arduino based embedded system projects. So the knowledge on interfacing LCD module to arduino is very essential in designing embedded systems.The LCD module has 16 pins and can be operated in 4-bit mode (using only 4 data lines) or 8-bit mode (using all 8 data lines). Here we are using the LCD module in 4-bit mode.



PROGRAMME
//                                       http://electronicshobbycorner.blogspot.in
//                                       Rajeev TR
//                                       rajeev.emb402@gmail.com

//  INTERFACING 16*2 lcd WITH ARDUINO 

//  LCD         ARDUINO
//   RS         8
//   EN         9
//   D4         10
//   D5         11
//   D6         12
//   D7         13                                  



#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup() 
{
 lcd.begin(16, 2);
 lcd.print("hello, world!");

}

void loop()
{
 

}

Download code here




Thursday, 7 September 2017

ESP 8266 INTERFACE WITH ARDUINO

     The ESP8266 arduino compatible module is a low-cost Wi-Fi chip with full TCP/IP capability, and the amazing thing is that this little board has a MCU (Micro Controller Unit) integrated which gives the possibility to control input/output digital pins via simple code . This device is produced by Shanghai-based Chinese manufacturer, Espressif Systems.
ESP8266-01Technical specifications


  • 32-bit RISC CPU: Tensilica Xtensa LX106 running at 80 MHz **
  • 64 KiB of instruction RAM, 96 KiB of data RAM
  • External QSPI flash – 512 KiB to 4 MiB* (up to 16 MiB is supported)
  • IEEE 802.11 b/g/n Wi-Fi
  • Integrated TR switch, balun, LNA, power amplifier and matching network
  • WEP or WPA/WPA2 authentication, or open networks
  • 16 GPIO pins **
  • SPI, I²C,
  • I²S interfaces with DMA (sharing pins with GPIO)
  • UART on dedicated pins, plus a transmit-only UART can be enabled on GPIO2
  • 1 10-bit ADC
Module pin description (pinout)
     Pins are arranged in two rows, having 4 on each row. Some models have pin description on the PCB, which make it simple. On the top row you can find following

Pins from First Row

GND         (Ground from power supply)
GPIO2       (Digital I/O programmable)
GPIO0       (Digital I/O programmable, also used                   for BOOT modes)
RX            UART Receiving channel

Pins from Second Row

TX            UART Transmitting channel
CH_PD    enable/power down, must be pulled to 3.3v directly or via resistor
REST        reset, must be pulled to 3.3v
VCC          3.3v power supply

Communicating with ESP8266

ESP8266 Datasheet download from here

Program

Program to create a WiFi client and connect to diffrent hotspots with arduino

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
char n;
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  Serial.println("Esp8266 test ......");
   Serial.println("a   Test ESP8266");
   Serial.println("b   Connect to samsung");
   Serial.println("c   connect to Redmi Note-4");
   Serial.println("d   Listing wifi routers");
   Serial.println("e   Listing current wifi router");
   Serial.println("");
   Serial.println("");
  }
void loop()
{

 if (mySerial.available())
 {
    Serial.write(mySerial.read());
  }
 
 
if (Serial.available())
  {
      n=Serial.read();
      if(n=='a')
      {
        Serial.println("ESP8266 Testing............");
        mySerial.println(F("AT"));
      }
      else if(n=='b')
      {
         Serial.println("Samsung connecting ............");
         mySerial.println(F("AT+CWJAP=\"SSID-1\",\"Password\""));
      }
       else if(n=='c')
      {
        Serial.println("Redmi Note-4 connecting ............");
        mySerial.println(F("AT+CWJAP=\"SSID-2\",\"password\""));
      }
      else if(n=='d')
      {
        Serial.println("Listing wifi routers");
        mySerial.println(F("AT+CWLAP"));
      }
      else if(n=='e')
      {
        Serial.println("Listing current wifi router");
        mySerial.println(F("AT+CWJAP?"));
      }
  }

}


Download code from here

Bluetooth Basics : Arduino interface with HC05

We can control any of your electronic devices with your smart phone, Even we can control a robot or any other special electronic equipment with our smart phone , Here is a simple tutorial for interfacing an Android Smartphone with Arduino via Bluetooth

Required Materials


Hardware

  1. Bluetooth Module HC 05/06
  2. Arduino & Battery (with cable)
  3. LED
  4. 220Ω Resistor
  5. Android device
Software
  1. Arduino IDE
  2. Bluetooth electronics
Connecting the Arduino Bluetooth hardware



Arduino Code

char data = 0;                                      //Variable for storing received data
void setup() 
{
  Serial.begin(9600);                         //Sets the data rate in bits per second (baud) for serial data transmission
  pinMode(13, OUTPUT);                 //Sets digital pin 13 as output pin
}
void loop()
{
      if(Serial.available())                     // Check if data available in serial port
      {
            data = Serial.read();               //Read the incoming data and store it into variable data
            if(data == 'a')                         //Checks whether value of data is equal to 1
            { 
              digitalWrite(13, HIGH);      //If value is 1 then LED turns ON
            }
            else if(data == 'b')                   //Checks whether value of data is equal to 0
            {
              digitalWrite(13, LOW);        //If value is 0 then LED turns OFF
            }
      }                            

}

Download Arduino code From here