Saturday 8 June 2024

IR sensor (with or without Arduino)

 IR Sensor without Arduino


Circuit Diagram: (LED and Relay):

Video:




IR sensor with Arduino

A servo motor is activated when any obstacle comes in front of IR sensor.

Circuit Diagram:



Arduino Code:

#include <Servo.h> 

Servo myservo; // create servo object to control a servo 

const int IRpin = 4;

void setup() { 
   myservo.attach(5); // pin 5 of Arduino with servo motor
   pinMode(IRpin, INPUT);
   myservo.write(0);
   delay(500);
   myservo.write(90);
}

void loop() { 
  if(digitalRead(IRpin)==0)
     myservo.write(0); // tell servo to go to a particular angle
  else
    myservo.write(90);
}

Video:



No comments:

Post a Comment