Go Down

Topic: Need Short Program Written Today (Read 1 time) previous topic - next topic

scolberg

I need a version of the code neccesary to make the prop dropper described here work.   http://www.nutsvolts.com/index.php?/blog/post/the_halloween_prop_dropper/

I can afford 30 USD

Functionality needed.

When triggered by a PIR a standard servo rotates 90 degrees, an LED is lit,  the program pauses 10 seconds, LED Off, a second continious rotation servo rotates for a variable time.  The variable time is controlled by a potentimeter.  Program ignores the trigger for 15 seconds and then monitors the trigger.

Contact me directly scarytinker at dslextreme.com

doublet

#1
Feb 17, 2011, 09:36 pm Last Edit: Feb 17, 2011, 09:54 pm by doublet Reason: 1
Do you still need it?

EDIT:
Here's a program to steer you in the right direction - I don't know how to drive a continuous servo:

Code: [Select]
#include <Servo.h>
Servo servo_normal;

int PIR_pin = 1; // port of the PIR
int pot_pin = 1; // port of the potentiometer
int LED_pin = 1; // port of the LED
int servo_normal_pin = 1; // port of the normal servo
int servo_cont_pin = 1; // port of the continious servo
int pot_value = 0;
int servo_value = LOW;
int servo_normal_value = 0;

void setup() {
  servo_normal.write(0);
  pinMode(PIR_pin, INPUT);
  pinMode(pot_pin, INPUT);
  pinMode(LED_pin, OUTPUT);
  pinMode(servo_normal_pin, OUTPUT);
  pinMode(servo_cont_pin, OUTPUT);

}

void loop() {
  servo_value = digitalRead(PIR_pin);
  if(servo_value = HIGH){
    // motion detected
    if(servo_normal_value == 0 || servo_normal_value == 90){
      servo_normal_value += 90;
    } else{
      servo_normal_value = 0;
    }
    servo_normal.write(servo_normal_value);
    digitalWrite(LED_pin, HIGH);
    delay(10000);
    digitalWrite(LED_pin, LOW);
   
    pot_value = analogRead(pot_pin);
    // add the continuous servo part here
    delay(15000);
  } else{
    // this will execute when there is no motion detected   
  }
 
}
Sorry God members, I'm an atheist.

scolberg


doublet

You will have to add the contuous servo part yourself, as I said, I've never worked with one. Also, be aware that the 'rotate servo 90°' part will do that only once, I programmed it as you asked. However, in the video, it seems like it does that multiple times. This code should do like in the video:

Code: [Select]
#include <Servo.h>
Servo servo_normal;

int PIR_pin = 1; // port of the PIR
int pot_pin = 1; // port of the potentiometer
int LED_pin = 1; // port of the LED
int servo_normal_pin = 1; // port of the normal servo
int servo_cont_pin = 1; // port of the continious servo
int pot_value = 0;
int servo_value = LOW;
int servo_normal_value = 0;

void setup() {
  servo_normal.write(0);
  pinMode(PIR_pin, INPUT);
  pinMode(pot_pin, INPUT);
  pinMode(LED_pin, OUTPUT);
  pinMode(servo_normal_pin, OUTPUT);
  pinMode(servo_cont_pin, OUTPUT);

}

void loop() {
  servo_value = digitalRead(PIR_pin);
  if(servo_value = HIGH){
    // motion detected
    for( int loopvar; loopvar < 10; loopvar++){
      if(servo_normal_value == 0 || servo_normal_value == 90){
        servo_normal_value += 90;
      } else{
        servo_normal_value = 0;
      }
      servo_normal.write(servo_normal_value);
      delay(250);
    }
    digitalWrite(LED_pin, HIGH);
    delay(10000);
    digitalWrite(LED_pin, LOW);
   
    pot_value = analogRead(pot_pin);
    // add the continuous servo part here
    delay(15000);
  } else{
    // this will execute when there is no motion detected   
  }
 
}
Sorry God members, I'm an atheist.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy