• 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 336 Times!

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

  • 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

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

  • What Online Casinos Have No Deposit Bonus in Australia March 30, 2023
  • Four Foolproof Tips To Never Run Out Of Blog Ideas For Your Website March 28, 2023
  • The Interactive Entertainment Serving as a Tech Proving Ground March 28, 2023
  • Is it Good to Run Apache Web server and MySQL Database on Separate Cloud Servers? March 27, 2023
  • Advantages of Cloud Server Over Dedicated Server for Hosting WordPress March 26, 2023

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, March 30, 2023, https://thecustomizewindows.com/2015/09/led-as-sensor-for-arduino-basic-sensors-in-robotics/.

Source:The Customize Windows, JiMA.in

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT