Electronic Project 28: A simple guide in detecting an obstacle using a photodiode, IR LED and a buzzer for the sound alarm

in #utopian-io8 years ago (edited)

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

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

The amplified output at the collector terminal will be connected to the buzzer and LED that is connected in series.

image.png

Now this is our final circuit diagram.

image.png

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.

image.png

When the photon is already converted to electric current, it will flow through the input pin A0.

image.png

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.

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

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

image.png

int photoState = 500; //initial setting for the photodiode

image.png

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); 
}

image.png

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);
}}
}

image.png

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.

image.png

Arrange each component in the breadboard before connecting.

image.png

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

image.png

Application

The readers can create their own obstacle detection circuit using photodiode and IR LED like the example below.

link source

Curriculum

Here are my other tutorials for electronic projects.

ELECTRONIC PROJECTS

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20

Tutorial 21

Tutorial 22

Tutorial 24

Tutorial 25

Tutorial 26

Tutorial 27



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @rfece143 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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