• 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.

This Article Has Been Shared 249 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic 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

  • Used Mobile Phone’s Display For Arduino & Other DIY Projects

    It Is Not Abnormal To Think About Used Mobile Phone’s Display For Arduino & Other DIY Projects To Save the Total Cost. Here are some details.

  • Buying Arduino Original Versus Arduino Clones

    Arduino Clone in this article means Arduino Compatible. Buying Arduino original versus Arduino clone has difference from many less known aspects.

  • Basic Electronic Components List and What They Do

    Here is an Illustration of the Basic Electronic Components List and What They Do. This article is helpful for new Electronics Enthusiasts.

  • Arduino GSM Shield : Getting Started With DIY IoT

    Compared to Wi-Fi Shield, Arduino GSM Shield is Practical as It Opens the Door Towards Real IoT. We Need to Control Things Over Internet.

  • Taking Out Hard Disk Motor For DIY Project

    Here is What Exactly You Will Do For Taking Out Hard Disk Motor For DIY Project. Probably You Need Just a Torx Screwdriver For Clean Work.

Additionally, 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

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

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 (20K Followers)
  • Twitter (4.9k Followers)
  • Facebook (5.8k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.2k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Software Modernization? January 21, 2021
  • Cloud Computing : Cybersecurity Tips for Small Business Owners January 20, 2021
  • Arduino : Independently Blink Multiple LED January 18, 2021
  • What is a Loosely Coupled System? January 17, 2021
  • How To Repack Installed Software on Debian/Ubuntu January 16, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "LED as Sensor For Arduino : Basic Sensors in Robotics," in The Customize Windows, September 15, 2015, January 21, 2021, https://thecustomizewindows.com/2015/09/led-as-sensor-for-arduino-basic-sensors-in-robotics/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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