What Will I Learn?
At the end of this tutorial:
♦ The readers will be able to create a circuit that can detect an object using a photodiode, IR LED and a buzzer alarm upon detection
♦ The readers will be able to know how the circuit works.
♦ Learn to apply the circuit in the future electronic projects
Introduction
In this tutorial, we will create a simple object detection circuit using the photodiode and IR LED. Upon detection, a sound alarm will be heard using the buzzer or a piezo speaker. This project can be used in obstacle detection.
You can read more about photodiode Here
and IR LED Here
Requirements
Electronic Components
♦ Arduino Uno
♦ Photodiode
♦ IR LED
♦ Resistor
♦ LED
♦ Transistor
♦ Buzzer
♦ Breadboard
♦ Connecting wires
Software
♦ Fritzing application
Difficulty
♦ Advance
Tutorial Contents
Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard
Part I. Schematic Diagram
So first let us construct our circuit diagram.
Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 Photodiode, 1 BJT transistor, 1 IR LED, 4 resistors, 1 buzzer and 1 LED.
Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
In this tutorial the input components will be the photodiode, IR LED and two resistors while at the output components will be the LED and one amplifier circuit for the sound alarm.
Now let us construct our circuit diagram.
At the input side of our circuit, we have a photodiode and an IR LED. When the IR LED emits an infrared light, the photodiode will then convert this light energy into current. The current is generated when photon is absorbs by the photo diode.
So we must connect the IR LED to the source voltage from the arduino uno then the negative terminal to the ground. Since the photodiode depends on the IR LED’s output infrared light we must put them closer in the breadboard.
The photons that being absorbs by the photodiode is then converted to electric current. This current will flow through the input pin of the microcontroller. So we will choose an input pin ,which is analog pin A0.
Then at the output side of our circuit, we need two output pins, pin 2 & 12. For pin 12, it will be connected to the amplifier circuit to be amplified. Then the output at pin 2 will be fed to the cathode terminal of the photodiode as you can see in the figure below.
The amplified output at the collector terminal will be connected to the buzzer and LED that is connected in series.
Now this is our final circuit diagram.
When the IR LED emits infrared light, the photodiode that was placed near the IR LED will absorb this light energy then convert it to electric current. The photodiode is a semiconductor device that converts light into electrical current when photon is absorbed.
When the photon is already converted to electric current, it will flow through the input pin A0.
Since our microcontroller is programmed to give output at pin 12, an output signal will now flow through the amplifier circuit as you can see in the figure below. The amplified output at the collector terminal of the transistor will now drive the buzzer to alarm and the LED to give lights.
Part II. Code
Now let us do programming of our Arduino uno.
Click on code to start.
The output pin of our circuit is pin 2 & 12. While the input pin is pin 0. So we must declare it to our codes.
int photoPin = 0; // select the input pin for the photodiode
int cathodePin = 2; // select the pin for the resistor pin through the cathode terminal of the photodiode
int resPin = 12; // select the pin for the resistor output
int photoState = 500; //initial setting for the photodiode
void setup() {
// declare each Pin as an INPUT:
pinMode(photoPin, INPUT);
// declare each pin as an OUTPUT:
pinMode(cathodePin, OUTPUT);
pinMode(resPin, OUTPUT);
digitalWrite(cathodePin, HIGH);
}
void loop() {
//assign a value to the photodiode
int value = analogRead(photoPin);
if (value <= photoState)
{
//when the value at the photodiode is less than or equal to the set value
//pin 12 is HIGH
digitalWrite(resPin, HIGH);
//pin 2 will be LOW
digitalWrite(cathodePin, LOW);
delay(10); //delayed in 10 milliseconds
else if (value > photoState){
//otherwise pin 12 is LOW
digitalWrite(resPin, LOW);
//then pin 2 is HIGH
digitalWrite(cathodePin, HIGH);
delay(10);
}}
}
Here are our arduino codes.
int photoPin = 0; // select the input pin for the photodiode
int cathodePin = 2; // select the pin for the resistor pin through the cathode terminal of the photodiode
int resPin = 12; // select the pin for the resistor output
int photoState = 500; //initial setting for the photodiode
void setup() {
// declare each Pin as an INPUT:
pinMode(photoPin, INPUT);
// declare each pin as an OUTPUT:
pinMode(cathodePin, OUTPUT);
pinMode(resPin, OUTPUT);
digitalWrite(cathodePin, HIGH);
}
void loop() {
//assign a value to the photodiode
int value = analogRead(photoPin);
if (value <= photoState)
{
//when the value at the photodiode is less than or equal to the set value
//pin 12 is HIGH
digitalWrite(resPin, HIGH);
//pin 2 will be LOW
digitalWrite(cathodePin, LOW);
delay(10); //delayed in 10 milliseconds
else if (value > photoState)
{
//otherwise pin 12 is LOW
digitalWrite(resPin, LOW);
//then pin 2 is HIGH
digitalWrite(cathodePin, HIGH);
delay(10);
}}
}
Part III. Breadboard
Click on the breadboard.
Arrange each component in the breadboard before connecting.
Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard
Application
The readers can create their own obstacle detection circuit using photodiode and IR LED like the example below.
Curriculum
Here are my other tutorials for electronic projects.
ELECTRONIC PROJECTS
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
thanks @creon
Hey @rfece143 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x