Build a Simple Obstacle Sensor with Arduino – Easy IR LED & Photodiode Tutorial
Components and supplies
About this project
Step 1: Gather StuffStuff you are gonna need:
Step 2: Assemble- IR LED Anode => 150 ohms resistor => 5v
- PhotoDiode Cathode => 3k ohms resistor => D2
Step 3 Upload The Code:Upload the code given. See my other projects:
Thank You!
Support:Please support me by Going to Instructables and voting my Work. Without your work I can't keep on making stuff.
Vote For Me!
https://www.instructables.com/id/How-to-Make-Remote-Controlled-Bulb-With-Arduino/
https://www.instructables.com/id/How-to-Make-a-Parabolic-Microphone-With-an-Old-TV-/
https://www.instructables.com/id/How-to-Make-Secret-Drawer-Alarm/
Code
CodeArduino
Arduino Codeint photoDiode=2;
int GreenLed=13;
int senRead=0;
int SenseRate=905;
void setup()
{
pinMode(photoDiode,OUTPUT);
pinMode(GreenLed,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(photoDiode,HIGH);
digitalWrite(GreenLed,LOW);
Serial.begin(9600);
}
void loop()
{
int val=analogRead(senRead);
Serial.println(val);
if(val <= SenseRate)
{
digitalWrite(12,HIGH);
digitalWrite(GreenLed,LOW);
delay(20);
}
else if(val > SenseRate)
{
digitalWrite(12,LOW);
digitalWrite(GreenLed,HIGH);
delay(20);
}
}
Schematics
Schematics
Schematicsobstacl_GeLzd2U2jr.fzz