Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: [Video] Electronic Dog Door - few weird things happening ?? on: June 19, 2011, 03:44:18 pm
Hi guys, great work you're doing here, just thought i'd throw in my $0.02.

I have got the code working fine, however, I have changed the part when both inputs are read as 0 to do a double check.

The code I have changed is here:
Code:
if( (0 == top_switch) && (0 == bot_switch) ) {                               // Either we have an error or the door is in
   Serial.println( "0, 0, error or transient door position; Checking what position the door should be in." ) ;      // a state of transition. Its probably an error
// \/\/CHANGED CODE \/\/
   check_door() ;                                                               // as we should never leave our loop until out of transient
// /\/\CHANGED CODE /\/\
  }       
What do you guys think?

My concern with such a change is that by definition, the door is in an indeterminate position and we have no idea if anything is in the portal's threshold. By blinding lowering the door it may pose a risk for any critter in the way. Granted, the door isn't direct drive but its still contrary to my preference for leaning toward a builtin safety. So its not that its wrong, I personally don't feel its as safe. Ultimately, that's not my call to make.


Good point, however, your code will open the door, then lower it should the light level be below the threshold, all I have done is eliminate the need for the door to open before checking where it should be, hopefully saving a little battery life in the process.

As for animal safety, the door is simply being lowered by the spool winding down, the only force pulling the door down is gravity, there is no force pushing the door downwards, I doubt anything but a small rodent would be injured by the force of a fairly light door being lowered relatively slowly.

Plus, for what I want to use this circuit for (chicken coop door opener) that safety measure becomes pretty much redundant, chickens tend to stay away from the door when it's time for bed.

Nice work on the safety measures there, seems like this would be useful in the testing phase of installation. How would I go about implementing a test mode option (delay becomes next to nothing before opening/closing based on LDR value), then a manual close and a manual open button?

Just a simple interrupt at the top for each pin?, something like this:
if (manualclose == high){
lower_door()
}
and the inverse for manual open?

Excuse the syntax, I code not good.                                                                                                                                               
2  Using Arduino / Programming Questions / Re: [Video] Electronic Dog Door - few weird things happening ?? on: June 18, 2011, 07:03:57 pm
Also added:
Code:
digitalWrite( motor_direction, LOW);

after digitalWrite (motor_power, LOW); in the lift door function, there is no need for the relay to remain on when the door is raised, this just uses up more power than necessary.
3  Using Arduino / Programming Questions / Re: [Video] Electronic Dog Door - few weird things happening ?? on: June 18, 2011, 06:25:22 pm
Hi guys, great work you're doing here, just thought i'd throw in my $0.02.

I have got the code working fine, however, I have changed the part when both inputs are read as 0 to do a double check.

The code I have changed is here:
Code:
if( (0 == top_switch) && (0 == bot_switch) ) {                               // Either we have an error or the door is in
   Serial.println( "0, 0, error or transient door position; Checking what position the door should be in." ) ;      // a state of transition. Its probably an error
// \/\/CHANGED CODE \/\/
   check_door() ;                                                               // as we should never leave our loop until out of transient
// /\/\CHANGED CODE /\/\
  }       

And I have added this above void lower_door:
Code:
void check_door()
{
  if( (light_level_smoothed < sunset_threshold) && (0 == top_switch) ) {     // door is up, sun is setting - lower door
      Serial.println( "light level < sunset_threshold and bottom switch is not active - lowering door..." ) ;
      lower_door() ;
    }
   else if( (light_level_smoothed > sunrise_threshold ) && (0 == bot_switch) ) {  // door is down, sun is rising - lift door
      Serial.println( "light level > sunrise_threshold and top switch is not active - raising door..." ) ;
      lift_door() ;
    }
}

This stops the door from opening itself again if it doesn't need to. At least, that is what I intend for it to do.

What do you guys think?
4  Using Arduino / Programming Questions / Re: Debouncing multiple inputs on: June 18, 2011, 10:59:53 am
Also, the delay(1000); is there to cause each loop to be 1 second, this allows the delay for the opening and closing to be set in seconds, just to make it a little easier to get the delays correct.

This project is for a chicken coop door opener, using a latching dpdt relay, hence the need for 2 outputs, one for each coil.
5  Using Arduino / Programming Questions / Re: Debouncing multiple inputs on: June 18, 2011, 10:48:21 am
Paul could be correct, I have changed some code to hopefully tell me when the manual close and the manual open button is pressed, however, the value seems to remain constant.

Here is the updated code:
Code:
//sensors and outputs
int sensorPin = A0;    // select the input pin for the LDR
int ledPin1 = 12;      // select the pin for one relay coil
int ledPin2 = 13;      // select the pin for the other relay coil
//
//buttons
int testpin = 11;      // select the pin for the test enable switch
int testpinstate = 0;   
int manualclosepin = 10;   // select the pin for the manual close button
int closestate = 0;
int closestateprint = 0;
int manualopenpin = 9;   // select the pin for the manual open button
int openstate = 0;
int openstateprint = 0;
//
//variables
int sensorValue = 0;  // variable to store the value coming from the sensor
boolean relayshouldbe = HIGH;   // what value the relay should be (will be compared against the relaycurrent variable to determine if any change needs to happen.
boolean relaycurrent = HIGH;   // what state the relay is currently in
int relaystate = 0;
int delayclose = 4;   // variable for the closing delay
int counterclose = 0;
int delayopen = 4;   // variable for the opening delay
int counteropen = 0;
int limit = 100; //sets the sensor value limit
//



void setup() {

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(testpin, INPUT);
  pinMode(sensorPin, INPUT);
  pinMode (manualclosepin, INPUT);
  pinMode (manualopenpin, INPUT);
  Serial.begin(9600);
}


void loop(){ 
    sensorValue = analogRead(sensorPin);
    testpinstate = digitalRead(testpin);
    openstate = digitalRead(manualopenpin);
    closestate = digitalRead(manualclosepin);
 
  // sets the delay based on the test switch input
  // if the test switch is high, the delay is reduced
if (testpinstate == HIGH){
    delayclose = 4;
    delayopen = 4;}
else{delayclose = 1200;
    delayopen = 400;}
        // Manual open/close settings, only enabled when test mode is enabled

        if ((closestate == HIGH) && (openstate == LOW)){
        relayshouldbe = LOW;
        closestateprint = 1;
        openstateprint = 0;}

        if ((openstate == HIGH) && (closestate == LOW)){
        openstateprint = 1;
        closestateprint = 0;
        relayshouldbe = HIGH;}
        // I didn't want both buttons being high to confuse things
        // so i made it do this instead.
        if ((openstate == HIGH) && (closestate == HIGH)){
        openstateprint = 0;
        closestateprint = 0;
        Serial.print("You're doing it wrong.");}


//


if ((closestate == LOW) && (openstate == LOW)){
openstateprint = 0;
closestateprint = 0;
  // This is for delay and as a jitter elimination method.
  if(sensorValue > limit){
  counteropen = counteropen + 1;
  }
  else{ counteropen = 0; }
 
  if(sensorValue < limit){
  counterclose = counterclose + 1;
  }
  else{ counterclose = 0;  }
  //
 
if ((counteropen > delayopen) && (relaycurrent == LOW)){

  relayshouldbe = HIGH;}
 
 
if ((counterclose > delayclose) && (relaycurrent == HIGH)){
 
  relayshouldbe = LOW;
  }
 
if (counteropen > delayopen + 2){
  counteropen = counteropen -1;
}
if (counterclose > delayclose +2){
  counterclose = counterclose - 1;
}

if ((relayshouldbe == HIGH) && (relaycurrent == LOW)){
digitalWrite(ledPin1, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
relaycurrent = HIGH;
relaystate = 1;}

if ((relayshouldbe == LOW) && (relaycurrent == HIGH)){
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin2, LOW);
relaycurrent = LOW;
relaystate = 0;}

// These are mainly to see what's going on and to check everything's working ok
Serial.println(" ");
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.println(" ");
Serial.print("Open Delay: ");
Serial.print(delayopen);
Serial.println(" ");
Serial.print("Close Delay: ");
Serial.print(delayclose);
Serial.println(" ");
Serial.print("relay state: ");
Serial.print(relaystate);
Serial.println(" ");
Serial.print("Open counter: ");
Serial.print(counteropen);
Serial.println(" ");
Serial.print("Close counter: ");
Serial.print(counterclose);
Serial.println(" ");
Serial.print("Manual Close state: ");
Serial.print(closestateprint);
Serial.println(" ");
Serial.print("Manual Open state: ");
Serial.print(openstateprint);
Serial.println(" ");
delay(1000);

}
}


6  Using Arduino / Programming Questions / Debouncing multiple inputs on: June 18, 2011, 08:55:09 am
Hi all, I have built a circuit, and it's working fine, except that when I press a button to perform an action, sometimes the button doesn't do anything, and i have to toggle it a few times before it registers. I believe this is a problem with debouncing, however, I have multiple buttons which have the same issue, so my question is, how do I debounce multiple inputs?

Here is my code:
Code:
//sensors and outputs
int sensorPin = A0;    // select the input pin for the LDR
int ledPin1 = 12;      // select the pin for one relay coil
int ledPin2 = 13;      // select the pin for the other relay coil
//
//buttons
int testpin = 11;      // select the pin for the test enable switch
int testpinstate = 0;   
int manualclosepin = 10;   // select the pin for the manual close button
int closestate = 0;
int manualopenpin = 9;   // select the pin for the manual open button
int openstate = 0;
//
//variables
int sensorValue = 0;  // variable to store the value coming from the sensor
boolean relayshouldbe = HIGH;   // what value the relay should be (will be compared against the relaycurrent variable to determine if any change needs to happen.
boolean relaycurrent = HIGH;   // what state the relay is currently in
int relaystate = 0;
int delayclose = 4;   // variable for the closing delay
int counterclose = 0;
int delayopen = 4;   // variable for the opening delay
int counteropen = 0;
int limit = 100; //sets the sensor value limit
//



void setup() {

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(testpin, INPUT);
  pinMode(sensorPin, INPUT);
  pinMode (manualclosepin, INPUT);
  pinMode (manualopenpin, INPUT);
  Serial.begin(9600);
}


void loop(){ 
    sensorValue = analogRead(sensorPin);
    testpinstate = digitalRead(testpin);
    openstate = digitalRead(manualopenpin);
    closestate = digitalRead(manualclosepin);
 
  // sets the delay based on the test switch input
  // if the test switch is high, the delay is reduced
  if (testpinstate == HIGH){
    delayclose = 4;
    delayopen = 4;}
  else{delayclose = 1200;
    delayopen = 400;}
 
// Manual open/close settings, only enabled when test mode is enabled
if (testpinstate == HIGH){
  if ((closestate == HIGH) && (openstate == LOW)){
   relayshouldbe = LOW;}

  if ((openstate == HIGH) && (closestate == LOW)){
   relayshouldbe = HIGH;}
   // I didn't want both buttons being high to confuse things
   // so i made it do this instead.
   if ((openstate == HIGH) && (closestate == HIGH)){
   Serial.print("You're doing it wrong.");}
//
}

if ((closestate == LOW) && (openstate == LOW)){

  // This is for delay and as a jitter elimination method.
  if(sensorValue > limit){
  counteropen = counteropen + 1;
  }
  else{ counteropen = 0; }
 
  if(sensorValue < limit){
  counterclose = counterclose + 1;
  }
  else{ counterclose = 0;  }
  //
 
if ((counteropen > delayopen) && (relaycurrent == LOW)){

  relayshouldbe = HIGH;}
 
 
if ((counterclose > delayclose) && (relaycurrent == HIGH)){
 
  relayshouldbe = LOW;
  }
}
 
if ((relayshouldbe == HIGH) && (relaycurrent == LOW)){
digitalWrite(ledPin1, HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
relaycurrent = HIGH;
relaystate = 1;}

if ((relayshouldbe == LOW) && (relaycurrent == HIGH)){
digitalWrite(ledPin2, HIGH);
delay(1000);
digitalWrite(ledPin2, LOW);
relaycurrent = LOW;
relaystate = 0;}

// These are mainly to see what's going on and to check everything's working ok
Serial.println(" ");
Serial.println(sensorValue);
Serial.println(delayopen);
Serial.println(delayclose);
Serial.println(relaystate);
Serial.println(counteropen);
Serial.println(counterclose);
delay(1000);
}
7  Using Arduino / Sensors / Re: Dual element PIR for motion tracking on: June 10, 2011, 08:06:47 am
Ok, it appears to be working, I swapped out the PIR for a D203B sensor instead of the D203S, and swapped out the resistors for a 1ohm and a 10k ohm resistor.

Am I correct in saying this will give me 10000 times gain?

Many thanks, n00bz0rz.
8  Using Arduino / Sensors / Re: Dual element PIR for motion tracking on: May 19, 2011, 04:01:25 pm
Connected using the arduinos 5v out to a LM358N op-amp using a 10k and a 100k resistor for the amplification.

The sensor itself has a V in of the arduinos 3v3 output, and the op-amp is using the 5v output, which i would hope allow for enough gain to show any significant change in input.

I have the sensor connected up to the Analog input (as shown in the code above) which i hoped would allow me to have a little leeway before performing any action (a sort of jitter elimination method) should this work? does the sensor need to be digital?

Thanks for the reply smiley
9  Using Arduino / Sensors / Dual element PIR for motion tracking on: May 17, 2011, 07:59:51 pm
Hi guys, I want to set up a circuit based around a dual element PIR sensor (D203S, datasheet here: http://www.electronikdreamz.com/data/sensor/d203s.pdf)

The idea is to be able to build a device with a servo in order to follow someone around a room. This is why I bought a dual element PIR sensor, in order to sense if the person is moving from left to right and vice versa, and to step the servo accordingly, following the person around the room by keeping them centralized in the sensor.

I assumed this could be done using analogRead in order to get a base number when nothing is in view of the sensor, and a higher(lower) number when someone is to the left of it, and a lower(higher) number when someone is to the right of it.

I don't seem to be seeing any change in value from the sensor though, could this be the code or the hardware wired up wrong?

Here is the code i am using:

Code:
int calibrationTime = 10;

int pirPin = A0;
int ledPin = 13;
int pirVal = 0;


void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //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(){

     pirVal = analogRead(pirPin);
     Serial.println(pirVal);
     delay(200);
}

The code is very basic at the moment, this is just to test if I have wired the device up correctly, and to see the changes in values when I move my hand near it.

Am I doing something wrong?
10  Using Arduino / Sensors / Re: LDR monitoring from breadboard on: March 30, 2011, 08:16:33 pm
It's not causing me problems as such, i'm just trying to get the same value going to both boards, so I know for certain what my threshold needs to be. I need to plug a second arduino into the standalone arduino in such a way that it reads the exact same value that the standalone would be reading.

As for the multimeter, I have one, but how would I translate the voltage readings into the analogue values the arduino would read from it?

Cheers smiley
11  Using Arduino / Motors, Mechanics, and Power / Re: Latching/Bistable 12v relay controlling on: March 30, 2011, 05:55:55 pm
I had used the transistors previously without base resistors in a different circuit, I must have fried them then.

The sketch was just a simplified drawing of what I was trying to do (with a 390 ohm resistor to the base  smiley-razz), you get the general idea, the transistors actually get their power from the same battery (about 10v) which powers the rest of the circuit, with the ground and +5v rails being connected to the arduino and anything else which requires 5 volts.

The code should monitor the LDR for its value, if it's above the threshold value which is preset in the code, it starts incrementing a counter (counteropen), which once that goes above a certain value (delay1) it clicks the relay on which should power the motor so it can open a chicken coop door. The same applies in reverse. The delay is both for validation and to make sure the chickens would definitely be inside the coop when it closes.

Make sense to you?

Any more questions, feel free to ask smiley
12  Using Arduino / Motors, Mechanics, and Power / Re: Latching/Bistable 12v relay controlling on: March 30, 2011, 11:56:39 am
Ok, had a crack at the code again, see what you guys think:
Code:
int LDR_pin = 0; // analog pin 0 (connect LDR here)

int LDR_val = 0; //initial LDR value

int LEDpin = 13; //This is the relays coil 1

int LEDpin2 = 12; //This is the relay coil 2

int counterclose = 0; //counter for closing validation

int counteropen = 0; //counter for opening validation

int Delay1 = 2;

int Delay2 = 2;

int TestEnablePin = 4; //connected to switch saying if the test mode is enabled, if yes, delay is much shorter
int TestEnable = 0;

boolean relayState = false;
boolean relayShouldBe = false;


int threshold = 80; // a threshold to decide when the relay turns on



void setup(){



  // declaration of pin modes

  pinMode(LDR_pin, INPUT);

  pinMode(LEDpin, OUTPUT);

  pinMode(LEDpin2, OUTPUT);

  pinMode(TestEnablePin, INPUT);


  // begin sending over serial port

  Serial.begin(9600);

}



void loop(){
  TestEnable = digitalRead(TestEnablePin);

  // read the value on analog input

  LDR_val = analogRead(LDR_pin);

  if (TestEnable == HIGH)
  {
    Delay1 = 2;
    Delay2 = 2;
  }
  else
  {
    Delay1 = 1200;
    Delay2 = 1200;
  }


  // if value greater than threshold turn on LED

  if (LDR_val < threshold) counterclose = counterclose+1;
  else counterclose = 0;

  if (counterclose > (Delay1)){
    relayShouldBe = false;
  }


  if (LDR_val > threshold) counteropen = counteropen+1;
  else counteropen = 0;

  if (counteropen > (Delay2)){//set delay here, 1 loop = 1 second
    relayShouldBe = true;
  }


  if (relayShouldBe == false && relayState == true){
    digitalWrite(LEDpin, HIGH);
    delay(100);
    digitalWrite(LEDpin, LOW);
  }

  if (relayShouldBe == true && relayState == false){
    digitalWrite(LEDpin2, HIGH);
    delay(100);
    digitalWrite(LEDpin2, LOW);
  }


  // output 'LDR_val' value into the console

  Serial.print("LDR = ");
  Serial.print(LDR_val);


  Serial.print(" Counter close = ");
  Serial.print(counterclose);

  Serial.print(" Counter open = ");
  Serial.print(counteropen);

  Serial.print(" testpin = ");
  Serial.print(TestEnable);

  Serial.print(" Delay1 = ");
  Serial.print(Delay1);

  delay(1000);




}
13  Using Arduino / Sensors / LDR monitoring from breadboard on: March 30, 2011, 10:53:41 am
Hi guys, currently got an arduino on a breadboard, hooked up to an LDR, which will click a relay once the light level goes above the threshold value for a preset amount of time, and click it off once it goes back below the threshold.

My issue is essentially trying to get a reliable threshold value from the LDR, ie, how can I connect the LDR to another arduino board while keeping the LDR part of the breadboard circuit, as I don't want to remove it in case the actual circuit wiring affects the reading of the LDR when I plug it back in.

So, how do I go about monitoring the sensor from another arduino while keeping it part of the circuit?

Many thanks!
14  Using Arduino / Motors, Mechanics, and Power / Re: Reversing Motor Problems on: March 29, 2011, 08:16:15 pm
You could power, reverse and stop a motor with a h-bridge I guess, but this is a little more tricky, you have to know exactly the currents and voltages you'd be dealing with in your motor, as some h-bridges don't like high current/voltage as I found out when one burst into flames on my breadboard.
15  Using Arduino / Motors, Mechanics, and Power / Re: Reversing Motor Problems on: March 29, 2011, 08:11:07 pm
Nope, because if you de-energise the relay, the normally closed contacts will close, and you will have power going to your motor in the normal direction.

When I say de-energise the relay, I mean, disconnect the coil of the relay (un-click it)
Pages: [1] 2