outlining a multi task project

again, I am a beginner. I have been through sparkfuns tutorial. have accomplished all the steps. my project involves a dozen or so sketches. I have been able to accomplish each task as an individual task.

compiling these sketches is a bit confusing. this is dependent on this, which depends on THIS, and IF this is THAT then THIS is different...

I am not looking for someone, to write my code. I AM, looking for direction as to where is the best place to learn how to incorporate many sketches into 1 in a manner that is logical, and most importantly, POWER SAVING! as this project will operate on a battery with no one to attend to it.

HOW DO YOU OUTLINE A PROJECT? is my MAIN question. I mean, there are a half dozen sketches in mine and there are a dozens ways to accomplish each task.

i know EXACTLY what i want to do. i have already done it with an analog circuit. but there are sooooooo many variables in this. what are some of the considerations that you put into your "story board" when you want to design something?

if you have time to elaborate, cool.. if you don't, no problem. i will learn regardless. and thank you to those who have offered their advice, each little bit has made me wiser.

Post a circuit diagram and a description of what your project does.

Take a look at the planning and implementing a program sticky at the top of this topic.

Link to Planning and Implementing a Program

Power saving is a different subject and depends very much on what you want to do and what things you have added to you Arduino.

...R

Nick Gammon's thread on power saving. power saving

thanks all, i will read all the suggested material. i came up with an "outline" so to speak. i can't write any code yet, but hopefully i can convey the concept of my project and one of you may say YES that is very possible.

  1. power arduino

  2. check LDR = if light = sleep = if dark = awake

  3. if awake = pin (x) = high / duration = 20 min, then, set pin (x) low / duration = 1s, then it can loop

  4. if awake (or) asleep

while/if awake - pushbutton (x) = pin (x) = low and = pin (x1) = high while/if asleep - pushbutton (x) = pin (x1) = high

release button (x) return to current state.

That should certainly be possible. But the details of how to wake it up will need to be considered. There are various options.

...R

hi Robin, RE: “sleep”… let me attempt to explain. our definitions are different. and…eventually i will communicate more accurately.

in my analog circuit, “sleep” simply means that during the day=light the only thing running is the LDR and a LM339 comparator circuit. “when” the comparator circuit discovers it is night it sends power to other components.

“now” i am replacing the LM339 and its components with an arduino. the arduino is on 24/7. it reads the voltage divider/LDR, and when dark, it sends power to other components.

which include a PIR and ISD 1820 sound module. the sketch i use is: HOPEFULLY, this is posted correctly?

int input = 0; //analog input 0 is connected to the sensor
int output = 2; //digital pin 2 is connected to the transistor base
int threshold = 812; // nominal threshold
int hyst = 50; // on when input above threshold + hyst, off when below threshold - hyst
int samplingDelay = 800; // higher values for slow changing signals, lower values for faster response

void setup() {
  pinMode(output, OUTPUT); //initializes pin 2 as an output
}

void loop() {
  int v;

  // read the value
  v = analogRead(input);

  // if it's higher than the on-threshold
  if (v > (threshold + hyst)) {
    // turn the output high
    digitalWrite(output, HIGH);
  }
  // if is't lower than the off-threshold
  else if (v < (threshold - hyst)) {
    // turn the output low
    digitalWrite(output, LOW);
  }
  // else don't change the output state

  // wait before taking another sample
  delay(samplingDelay);
}

it works well though i had to change the parameters because of the speed of the LDR.

i have discovered some anomalies in the other components using the arduino, but they actually work in my favor.

so… now it is dark, i have power to the other pieces, now what i want to do is learn how to turn off the HIGH state of PIN 2 for, say 1 - 2 seconds. as this will cause the PIR and 1820 to reset=play.

how is the display of the code? acceptable under forum guide lines?

Are your "other components" connected directly to pin 2? If so, what is the total current draw? It must not exceed 20 mA.

Fredric58: in my analog circuit, "sleep" simply means that during the day=light the only thing running is the LDR and a LM339 comparator circuit. "when" the comparator circuit discovers it is night it sends power to other components.

If you study the code in Planning and Implementing a Program you will see that the different activities are in different functions. If you organize your code like that it will make it easier to do different things at different times.

You can use millis() to manage the timing of your PIR reset. I hope the use of millis() is well demonstrated in planning and implementing...

However if you are going to use millis() for timing you need to use it everywhere because it is essential that loop() can repeat as often as possible - hundreds or thousands of times per second. Using delay() prevents that.

Another important trick is to use variables to record the state of things - for example whether th PIR is in the middle of its reset process. That could be as simple as PIRresetting = true; and you would refrain from doing something else if the variable is true.

...R