Motion detection sensor (PIR) with arduino)

Arduino Tutorial #6 PIR Motion detection sensor with Arduino & interface with LED light

Posted 3 CommentsPosted in Arduino

If you are visual guy you can watch this tutorial in video mention below this lesson.

hi guys in this tutorial we will see how to use motion detection sensor in Arduino & interface with LED light. So lets get started.  PIR sensor this is also called motion detection sensor. we can use this sensor in home automation like lights off automatically when there is no one in the room & light ON when someone enters the room. It can be also use for counting people or object I will show you in next tutorial.PIR sensor have two slot which senses IR if someone (warm body human or animal) passes by it. It will have difference in IR which will cause positive differential change between both slot. It will detect whenever there is IR changes.

Components:
  1. PIR sensor,
  2. Arduino,
  3. jumper wire,
  4. Bread board,
  5. LED light.

To see which pin is for VCC & GND. Just remove the white cover you can see there is pin name & in some sensor it is printed on the bottom side of circuit so make sure which in VCC & GND and middle one is for output.

Pin number
Pin number
PIR sensitivity & time trigger trimport
PIR sensitivity & time trigger trimport

 

 

 

 

 

 

 

 

 

PIR has a trimpot which can be use for adjusting sensitivity & trigger time.

Circuit diagram:

Do connection as shown in diagram.

PIR sensor circuit diagram
PIR sensor circuit diagram

 

sketch:
int ledPin = 13;                // choose the pin for the LED
int inputPin = 3;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
 
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
 
  Serial.begin(9600);
}
 
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
      delay(200);
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

 

We will set the pin number 13 for LED, input pin which is our PIR sensor output pin. When Arduino start there is no motion therefore pirstate is low. Val which is variable for reading pin PIR sensor initially at zero that is low. Pinmode declare the LED as output, sensor as input. Serial.begin will initialize the communication between computer & Arduino. Val value equal to sensor input value. If it is high LED light will on. If pirstate value is low. it will print motion detected. And set  pirstate equal to high. To prevent printing motion detected or motion ended repetitively. You can give any second delay for LED light. We want only output when it is detected it will show in serial monitor. If val is low it will turn off light. It will print motion ended. Upload the sketch. Go to tool & serial monitor. When I move my hand over sensor it will show motion detected when hand passed the sensor it shows motion ended. If it is continuously blinking or LED is ON so adjust the sensitivity & time trigger trim port.

Components to buy online:

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2vqnDHc   (PIR sensor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

http://amzn.to/2vSpUON   (LED)

  Till then keep learning keep making. 🙂

Measure humidity & temperature with Arduino

Arduino tutorial 5# how to Measure humidity & Temperature with DHT22/DHT11 in Arduino.

Posted 2 CommentsPosted in Arduino

Hi friends. In this tutorial we will see how to measure temperature & humidity with  DHT22/DHT11 in Arduino so lets get started. For this you will need

COMPONENTS:
  1. Arduino,
  2. jumper wire,
  3. breadboard,
  4. 10K ohms resistor,
  5. DHT22 sensor.

There are two version of sensor. One is DHT11 & second is DHT22.

DHT11 is cheaper in cost and less accurate compare to DHT22.

DHT22 is more accurate and have larger range compare to DHT11.

In this tutorial we are using DHT22. Sensor have four pin. Pin 1 is for : 5V power, Pin 2 is for: Data , Pin 3: not used, Pin 4 is for: GND.

CIRCUIT DIAGRAM:
Circuit diagram for DHT22 with arduino
Circuit diagram for DHT22 with arduino

This is circuit diagram. 10k ohms resistor is used which is a pull-up resistor because Random noise can change the state to go HIGH or LOW level randomly. So, The pull-up resistor ensures that the wire is at a defined logic level even if no active devices are connected to it. Do connection as shown in diagram.

Go to github website https://github.com/adafruit/DHT-sensor-library the link is mentioned below in the description. And download the file. After downloading unzip it. Change the file name to DHT.

Delete this file

Delete these files. shown in right side of image. And copy the DHT folder & paste in Arduino library folder. Now open the example folder then DHT tester. Open DHT tester file you can directly upload the sketch.

Sketch:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}
Explaination:

The purpose of the instruction “#include” is to include an external library in our project so we can use its functions. Define  DHT pin number that is pin 2. Define DHT type 22 or 11. Then initialize the library. Serial.begin (9600) it will create serial connection with Arduino. Serial.println will print hello massage when serial monitor is started. Dht.begin will start DHT. Lets going to loop function. We take measurement for humidity, temperature in Celsius & Fahrenheit using Float point h, t & f. “isnan” for  is not a number. This  is || OR Boolean operator.  If value of h,t or f is not a number it will print Failed to read from DHT sensor!. If you don’t want heat index you can delete it. Go to serial monitor now you can see the values of humidity, temperature in Celsius & Fahrenheit.

Components list to buy online:

http://amzn.to/2vqIKJP  (DHT22)

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

http://amzn.to/2vmSK8l  (Resistor)

 

For more videos subscribe the channel

Till than keep learning keep making. 🙂

How to interface Photo-resistor with LED

Arduino tutorial 4# How to interface Photoresistor with LED

Posted Leave a commentPosted in Arduino

 

If you are visual guy you can watch this tutorial in video mention below this lesson.

In this tutorial we will see how to interface photo-resistor sensor with LED light. If you have not read my previous article for photo-resistor in Arduino. You can click here.

 

Interface LED with Photo-resistor circuit diagram
Interface LED with Photo-resistor circuit diagram

 

Do connection as shown in circuit diagram. Whenever light fall on sensor it will create high resistance and prevent to flow current. And LED light will OFF. When there is no light on sensor it will have less resistance and current will flow and LED will ON. All the parts and programming is same as previous video. Only for this you will need one LED light and 2 Extra jumper wire.

When I fall light on sensor LED light will OFF. When I move light from sensor it will again ON.

Components list for buying online.

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2vSpUON   (LED)

http://amzn.to/2uK49eW  (Photo-resistor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

http://amzn.to/2vmSK8l  (Resistor)

 

KEEP LEARNING KEEP MAKING 🙂

How to use photo-resistor with arduino

Arduino tutorial 3# How to use Photo-resistor with Arduino.

Posted 1 CommentPosted in Arduino

If you are visual guy you can watch this tutorial in video mention below this lesson.

In this tutorial we will see how to use photo-resistor in Arduino.

For this you will need

PART:
  1. Arduino,
  2. Jumper wire,
  3. breadboard,
  4. 10K ohms resistor,
  5. Photo-resistor.

A photo-resistor is a light-controlled variable resistor. The resistance of a photo-resistor decreases with increasing incident light intensity. An analog input converts a voltage level into a digital value.

Circuit Diagram :
Photo-Resistor with Arduino circuit Diagram
Photo-Resistor with Arduino circuit Diagram

In this circuit diagram we are using voltage divider. A voltage divider is a passive linear circuit that produces an output voltage that is a fraction of its input voltage. Here input voltage is 5V and two resistor are connected in series. One resistor which is fixed 10k ohms resistor. And other is photo resistor which is a light-controlled variable resistor. When light intensity changes the output voltage changes.

Assembly:
  1. Connect resistor as shown in diagram then connect photo-resistor.
  2. Make sure it is align in same column as shown in diagram.
  3. connect red wire to 5V socket on Arduino,  black wire to ground and green wire to A1.
  4. Upload the sketch below.
Sketch :
void setup() {
 Serial.begin(9600);
}

void loop() {
 int sensorvalue=analogRead(A1);
 Serial.println(sensorvalue);
 delay(100);
}
Explanation :

This is Serial.begin (9600) it will create serial connection with Arduino. By this Arduino can send text output. AnalogRead(A1) which will get reading from socket A1. And Store it to local integer value sensorvalue. So whatever A1 get output we will print it through serial.println(sensorvalue). “Println(sensorvalue)” will create sensor value in new line. If you use “serial.print(sensorvalue)” without “ln” it will print sensor value in the same line. Time delay is in millisecond which is time between each sensor value is printed.

Upload the sketch.

Go to tools and serial monitor. Now you can see values.

If I keep my finger it on sensor it will change value. So your values may be different because of lightning condition.

Components list to buy online:

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2uK49eW  (Photo-resistor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

http://amzn.to/2vmSK8l  (Resistor)

 keep learning keep making 🙂

How to fade on & off LED with Arduino

Arduino Tutorial 2# LED Light fade on and off.

Posted Leave a commentPosted in Arduino

If you are visual guy you can watch this tutorial in video mention below this lesson.

In this lesson we will see how to make LED light fade on and off. If you have learned my previous lesson 1 then you will have to change only sketch (programming).

All the parts, circuit diagram, assembly remain same as previous lesson LED blinking to see that click here.

After assembly you need to change sketch (programming). (more…)

Arduino Tutorial 1# LED Light blinking

Posted 1 CommentPosted in Arduino

If you are visual guy you can watch this tutorial in video mention below this lesson.

This is first lesson on arduino uno. In this lesson we will see how to make LED light blink using arduino. I will explain how you can change the blinking time with little change in programming (sketch). If you are very new to this just go to this Arduino official website and download IDE which is nothing but a software which will help you to write code and upload it to the board. (more…)