Help Needed! Is this Possible?

Hi, Im an Architecture student and i've got to make a responsive machine.

My design includes a twisting surface that reacts as people walk past.

I am looking to use 2 servos to control and twist both ends of a surface and looking at using 3x IR transmitters & Receivers to trigger the servos to turn 'x' degrees when the signal is broken.

My questions are:
Is this possible to use IR transmitters & Receivers (like a sensor) to trigger a certain part of the code 'when the signal is broken'.

As in if you walk past the first set which triggers the left servo to turn 90deg;
Walk past the second set which triggers the left servo to turn another 90deg and the right servo to turn 90deg;
then walk past the third set which triggers the right servo to turn 90deg so the surface is then fully closed.

Is there any sample codes as i have never used an Arduino board or electronics before, but will be using it alot for my design module, hopefully be able to use the Firefly plugin for 3D modelling.

And if any one is able to help draw up a schematic would be MUCH appreciated.

Please email me richardpeterberry@ymail.com

Regards
Richard

Fairly common type of request, like the below from yesterday. Best bet is to use google advanced search to search the forum for what you need.

http://arduino.cc/forum/index.php/topic,76801.msg580313.html#msg580313

For this kind of setup you're basically gonna have 3 edge detecting if statements. inside each statement theres an servo instruction. Since the arduino works by looping a set of instructions edge detection is critical or else the arduino might send the "rotate servo" command several times per second.

Provided some links that should help you get an idea on what you need.

http://www.arduino.cc/playground/ComponentLib/Servo

Sure, you get a couple of units like this
http://www.mcmelectronics.com/browse/Photobeam-Curtain-Sensors/0000000905&p=?gclid=CMKRmfXDiqwCFUKo4AodQxK0oA
Have the arduino do the servo thing when the beam is broken and an input pin is pulled low.

Can also do cheaper using discrete components, but for that you'll need more engineering help.

Thanks All for the advise, much appreciate it.

My eyeballs are burning doing all this reading, but slowly getting somewhere!

I can get the servo to read when the signal is blocked and perform an action eg, turn the servo 90deg, however its either 90 or back to 180. I need to try link this sensor with 2 other sensors so;

when you break the first sensor the left servo turns 90deg.
when you break the second (middle) sensor both servos turn 90deg.
then when you break the third (last) sensor the right servo turns 90.

Meaning if there was a surface (piece of paper) attached to both servos it would of turned a full 180 with a twist motion.

Please see image of sketch im trying to achieve.

I also cant seem to get the servo to turn slower, ive tried using delay but seems to just crash the board :astonished:

Here is the code i have created to get the action so far:

/*
using infrared transmitter and reciever to trigger servo for responsive surface
richard peter berry
richardpeterberry.com

*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo

// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int threshold = 1016; // an arbitrary threshold level that's in the range of the analog input

void setup() {
// attach servo
myservo.attach(3);
// initialize serial communications:
Serial.begin(9600);
}

void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the SERVO:
if (analogValue < threshold) {
myservo.write(180); // set servo to full
} else if (analogValue > threshold) {
myservo.write(90); // set servo to mid-point
}

// print the analog value:
Serial.println(analogValue, DEC);

}

my infrared reciever recieves values between 1013 and 1017 hence the threshold value. this value is fed into Anolgue in A0.

Any ideas for the script would be much appreciated.

Regards
Richard

I also cant seem to get the servo to turn slower, ive tried using delay but seems to just crash the board

Tried using it where/how? The delay() function can not possibly cause the Arduino to crash.

I also cant seem to get the servo to turn slower, ive tried using delay but seems to just crash the board

The servo "sweep" example code shows how to make the overall servo movement slower.

Damn, nice drawing!

I've tried using the servo sweep example for delay. like so;

// if the analog value is high enough, turn on the SERVO:
if (analogValue < threshold) {
myservo.write(180); // set servo to full
delay(5000)
} else if (analogValue > threshold) {
myservo.write(90); // set servo to mid-point
delay(5000)
}

but seems to slow the readings in the serial and doesnt move the servo just twitches.

any ideas?

Look at the sweep example again - it moves the servo in smaller steps using this construct:

for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }

Compare that to your latest code which does the servo move in one and waits afterwards. Sweep should serve you better; the crash is something of a mystery though.

Ive found why it seemed to crash in my delay i was putting (5000) not just seconds (5). But the problem is it still isnt slowing the servo down just the serial read, so its reading every 5 seconds not the motor taking 5 seconds?

how can i seperate a code within a code?

/*
using infrared transmitter and reciever to trigger servo for responsive surface
richard peter berry
richardpeterberry.com

*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo
int pos = 180;
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int threshold = 1016; // an arbitrary threshold level that's in the range of the analog input

void setup() {
// attach servo
myservo.attach(3);
// initialize serial communications:
Serial.begin(9600);
}

void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
for(pos = 180; pos > 0; pos -= 1) // goes from 0 degrees to 180 degrees
// if the analog value is high enough, turn on the SERVO:
if (analogValue < threshold) {
myservo.write(180); // set servo to full
delay(5); // waits 15ms for the servo to reach the position
} else if (analogValue > threshold) {
myservo.write(90); // set servo to mid-point
delay(5); // waits 15ms for the servo to reach the position
}

// print the analog value:
Serial.println(analogValue, DEC);

}

This should be closer to what you want:

void loop()
{
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
if (analogValue < threshold) 
  {
  for(pos = 90; pos < 180; pos++)  // goes from 90 degrees to 180 degrees
    {
    myservo.write(pos);
    delay(5);
    }
  } 
else
  {
  for(pos = 180; pos > 90; pos--)  // goes from 180 degrees to 90 degrees
    {
    myservo.write(pos);
    delay(5);
    }
  } 
Serial.println(analogValue, DEC);
}

Another way to do it. This way it will sweep but also turn back mid-range if the target moves.

void loop() {
  // read the value of the potentiometer:
  int analogValue = analogRead(analogPin);

  // if the analog value is high enough, turn on the SERVO:
  if (analogValue < threshold) {
    pos++;
  } else {
    pos--;
  }

  pos = constrain(pos, 90, 180); // keeps pos within 90 to 180

  myservo.write(pos);
  delay(5); // increase to sweep more slowly
}