Show Posts
Pages: [1] 2 3 ... 147
1  Using Arduino / LEDs and Multiplexing / Re: Send LED HIGH after "x" seconds on: April 17, 2014, 09:02:07 pm
Perhaps I really dont have an understanding of the }
i thought it's to execute whats after it as a whole?
before moving on to the next?

The brackets are for bunching relevant stuff together.

I'm really new at this...

This is about a lot more than "Send LED HIGH after 'x' seconds" ─ isn't it?
You have to approach this thing in steps.
This "one felled swoop" approach is not a winner.

I inserted some brackets where I thought they should go, but that's kind of hard to tell
So, it compiles, but I'm pretty sure that it's not what you figure.

Code:
int photocellPin = 0;// Photocell connected to analog pin 0
int photocellVal = A0; // define photocell variable
int pirVal = LOW;// motion sensor variable
int ledState = 0;//state of the led
int minLight = 20;//min light threshold
int maxLight = 20;//max light threshold
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;       

//the time when the sensor outputs a low impulse
unsigned long lowIn;
unsigned long refTime;
unsigned long trippoint;
const long threshold = 5000;
byte DET;
const byte pirPin = 2;

unsigned long pause = 5000UL; 

boolean lockLow = true;
boolean takeLowTime; 

//int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;

void setup()
{
  Serial.begin(9600);
  pinMode(photocellPin, INPUT);
  pinMode(pirPin, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++)
  {
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

void loop()
{
  photocellVal = analogRead(photocellPin);
  pirVal = digitalRead(pirPin);
  if (photocellVal < minLight && ledState == 0)
  {
    for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
    {
      analogWrite(ledPin1, fadeValue);   
      delay(30);
    }
  } 
  DET = digitalRead(pirPin);
  if (DET == 1)  // inactive
  {
    refTime = millis();
    trippoint = refTime;
  }
  else   // Active Low
  {
    pirActive();
  }

  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledPin5, HIGH);

  if(lockLow)   //  IF without a Condition to Meet -- WRONG
  { 
    lockLow = false;           
    Serial.println("---");
    Serial.print("motion detected at ");
    Serial.print(millis()/1000);
    Serial.println(" sec");
    delay(50);
  }         
  takeLowTime = true;                   
   
  if(pirVal == LOW)
  {   
    digitalWrite(ledPin1, LOW);  //the led visualizes the sensors output pin state
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
  }
           
  if(takeLowTime)    //  another IF without a CONDITION!!!!!
  {
    lowIn = millis();          //save the time of the transition from high to LOW
    takeLowTime = false;       //make sure this is only done at the start of a LOW phase
  }
 
  if(!lockLow && millis() - lowIn > pause)  //  BAD code, and NO CONDITION !!!!
  { 
    lockLow = true;                       
    Serial.print("motion ended at ");      //output
    Serial.print((millis() - pause)/1000);
    Serial.println(" sec");
    delay(50);
  }
}   
   
void pirActive ()
{
  trippoint = millis();
  if ((trippoint-refTime) > threshold)
  {
    digitalWrite(ledPin2,HIGH);
    digitalWrite(ledPin3, HIGH);
  }
}

I removed a lot of the comments, that's the only way I could keep from flying into a rage.
You have a few IF statements without a Condition, the equivalent of: IF (B).  Well, What about "B", anyway?
If (B == 100) or If (B == false) gives "B" a condition to meet.  See?
Work out simpler stuff first that you can incorporate later.
There's much for you to develop.
2  Using Arduino / LEDs and Multiplexing / Re: Send LED HIGH after "x" seconds on: April 17, 2014, 08:33:38 am
Automobile_Deterrent:131: error: a function-definition is not allowed here before '{' token
Automobile_Deterrent:138: error: expected `}' at end of input
Automobile_Deterrent:138: error: expected `}' at end of input

You have some bracket errors.
I think that it's easier to see where your brackets are amiss if you adopt "our" convention, each bracket on a line by itself:
Code:
void loop ()
{
  something
  or other
  if (whatever)
  {
    this and that
  }
}

That way they're stacked up like, a little more obvious.

[ I don't see where the problem is right now, because... I don't have access to the IDE right now. ]
3  Using Arduino / Motors, Mechanics, and Power / Re: Can't wire my stepper motor to make it work! on: April 16, 2014, 08:36:57 am
one more question if i can,  i want my arduino powered from a wall socket, not from my laptop, do you know what voltage the arduino power socket can handle? thaanksss

Is that all?
Not less than 7V nor more than 9V.
4  Using Arduino / General Electronics / Re: pnp transistor array with common emitter on: April 15, 2014, 08:28:06 am
Thank you. But now i am confused, which one is the right way,...

My way.

5  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 15, 2014, 08:22:11 am
There are 5 speeds (as derived from the map scheme), or levels, or whatever you want to call them. 
So, when it changes a level, from 3 to 4 or 3 to 5 (for example), it can/will, by the looks of it here, cut short instead of winding down, no matter where it is in the curve - bang, it starts anew.

The transition to a new "speed" shouldn't be allowed till the output is at "0".
6  Using Arduino / Motors, Mechanics, and Power / Re: Controlling Two 12v Fans off Arduino using one Power Adapter on: April 14, 2014, 10:02:41 pm
So - "what's the story, morning glory?"
7  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 14, 2014, 09:57:18 pm
I changed it to A0, same flashing result

So you do have the "temperature sensor" connected to Analog In pin A0 (not Digital pin 0) -- right ?

And when I posted that I got some wonky results, that was only when it changed val, the transitions from one to the next weren't "graceful".

And that's what I've been saying the whole time: ' the transitions from one to the next weren't "graceful" '
It does work, but not well.

Horsefeathers!
You posted that you were getting "random" flashing, "not working", "doesn't work" and that like.
Maybe I'm having an aneurysm.  Does anybody else smell burning toast?
So your beef all along has been the transitions?

My "guess" would be to structure the equation so that any new value of x is incorporated when the output is:
a) at max
OR
b) at min.




8  Using Arduino / General Electronics / Re: pnp transistor array with common emitter on: April 14, 2014, 09:46:03 pm
velo

PNPs are OK.
I had to tweak the resistor values and their placement a bit, but as long as it remains a 5V circuit then all is well.

[see attachment]
9  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 14, 2014, 09:15:09 pm
Thanks for quoting my last post to you, but you did not answer my question.
10  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 14, 2014, 08:17:26 am
I changed it to A0, same flashing result

So you do have the "temperature sensor" connected to Analog In pin A0 (not Digital pin 0) -- right ?

And when I posted that I got some wonky results, that was only when it changed val, the transitions from one to the next weren't "graceful".
11  Using Arduino / Project Guidance / Re: 6v 300mA water pump activated by PIR using Arduino Board - 6v issues on: April 13, 2014, 04:24:06 pm
Great! So I will be able to use the same power source (battery pack) to power the Arduino too correct?
Maybe, depending on its capacity.  The motor turning on might take the voltage down (dip) to where the Arduino might reset.

Then I can connect the PIR to another output and write the sketch from there?
Connect the PIR's output to an Arduino input.

Also, by what you are saying, you cant control the VIN pin?

"Control"?
12  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 13, 2014, 04:09:40 pm
I don't have a temperature sensor handy, so I used a CdS photocell circuit in lieu thereof.

Code:
const int transistorPin = 9;
int tempPin = A0;
int tempReading;
int x;
void setup()
{
  pinMode(transistorPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  tempReading=analogRead(tempPin);//temperature reading
  x=map(tempReading,0,100,1,5);//map the reading to change the frequency
  float val = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;//the function of breathing led
  analogWrite(transistorPin, val);
}

That works, but the output is kind of wonky.
My "map" is a little different, my photocell circuit resulted a 0 - 80 range.
A photocell isn't fast, but a temperature sensor is a lot slower, they shouldn't result abrupt changes.
A photocell situation might benefit from a rolling average, to smooth things out a bit.
But, most of all, the assignment of tempPin should be A0, not 0.
13  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 13, 2014, 03:56:07 pm
Oh!
I should have seen this before.
You have
int tempPin = 0;

Change that to
int tempPin = A0;
14  Using Arduino / LEDs and Multiplexing / Re: Breathing LED controlled by temperature sensor (NEED HELP!!) on: April 13, 2014, 03:25:56 pm
Whats the point of /17?
x=map(tempReading,150,170,1,5);
OK, map is resulting a range of 1 to 5 already, provided that 150 < tempReading < 170.
Is that the situation, those are your results?
tempReading=analogRead(tempPin);
Serial.println(tempReading,DEC);
  // this is always a number 150-170 ??

Yeah, I know the fade works if there is no x...
No, x is needed either way.
15  Using Arduino / Motors, Mechanics, and Power / Re: Controlling Two 12v Fans off Arduino using one Power Adapter on: April 13, 2014, 02:51:15 pm
P2N2222A
anything I can do with that?

I would just use the NPNs.  The HEXFETs are overkill.

> > > Adding schematic (attachment).  Change RB to 1K-2.2K
It has "2N3904" there, but same difference.
Pages: [1] 2 3 ... 147