Wednesday, June 10, 2015

Photosensor

How to build and control an LED on an Arduino with an LDR sensor:
by J.B. Wylzan

Project 11: LDR Sensor

This project teaches how to turn on and off any of your first 10 projects with a light sensor.



Hardware:
LEDs
resistors
photosensor
wires
breadboard
Arduino UNO

Block Diagram:

image designed by Fritzing

Note: Replace the switch button with the photosensor (A0/3,3v).See actual assembly below:


Actual Assembly:  





Procedure:
1. Use the same prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #11  below
5. Paste Code #11
6. Click File > Save
7. Click Verify
8. Click Upload
9. Activate leds by cupping the light sensor

Code # 11:  
/* 
    iHackLab The Switch 
    powered by Arduino
    sketched by J.B. Wylzan
    modified by Lawsinium
    code is public domain. */
    
const int ldrPin = 0;
const int ledPin = 8;
int Calphotons;
int Valphotons;


void setup()
{
  pinMode(ledPin, OUTPUT);
  Calphotons = analogRead(ldrPin);
}


void loop()
{
  Valphotons = analogRead(ldrPin);

 if (Valphotons < Calphotons - 50)
  {
    digitalWrite(ledPin, HIGH);
  }

  else
  {
    digitalWrite(ledPin, LOW);
  }

}


/* end program */



Project # 12: The Game of Reflex




Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 

No comments:

Post a Comment