Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 232
211  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 02:24:21 pm
Look at reply #6, the code I gave didn't have void loop() in it, but the code before it did.
212  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 02:17:27 pm
@wildbill

I know, but I retraced my steps, found it and brought it home.
213  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 01:50:46 pm
How short, because you can change the code to this and it will make the LEDs come on and go off in a fraction of a second.

Edit: I made a mistake, I had abs( SensorOne_timer - SensorTwo_timer) > 10, instead of <=
Make sure you fix your code.

Code:
boolean GotFirstSensor= false, GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, SensorOneState, RISING); // digital pin 2
  attachInterrupt(1, SensorTwoState, RISING); // digital pin 3
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
  {
    if( (SensorOne_timer > SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) <= 10 /*millisSeconds */)
    {
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
    }
    else if( (SensorOne_timer < SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) <= 10 /*millisSeconds */)
    {
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
    }
    // LEDs off
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);

    ClearStates(); // clear the states for next use
  }
}

void ClearStates()
{
  GotFirstSensor= false;
  GotSecondSensor = false;
}

void SensorOneState()
{
  SensorOne_timer = millis(); //record the time the car reaches the first gate
  GotFirstSensor = true;
}

void SensorTwoState()
{
  SensorTwo_timer = millis(); //record the time the car reaches the second gate
  GotSecondSensor = true;
}
214  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 01:32:28 pm
Ah, it would help if the code was in the loop function. Sorry about that.

Code:
boolean GotFirstSensor= false, GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, SensorOneState, RISING); // digital pin 2
  attachInterrupt(1, SensorTwoState, RISING); // digital pin 3
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
  {
    if( (SensorOne_timer > SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) < 10 /*millisSeconds */)
    {
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
    }
    else if( (SensorOne_timer < SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) < 10 /*millisSeconds */)
    {
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
    }
    else /* now it does nothing if the time difference is greater than 10 */
    {
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
    }

    ClearStates(); // clear the states for next use
  }
}

void ClearStates()
{
  GotFirstSensor= false;
  GotSecondSensor = false;
}

void SensorOneState()
{
  SensorOne_timer = millis(); //record the time the car reaches the first gate
  GotFirstSensor = true;
}

void SensorTwoState()
{
  SensorTwo_timer = millis(); //record the time the car reaches the second gate
  GotSecondSensor = true;
}
215  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 01:22:45 pm
Did you combine the first code and the new one?

Try it now.
Code:
boolean GotFirstSensor= false, GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, SensorOneState, RISING); // digital pin 2
  attachInterrupt(1, SensorTwoState, RISING); // digital pin 3
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
{
   if( (SensorOne_timer > SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
   {
       digitalWrite(12, HIGH);
       digitalWrite(13, LOW);
   }
   else if( (SensorOne_timer < SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
   {
       digitalWrite(12, LOW);
       digitalWrite(13, HIGH);
   }
   else /* now it does nothing if the time difference is greater than 10 */
   {
       digitalWrite(12, LOW);
       digitalWrite(13, LOW);
   }
   
   ClearStates(); // clear the states for next use
}

void ClearStates()
{
  GotFirstSensor= false;
  GotSecondSensor = false;
}

void SensorOneState()
{
  SensorOne_timer = millis(); //record the time the car reaches the first gate
  GotFirstSensor = true;
}

void SensorTwoState()
{
  SensorTwo_timer = millis(); //record the time the car reaches the second gate
  GotSecondSensor = true;
}
216  Using Arduino / Project Guidance / Re: I need some options for 12V battery supply on: June 23, 2014, 01:02:09 pm
I use this one,(6800mhA actually) but there are many others like this for less. 12V Super Battery

They also last for a VERY long time (charge wise).
217  Using Arduino / Project Guidance / Re: LCD menu's on: June 23, 2014, 12:42:05 pm
Code:
byte counter = 0;
byte maxMenus = 3; // 0, 1, 2

// In loop with rest of code
if(switchVar1 == 32) // you might want make it so the counter is only incremented if the button is pressed & released and not held.
{
   counter+1 < maxMenus?  counter++ : counter = 0;
}

switch(counter)
{
  case 0:
     // something
     break;
 
  case 1:
     // something
     break;

  case 2:
     // something
     break;
}
218  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 12:26:52 pm
Quote
But i have one last question just to prove that it works question: what does the code does when pin3 is activated and 2 is activited 3 milisecondes later?
Pin 12 goes HIGH, 13 goes LOW

And what does the code does when 3 is activated and 2 is activated 9 milliseconds later?
Same

And what does the code does when pin3 is activated and pin2 14 miliseconds later?
Nothing, the time difference is greater than 10 milliseconds

Is this homework or a school project?
219  Using Arduino / Project Guidance / Re: Counting Person entering a room on: June 23, 2014, 10:49:51 am
To increment and decrement a counter based on the number of people who entered or left will need a two sensor gate.

If sensor one is triggered first then sensor two, a person has entered.
if sensor two is triggered first then sensor one, a person has left.

You will have issues if two people are rude and try to enter and leave at the same time.
220  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 10:32:07 am
Quote
thanks for the code but is it that when pin1..... Pulsed than when pin2.... Pulsed in 10 milliseconds or less than it would send a puls via pin3.... But when pin2 pulsed and when in 10 milliseconds or less pin1 pulsed it sends a puls via pin4.....

And if one of the two pulsed and none of those two cases happend nothing happens to the output prins so for exemple
When pin1 sends 11 or more miliseconds after pin2 nothing happens or when pin2 pulsed and pin1 pulsed 11 miliseconds or more after it nothing happens?
?

From the description you gave, I made a code that looks at two pins, (2 and 3), then from those two pins, you get two different times in milliseconds of when they were pressed, activated or triggered. Those times are then compared and whichever one is greater and is within 10 milliseconds, it activates the corresponding output. If the time difference is greater than 10 milliseconds, the code does nothing.

Actually, I should add that in and be able to clear the states.
Code:
if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
{
   if( (SensorOne_timer > SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
   {
       digitalWrite(12, HIGH);
       digitalWrite(13, LOW);
   }
   else if( (SensorOne_timer < SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
   {
       digitalWrite(12, LOW);
       digitalWrite(13, HIGH);
   }
   else /* now it does nothing if the time difference is greater than 10 */
   {
       digitalWrite(12, LOW);
       digitalWrite(13, LOW);
   }
   
   ClearStates(); // clear the states for next use
}

void ClearStates()
{
  GotFirstSensor= false;
  GotSecondSensor = false;
}
221  Using Arduino / Project Guidance / Re: Asking input from final user on: June 23, 2014, 10:23:14 am
Why is this needed if it is much easier to do this from a regular computer? Also you don't need to know any kind of coding language, if you use a computer.

Quote
- Arduino as a wifi web server and then you have to connect and enter your information -> quite big solution for I think a small problem
Overkill
- Having a software/webpage either online or stored on the arduino that would ask the user its ID and automatically update the arduino program while connected through USB (Would be nice but could not find anywhere how to do this ?? at least how to upload a program on arduino through a webpage ??)
Are you looking to compile and upload the code from the webpage, im not sure if that's possible.
- Keyboard on the item so that you can enter your ID after pressing a button - again then a lot of hardware needed for a small problem.
Again overkill, but you could use a 4x3 keypad.
222  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 10:07:11 am
Ok, you need this.

Code:
boolean GotFirstSensor= false, GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, SensorOneState, RISING); // digital pin 2
  attachInterrupt(1, SensorTwoState, RISING); // digital pin 3
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
{
   if( (SensorOne_timer > SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
   {
       digitalWrite(12, HIGH);
       digitalWrite(13, LOW);
    }
    else if( (SensorOne_timer < SensorTwo_timer) && abs( SensorOne_timer - SensorTwo_timer) > 10 /*millisSeconds */)
    {
        digitalWrite(12, LOW);
        digitalWrite(13, HIGH);
    }
}

void SensorOneState()
{
  SensorOne_timer = millis(); //record the time the car reaches the first gate
  GotFirstSensor = true;
}

void SensorTwoState()
{
  SensorTwo_timer = millis(); //record the time the car reaches the second gate
  GotSecondSensor = true;
}

223  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 09:42:56 am
This code here is for a speed gate, but it kinda does what you want already. You just need to take out and add a few things. Also it does not use the analog pins, it uses interrupts.

Code:
#define FPS_to_MPH 0.68182 // scale factor
#define DISTANCE 35.5625 // distance between the two sensors or gates in feet.
#define swap(type, A, B) {type T = A; A = B; B = T;}

float Speed = 0, MPH = 0, tmp = 0;
boolean GotFirstSensor= false, GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  attachInterrupt(0, SensorOneState, RISING);
  attachInterrupt(1, SensorTwoState, RISING);
}

void loop()
{
  // This is using normal buttons to detect car passing through one gate to another,
  // this can be changed to use US sensors to replace the buttons. That part you will  
  // need to write yourself.

  if(GotFirstSensor & GotSecondSensor) //both must be true for this condition to be true
  {
    Speed = GetSpeed(SensorOne_timer, SensorTwo_timer, DISTANCE); // send the times and the distance into the function.
    Serial.print("MPH: ");
    Serial.println(Speed);
    ClearStates();
  }
}

void SensorOneState()
{
  SensorOne_timer = millis(); //record the time the car reaches the first gate
  GotFirstSensor = true;
}

void SensorTwoState()
{
  SensorTwo_timer = millis(); //record the time the car reaches the second gate
  GotSecondSensor = true;
}

void ClearStates()
{
  GotFirstSensor= false;
  GotSecondSensor = false;
}

float GetSpeed(unsigned long T1, unsigned long T2, float distance)
{
  MPH = distance * (FPS_to_MPH); // "(FPS_to_MPH)" -> conversion factor, feet per second to miles per hour
  if(T1 > T2)
    swap(unsigned long, T1, T2);
    
  tmp = (T2 - T1)/1000.00; // since the time we are using is in milliseconds, we need to convert milliseconds to seconds
  Serial.print("Time (seconds): ");
  Serial.println(tmp);
  return (MPH / tmp); //return the speed of the car in MPH
}

This code records the time the sensor states are triggered, and all you really need is to see which one has the greater time and is within 10 milliseconds, then from that you turn on the corresponding output.
224  Using Arduino / Project Guidance / Re: voice based password protected safty room on: June 23, 2014, 09:35:14 am
I can write A code but I can't test it (I have an iPhone), nor do I know exactly what your trying to do or how you want it to work. What is the motor supposed to do, what do the LED output, why do you need the AND and NOT gates?

I'm not so sure this is the type of thing you want to do with an arduino, especially if its for a safety room.

I don't want to be held responsible in the event the safety room turns out to be not so safe.

Added:
If the DC motor is to lock/unlock a door or window, you're better off using a servo instead.
225  Using Arduino / Programming Questions / Re: Help on: June 23, 2014, 09:28:29 am
So...
A0 then A1 -> output on pin 12
A1 then A0 -> output on pin 13

That's easy but where/how are you going to get these pulses, what equipment do you have to get them? You need an EEG, something that can detect those minute electrical pulses, then in turn feed that into the arduino.

Take a look at this. Mini Arduino EEG
Pages: 1 ... 13 14 [15] 16 17 ... 232