fbpx
Arduino Lesson 9: Proximity Sensor
Arduino Lesson 9

Proximity Sensor

Detect distance from a proximity sensor

Components Required

Buy
Buy

Introduction

In this example, you are learning how to use proximity sensor. This sensor (TCRT5000) uses reflection on a surface theory to working. From a white and polished surface reflects large percentage of light and from a black and rough surface absorbs (not reflect) large percentage of light that incidence on the surface.

Learning outcomes:

  • Reflection theory using with Infrared radiations.
  • Turning physical parameter to an analog electric signal.

Theory

A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact. A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the field or return signal.

Features:

  • Supply voltage 3.3V ~ 5V
  • Detect distance 1mm ~ 8mm

Methodology

  1. As the first step, you should connect a Magicbit proximity sensor to Magicbit core board. For this you can use one side connector from four side connectors of the Magicbit core board or if you want to extend the length the connection you can use jumper wires.
  2. For this example, the proximity sensor was connected to the upper left connector of the Magicbit core board.
  3. Then connect the Magicbit to your pc and upload the code. You can get outputs using serial monitor.

Code

 

const int IRpin = 32;

void setup() {
  Serial.begin(9600);
  pinMode (IRpin, INPUT);
}
void loop() {
  Serial.println(analogRead(IRpin));
  delay(100);
}

 

Outputs: Serial monitor

https://i0.wp.com/github.com/HarshaWeerasinghe/MagicBit_Sensors/blob/master/resources/TCRT5000/surface_black.png?w=640&ssl=1

Figure 1: Serial output when faced a black surface

https://i2.wp.com/github.com/HarshaWeerasinghe/MagicBit_Sensors/blob/master/resources/TCRT5000/surface_white.png?w=640&ssl=1

Figure 2: Serial output when faced a white surface

Explanation

Const int: Defining input pin.

Serial.begin(9600): Setting baud rate.

analogRead: Read the data input of configured data pin.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *