Need a lot of help with a project.

Hi all,

I’m new here and totally new to working with an Arduino. I have recently just got my first. I have lots of experience with analogue electronics and working with hardware. Unfortunately my code writing skills are absolute zero. This is my first “real” Arduino project, I have done most of the examples and basics etc.

I’m trying to make a laser tripwire with a differance. I have a 2 CH remote control and LCD screen which I would like to intergrate. A really loud siren and green laser. The other difference from the many other laser tripwires I’ve seen around is that I would like it to remain in alarm mode until reset.

Here is how I envision it working:

http://i54.tinypic.com/2cxhijb.jpg

Here’s the 2CH R/C

http://i52.tinypic.com/2mwb8gg.jpg

http://i55.tinypic.com/333idcy.jpg

Big loud siren:

http://i51.tinypic.com/2crtzwl.jpg

Digital pins 2,3,4,5,11,12 are used by the LCD

Analog pin 0 by the LDR

I was going to use Digital pins 7,8,9 for the LED’s and the relay to activate the siren.

And either pins 10 and 13 for the buttons or Analog pins 1 and 2.

The R/C module can set each button to be either momentary, latching on/off or various times. I am going with momentary.

I am having a lot of difficulty with this project, I can’t figure out how to have the buttons interupt a process or have the alarm sound indefinately. I also have no idea how to bring this project together and have each bit of code working together.

I would really appreciate it if somebody could have a look at what I am trying to achieve and try point me in the right direction. Maybe somebody has done something similar that I can tweak and play with. I realise that this is a very ambitious first project, however I have all the hardware necessary and this is something that I have dreamed of since I was a child (who hasn’t). It’s literally driving me crazy, I need to achieve this soon. If somebody could write the code for me I would give them full credit (naturally), but I would also tell everybody I know and meet about how awesome they truely are and be forever in their debt.

Please don’t flame me or add anything unpleasent or unconstructive, I realise that this project is way above my skill level (as far as the coding end goes) and that it is a lot to ask, but I really really want to get this done and thought I may as well ask, nothing to lose.

Many thanks for reading. Any input, or assistance getting this project up and running would be very much appreciated

I am having a lot of difficulty with this project, I can’t figure out how to have the buttons interrupt a process or have the alarm sound indefinitely. I also have no idea how to bring this project together and have each bit of code working together.

Trying this complex a project with Halloween right around the corner may be more than you can chew. You have a whole first semester college course in this one project. To pull it off, you will need to be able to drink from a fire hose! (This may be “unpleasant or nonconstructive” but since you made the comment not to, I felt obliged to.)

  1. Break things down into chunks or modules. Create a set of subroutines (library) to interact with the sub components like the LCD and horn. The LCD might have routines like initialization, setCursorToXY, writeString, clear, changeContrast, … The horn is likely to only have hornOn, hornOff.

  2. Test each of these libraries using their own test program (sketch). Resist trying to take the Big Bang approach. Always a bad idea especially when on a tight schedule.

  3. Once you have the puzzle pieces made, now it is time to arrange them. From your description and reading between the lines, a finite state machine (FSM) architecture is likely to be your best get. Read up on an FSM and learn to draw “Bubble/State Diagrams”. Now diagram (your picture at the top is a good start) your various states.

  4. Once you have the Bubble/State Diagram, the coding should “drop into place”. You will be looking at a switch statement inside the loop() method. Based on the state you are in, you will do something and possibly change the state to a new one. Some states may sit and wait for something to happen by polling a GPIO pin. Others may make something happen.

  5. It is only slightly possible you may need to have some devices interrupt driven. For this type of application polling of IO should be more than adequate. Who cares if the horn goes off in 10 micro seconds or 10 milliseconds. Its still going to scare. Stay away from interrupts unless you think it is absolutely necessary and you get confirmation that it is. It will only complicate an already complex task.

Good luck!

fll-freak:

(This may be “unpleasant or nonconstructive” but since you made the comment not to, I felt obliged to.)

On the contrary, that was very pleasant and informative! I was just afraid of being flamed out of here so fast…

I have been attempting to do as you suggest, unfortunately I think I just need a “quick fix” for this one to get it ready ASAP, as at the rate I am going it may take a few years to get there.

Will stick at it though.

Many thanks for getting back to me : )

Although non-intuitive a “quick fix”/ “Big Bang” approach and “ASAP” tend to be mutually exclusive if you are not very comfortable with the material. A bootstrap approach will almost always get you to the finish line first.

Of everything on your plate, what are you most concerned with? Interfacing to the LCD, the basic architecture (FSM), … ? If you narrow the problem down to your highest risk item and farm that out for help, you might get more replies here. Looking at your overall problem is daunting. Very few people here have the time to help with the whole project. But we might be convinced to give you help in specific areas.

Thanks,

I have been trying to break it down into the core components and get them working individually, I have tested everything ok. I can write a sketch that will run the LCD, I can set up a tripwire and have it trigger the relay. My problem comes when I try to get code doing more than one thing at a time.

I will keep at it and try to be more specific with my queries.

Perhaps for a start if somebody could give me some help modifying the code featured in this instructable so that the alarm continues to sound after the beam is restored and until a reset button has been pressed. That would be a great beginning.

http://www.instructables.com/id/Arduino-Laser-Tripwire/

Thanks again for getting back to me, I appreciate it…

The code in that Instructable is very simple. If you are not comfortable coding it would not give you much to go on.

From your diagram I quickly put this FSM together. It will give you an idea how to do “multiple things at once”. This will obviously not compile, but it will give you a skeleton to put your code on.

int State = 0;

#define PowerOn  0
#define WaitForB1  1
...

loop() {

switch (State) {

case PowerOn:
  Turn GreenLed on
  Send "System Ready" to LCD
  Enable Cursor blink (Do you REALLY need this?)
  State = WaitForB1
  break;

case WaitForB1:
  if (button 1 has been pressed) {
    countdown = now + 10s
    State = Arming
  }
  break;

case Arming:
  write System Arming in "countdown" to LCD
  edit: if (second has changed) {
    countdown -= 1;
  }
  if (now in Seconds is even) {
    turn on red LED
  } else {
    turn off red LED
  }
  if (now > countdown) {
    State = ArmedPrep
  }
  break;

case ArmedPrep:
  Turn Laser on
  Turn red LED on
  print "System Armed" to LCD
  State = Armed
  break;

case Armed:
  If (button1 is pressed) {
    State = PowerOn
  }
  if (laser tripped) {
    State = TrippedPrep
  }
  break;

case TrippedPrep:
  Turn laser off
  Turn on siren (When does it ever get turned off?????)
  Write "Alarm" to LCD
  State = Tripped
  break;

case Tripped:
  if (now in Seconds is even) {
    turn on red LED
  } else {
    turn off red LED
  }
  if (button 1 is pressed) {
    State = PowerOn
  }
  if (button 2 is pressed) {
    State = ArmedPrep
  }
  break;

default:
  write to LCD "Holy Cow, bad case"
  State PowerOn
  break;
} // end switch

} // End loop

edit:

10/5/2011 added the countdown -=1 in case Arming

Cheers mate, thank you for that.

In work today, don’t have much free time. I will play around with it when I get home.

Thank you for your time…

Your bill is in the mail…