element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Laser tripwire assistance
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 2 replies
  • Answers 2 answers
  • Subscribers 391 subscribers
  • Views 326 views
  • Users 0 members are here
Related

Laser tripwire assistance

otanoob
otanoob over 7 years ago

I've been trying to setup a laser tripwire as a fantasy project. The sketch I'm using looks like this

 

[code]

 

int ldrPin = A4; // the cell and 10K: pulldovn are connected to a0

int sirenPin = 11; //pin 3 selected!!

int ledPin = A0;

long ldrValue1, ldrValue2;

void setup(void) {

  pinMode (sirenPin, OUTPUT); // set the siren pin as output

  pinMode (ledPin, OUTPUT); // set the siren pin as output

  pinMode (ldrPin, INPUT); // set the siren pin as output

  //Serial.begin(9600);

}

void loop(void) {

  ldrValue1 = analogRead(ldrPin);

  delay(10);

  ldrValue2 = analogRead(ldrPin);

  if (ldrValue1 - ldrValue2 > 20) {

    digitalWrite(sirenPin, HIGH);

    digitalWrite(ledPin, HIGH);

    delay(1000);

  }

  else {

    digitalWrite(sirenPin, LOW);

    digitalWrite(ledPin, LOW);

  }

  //Serial.print("Analog reading = ");

  //Serial.println(ldrValue1); // the raw analog reading

}

[/code]

 

My issue seems to be with the hardware. I was told a 1k resistor would suffice for the ldr I'm using .It all worked for an hour, then I attempted to extend the ldr with jumper wires and it stopped functioning. Any ideas?

 

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 7 years ago +3 suggested
    You may wish to revise where things are actually connected. int ldrPin = A4; // the cell and 10K: pulldovn are connected to a0 int sirenPin = 11; //pin 3 selected!! int ledPin = A0; long ldrValue1, ldrValue2;…
  • fmilburn
    fmilburn over 7 years ago +1 suggested
    Hi Joseph, If you are using a breadboard, check all connections to make sure they are good. If you have a digital multimeter you can check for continuity. Turn on the serial print and see if there is a…
  • fmilburn
    0 fmilburn over 7 years ago

    Hi Joseph,

     

    If you are using a breadboard, check all connections to make sure they are good.  If you have a digital multimeter you can check for continuity.  Turn on the serial print and see if there is a reading on the analog pin.  Did you change the resistor from when it was working?  I would not expect a jumper to make a difference if there is a good connection.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mcb1
    0 mcb1 over 7 years ago

    You may wish to revise where things are actually connected.

     

    int ldrPin = A4; // the cell and 10K: pulldovn are connected to a0
    int sirenPin = 11; //pin 3 selected!!
    int ledPin = A0;
    long ldrValue1, ldrValue2;
    void setup(void) {
      pinMode (sirenPin, OUTPUT); // set the siren pin as output
      pinMode (ledPin, OUTPUT); // set the siren pin as output
      pinMode (ldrPin, INPUT); // set the siren pin as output
      //Serial.begin(9600);
    }
    void loop(void) {
      ldrValue1 = analogRead(ldrPin);
      delay(10);
      ldrValue2 = analogRead(ldrPin);
      if (ldrValue1 - ldrValue2 > 20) {
        digitalWrite(sirenPin, HIGH);
        digitalWrite(ledPin, HIGH);
        delay(1000);
      }
      else {
        digitalWrite(sirenPin, LOW);
        digitalWrite(ledPin, LOW);
      }
      //Serial.print("Analog reading = ");
      //Serial.println(ldrValue1); // the raw analog reading
    }

     

    Line 01 says that the LDR will connect to A0, yet the declaration is A4

    Line 02 says it will be D3 yet the declaration is D11

    Line 03 has the Led on A0.

     

    Not sure where you got the code from but reading the LDR 10mS apart is probably going to give the same value.

    So I suspect it will never meet the true condition in Line 14.

     

     

    Not that it will matter but the analogue vaue reading is a number between 0 and 1023, so it doen't need to be decalred as a long, and int will handle it just as well.

     

     

    Can you confirm the connections .... maybe a good well focused picture or two.

    Otherwise it looks like it should work.

     

    Mark

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube