IR Module Tutorial

by KMHOOI in Circuits > Arduino

343 Views, 2 Favorites, 0 Comments

IR Module Tutorial

Presentation1.jpg

Test your IR module if it works!

Supplies

Presentation1.jpg

Arduino    x1 ***Any Arduino, I use Arduino Uno.***

IR module x1

LED           x1

Wire         x3 *** 3 piece normal wire/jumper wire/etc

Circuit Diagram

circuit.JPG

Connect the wires to the Arduino as shown.

Note:

No breadboard required.

Picture above is just a reference


Circuit:

Led + to any digital or analog pin

Led - to Arduino GND

IR VCC to Arduino 5V

IR GND to Arduino GND

IR OUT to Arduino any digital or analog pin


Coding

For better result, you can download Arduino IDE Software in https://www.arduino.cc/en/software

Code :

void setup()

{

 pinMode(A0,OUTPUT); //depends on where your led connected

 pinMode(A3,INPUT); //depends on where your ir module connected

 Serial.begin(9600);

}

void loop()

{

 if (digitalRead(A3)== LOW)

 {

  digitalWrite(A0,HIGH);

  Serial.println ("Obstacle detected");

   

  delay(100);

 }

 else 

 {

   

  digitalWrite(A0,LOW);

  Serial.println ("No obstacle");

  delay(100);

   

 }

}

  

Testing

Capture.JPG

***Remember connect the cable to your PC***

Open your Arduino IDE and click serial monitor (the magnifier-like icon)

What should you see:

When the module sensed obstacle, the serial monitor will print "Obstacle detected" and your led will bright; else the serial monitor will print "No obstacle" and your led will off.

Done

Congrats to all who succeed!

Have fun!

Thanks for watching!