• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » LED as Sensor For Arduino : Basic Sensors in Robotics

By Abhishek Ghosh September 15, 2015 9:37 pm Updated on September 16, 2015

LED as Sensor For Arduino : Basic Sensors in Robotics

Advertisement

Theoretically, LED Can Act as Light Emitter & Light Detector. Here is How To Use LED as Sensor For Arduino, Circuit & Code Explaining Sensors in Robotics. This plain LED is never used in real life as sensor as basically they are designed to emit light, the light sense works better in one direction, sensitivity is lesser. This is analog sensor. First, we are sharing the code & circuit diagram. This is not what exactly what we want to talk about.

 

LED as Sensor For Arduino : Basic of Using Sensors in Robotics

 

This article, LED as Sensor For Arduino is just a basic example of using sensors to control a desired action. It is better to read about sensor in technology.

In this guide LED as Sensor For Arduino, light will go away if the “sensor LED” is exposed to dark, the “lighting LED” will glow when that dark condition is present for a defined period.

Advertisement

---

We are not exactly playing with toys. We have talked about wheeled chassis in robotics and basic way to control a DC motor. Now, if you combine this knowledge or rather projects – you can make a basic moving thing which will move when light is off.

Yes, that basic imaginary logically right robot which can oddly move at dark not at light will become better if you stay and read our guides. Our guides, be it for digital photography or WordPress or server works are written in a way that you should read from that topic’s initial articles. We merge towards an action which is practical. That light sensor is basic behind proximity sensors, obstacle detection etc. Other websites do not have this hierarchal way of guides. Yes, if you read Darren Rowse’s blogs, you’ll feel the same pattern in different topics. We do not want that you waste money.

 

LED as Sensor For Arduino : Code & Circuit

 

Light will go away if the “sensor LED” is exposed to dark, the “lighting LED” will glow when that dark condition is present for a defined period.

Sensor LED will be attached to Analog (input)’s A3 pin and GND. LED which will glow will be attached on Pin 13 and GND. Here is circuit :

LED as Sensor For Arduino Basic Sensors in Robotics

And here is the code :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
int led = 13;                                        // the pin where you will put the LED
int sensorpin = A3;                           // the analog pin where you put your sensorLED
int resetteller = 0;                              // the rest are counters and variables to calculate with
int sens = 0;
int teller = 0;
int basis = 1024;
int test = 1024;
int test2 = 1024;
int test3 = 1024;
 
// this are the values to play with to get better (or worse) results
int marge = 5;                         // the space between a positive and negative reading
int vertraging = 1;                  // the speed of the readings; a lower number is a higher speed
int samples = 70;                   // the amount of samples to compare to make one reading
int resetsamples = 30;          // how many cycles to run the light on before you don't trust the value anymore
 
void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);                                   // no real part of the program, just for debugging
  for(teller =0; teller < samples; teller++) {// remember the lowest value out of many readings
   sens = analogRead(sensorpin);
   if (sens < basis){basis = sens;}
   delay(vertraging);                                     // the sensor needs a delay here to catch its breath
  }
}
 
 
void loop() {                                            
for(teller =0; teller < samples; teller++) {// remember the lowest value out of many readings
   sens = analogRead(sensorpin);
   delay(vertraging);                                   // the sensor needs a delay here to catch its breath
   if (sens < test){
   test3 = sens;                                            // remember the 3 lowest readings
   test2 = test3;
   test = test2;}
  }
  if (test < basis-marge && test2 < basis-marge && test3 < basis-marge){//all 3 low readings mus be < the basis reading
    digitalWrite(led, HIGH);
    resetteller++;                                         // count how long the LED stays on
  }
    else{
      digitalWrite(led, LOW);
      basis = test;                                         // if the lowest test reading is higher than the basis, basis will be reset
      resetteller = 0;
    }
    if (resetteller > resetsamples){basis = test;}//if LED stays on to long, we don't trust it and reset basis
    Serial.print(basis);Serial.print("  ");Serial.print(test);Serial.print("  ");Serial.println(sens);//just for debugging
    test = 1024;
}

The code was shared in Instructables and we see no reason to change it. Analog of Arduino is not exactly great, code may work once, there is chance short circuit etc. It is basically not hugely great example for Arduino but great example for a basic sensor. Do not touch the board’s bottom with hand, it can short circuit the analog pins. At least in our long duration test it works. If does not work after once worked, then upload the Blink program & watch the blinking pattern of RX and TX while the Blink sketch is getting uploaded. Unplug USB and try other stuffs later. It may happen due to an effect. That is also a kind of sensor system. Arduino is not exactly a good standard to learn embedded electronics.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to LED as Sensor For Arduino : Basic Sensors in Robotics

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Arduino With DHT 11 Sensor and Arduino Online IDE : Basic IoT

    Arduino With DHT 11 Sensor and Arduino Online IDE is Example of Basic IoT Which Needs No Special Hardware But Arduino, DHT11, Internet Connection & Web Browser.

  • Arduino Temperature Humidity Sensor : New DHT11, DHT21, DHT22 Test Code

    Here is New Test Codes For Arduino Temperature Humidity Sensor DHT11, DHT21, DHT22 Test Code as Hardware (Not Shields). 2 Libraries Needed.

  • How to Control Multiple Relays With Single Arduino ESP32?

    Before How to Control Multiple Relays With Single Arduino ESP32 Testing, You Need to Learn How to Create Multiple MQTT Channels & Fetch Data.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy