element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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 Help making basic laser trip wire program fit my needs..
  • 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 Not Answered
  • Replies 4 replies
  • Subscribers 417 subscribers
  • Views 568 views
  • Users 0 members are here
Related

Help making basic laser trip wire program fit my needs..

e14 Contributor
e14 Contributor over 13 years ago

Hello friends. Well I've been toying with my new Uno and I think I have the basics down but a few things I need it to do are still beyond me. I've read two books so far but the examples they give seem to be more information driven and not sensors based. I have a basic laser trip wire with this sketch and it works like it is supposed to..

 

 

void setup(){

pinMode(4, OUTPUT);          // Laser

pinMode(13, OUTPUT);        // LED

}

 

void loop(){

digitalWrite(4, HIGH);           // Turn on laser

if(analogRead(0) < 750){       // Read sensor

digitalWrite(13, HIGH);         // Turn on LED

}else{

digitalWrite(13, LOW);         // Turn off LED

}

}

 

 

 

So like I said this works fine for the basics but I need to add a few things.

 

1. A timer- I need to only run this program once every 30 minutes for 2 minutes. Would I need an RTC because I believe 30 minutes is too long for the built in Timer1?

 

2. I need to incorporate either a http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger or a http://www.seeedstudio.com/wiki/Grove_-_IR_Distance_Interrupt that runs with the  http://www.seeedstudio.com/wiki/Grove_-_Light_Sensor or before the program AND after a minute of the program running. The reason being is the OUTPUT that is triggered by the break in the laser will be a relay controlled motor so I need to make sure the motor doesnt turn on when I am at max height or the laser or sensor malfunction and burn up my motor. I understand I can use a double IF but from what I have read I can't have 2 sensors running at the same time so I need to know how to do them asimultaneously where the program shuts down if the range < 8in at anytime during the 2min on time or run the range finder first and IF the range is > 8'' run the laser wire for 1min and then loop back around and run it one more time. If the range < 8'' do nothing.

 

3. The laser I'm using is rather strong so I would like to blink an LED for 10secs before the laser turns on so I am not too close.

 

If anyone out there can help with any of this I would really appreciate it because my brain is going nuts trying to figure this out. I hope my first post makes sense..

  • Sign in to reply
  • Cancel
Parents
  • mcb1
    0 mcb1 over 13 years ago

    Dustin

     

    30 mins is possible using the Arduino.

    Normal 'int' allows numbers to 32,768 (15 bits plus a sign)

    while a long number gives up to 2,147,483,647

     

    I've never had delay work much above 30,000, so I would suggest either doing a two step approach (incrementing a 1 sec counter with a delay(1000), and when it hits 1800 then your 30mins is up).

     

    The other option is to use Millis() ( http://arduino.cc/en/Tutorial/BlinkWithoutDelay ) and make the interval 30 mins or 1800,000 mS.

    You simply check if 'its time' and then call the part of the program that does the work.

    see http://arduino.cc/en/Tutorial/WhileLoop

    It calls the void calibrate() routine

    Its possible to have a loop() section that simply just calls the other routines

     

     

    Your sketch is a little light to comment on, and how and what is on A0. (Ambient light sensor??)

     

    I would use the light sensor to see if there is enough/not enough light, and then run the distance sensor.

    Its true you do have trouble trying to run two ultrasonic ping sensors within a short time of each other, but without knowing the book, I can't understand under what scenario they say you can't read two sensors.

     

     

    You may find a flow chart of your plan will help.

    The answer to each is a yes/no which translates to a simple if statement.

     

    The LED blinking can be a simple routine you call, and at the end it returns to the main loop.

     

    Hopefully this powerful laser is not going to pose a danger or nuisance to others.

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 13 years ago

    Dustin

     

    30 mins is possible using the Arduino.

    Normal 'int' allows numbers to 32,768 (15 bits plus a sign)

    while a long number gives up to 2,147,483,647

     

    I've never had delay work much above 30,000, so I would suggest either doing a two step approach (incrementing a 1 sec counter with a delay(1000), and when it hits 1800 then your 30mins is up).

     

    The other option is to use Millis() ( http://arduino.cc/en/Tutorial/BlinkWithoutDelay ) and make the interval 30 mins or 1800,000 mS.

    You simply check if 'its time' and then call the part of the program that does the work.

    see http://arduino.cc/en/Tutorial/WhileLoop

    It calls the void calibrate() routine

    Its possible to have a loop() section that simply just calls the other routines

     

     

    Your sketch is a little light to comment on, and how and what is on A0. (Ambient light sensor??)

     

    I would use the light sensor to see if there is enough/not enough light, and then run the distance sensor.

    Its true you do have trouble trying to run two ultrasonic ping sensors within a short time of each other, but without knowing the book, I can't understand under what scenario they say you can't read two sensors.

     

     

    You may find a flow chart of your plan will help.

    The answer to each is a yes/no which translates to a simple if statement.

     

    The LED blinking can be a simple routine you call, and at the end it returns to the main loop.

     

    Hopefully this powerful laser is not going to pose a danger or nuisance to others.

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to mcb1

    Thanks Mark and I really appreciate the quick response.. So I will look into Milli a little more in depth for my LED and timing issue. As for the light sensor (A0) it is a basic analog sensor that gives a reading of 0-1023 that is constantly running. Without the laser on the photo resistor I get a reading of around 600 and when the laser is on the resistor I get a reading of 1000. The reason I thought you couldnt use the two together is the IR Range Finder is also constantly running and sending a reading. If I can use them together I would be a happy man.

    A little info on what I am trying to do.. My fiance is a botany student in college and is trying to create a new strain of a plant that she is still deciding on. I turned a section of a spare room into a small hydroponic setup for her. Everything works great but the problem is the HID light that she uses needs to stay at a certain distance from her plants so they dont get burnt and to get the most out of her light. This becomes a hassle to constantly check distances and raise the light manualy plus it limits time we can spend away from the house (vacations). I looked around on various sites and there is no automatic light lifter. Someone suggested I looked into Arduino about 3 weeks ago and ever since then I have been trying to learn as much as possible. I have already designed the laser system and the winch controlled by a 12vdc 6300 ounce-in torque geared motor that turns very slowly. The laser is mounted 8'' under her light to the size of her garden. The laser bounces off of 7 aluminum pieces and back to the sensor creating a plane so if at anytime the line is broken it triggers the motor until it is read again. So this is where my issues come from. I dont want the system running 24/7 because that is over kill and it will greatly reduce the time the laser is good for. The project box is mounted on top of her hood and this is where the IR Range Finder comes in. I havent bought it yet but I will soon and it will be mounted on top of the box. I need it to measure the distance to the ceiling and stop the motor at a set point from running in case of a malfunction with the laser causing the sensor to think it is tripped. This would be bad because the motor is expensive and I'm not sure if it would rip the light down killing her work. As far as the laser is concerned it is only a 1mw 3vdc .3a laser but it is strong enough to damage an eye. The laser line is visible when on. I also thought about hooking a PIR sensor up to turn off everything if it reads a presence but I will work on that later.

    Hopefully this helps in trying to understand what I'm trying to do and become fiance of the year.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify 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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube