need some major help with project...

can anybody tell me if this code is done properly? needs 1 sensor to activate 3 servo’s to turn 180 degress when light is detected then back to 0 degrees when no light is detected. If this is not correct, could you please help me fix the errors to make this project work.

#include <Servo.h>

Servo myservo;
Servo myservo1;
Servo myservo2; // create servo object to control a servo
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9);
myservo1.attach(10);
myservo2.attach(11); // attaches the servo on pin 9 to the servo object
// syntaxf 21c

int sensorPin = 3; //pin that the input fron LED
int val = low;

if (sensorPin == high) // if signal is high on 3 then run following
void setup ()
{
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(10);
myservo1.write(pos);
delay(10);
myservo2.write(pos);
delay(10); // waits 15ms for the servo to reach the position
}

if (sensorPin == low)
void setup ()
{
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(10);
myservo1.write(pos);
delay(10);
myservo2.write(pos);
delay(10); // waits 15ms for the servo to reach the position
}
}

Format-wise, take out the 2nd & 3rd void setup()

add

pinMode (sensorPin, INPUT);  // make sure the sensor can actually drive Lo & High 
// might have to change to an analogRead on an analog pin and make decisions based on value

void loop(){ 
// now read the sensor, change the if statement to:
if (digitalRead(sensorPin)== HIGH){

after it says int val = low. add } at the end to close out void loop(){

The visual difference between this

 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(10); 
    myservo1.write(pos);
    delay(10);
    myservo2.write(pos);
    delay(10);    // waits 15ms for the servo to reach the position 
  }

And this:

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

will be minimal.

Did you realise that you don’t need Arduino hardware to run the Arduino IDE?
You could have got your sketch to at least compile.

Does this look correct? Im new to this program…it may help me alot if i could see the whole layout with the fixtures included.
#include <Servo.h>

Servo myservo;
Servo myservo1;
Servo myservo2; // create servo object to control a servo
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9);
myservo1.attach(10);
myservo2.attach(11); // attaches the servo on pin 9 to the servo object

pinMode (sensorPin, INPUT);
Void loop ()
{
if (digitalRead(sensorPin)== HIGH){// if signal is high on 3 then run following
int val = low;
}

{
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’
myservo1.write(pos);
myservo2.write(pos);
delay(10); // waits 10ms for the servo to reach the position
}

if (digitalRead(sensorPin)== low)

{
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
myservo1.write(pos);
myservo2.write(pos);
delay(10); // waits 10ms for the servo to reach the position
}
}

Install the Arduino IDE, open it, paste your code into it, and click on “verify”.
Work through the error messages.
Humans are not good compilers.

Remember that C is case-sensitive.

if (digitalRead(sensorPin)== HIGH){// if signal is high on 3 then run following
int val = low;
}

Three things here:
You haven’t defined “sensorPin”,
“low” is spelled “LOW”, and “val” is a new variable that you have defined assigned a value to and are going to destroy in the next few nanoseconds.
Lose the "“int” off the front.

for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees

The loop goes from 0 to 179, not 180.

gabe,

You should try something that fits your programming skills. I suggest the tutorials. You're either trying to program with brute force/hodgepodge or end up relying on others to spoon feed you with code, neither of which works for you. There are lots of mistakes in your original code that beginners can pick out after a whole day of learning.

okay im trying my best to figure this out, and im making changes as a beginner… and much help is needed.

#include <Servo.h>

Servo myservo;
Servo myservo1;
Servo myservo2; // create servo object to control a servo
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9);
myservo1.attach(10);
myservo2.attach(11); // attaches the servo on pin 9 to the servo object
// syntaxf 21c

pinMode (sensorPin = INPUT); //pin that the input fron LED
val = LOW;
}
if (digitalRead(sensorPin) == HIGH) // if signal is high on 3 then run following

}
for(pos = 0; pos < 179; 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’
myservo1.write(pos);
myservo2.write(pos);
delay(10); // waits 10ms for the servo to reach the position
}

if (sensorPin == LOW)

{
for(pos = 179; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
myservo1.write(pos);
myservo2.write(pos);
delay(10); // waits 10ms for the servo to reach the position
}
}

pinMode (sensorPin = INPUT);   //pin that the input fron LED 
  val = LOW;

Why aren't you at least trying to compile this, or at least reading the reference material provided? http://arduino.cc/en/Reference/PinMode

"val" hasn't been defined, so assigning the value LOW to it is impossible.

myservo2.attach(11);  // attaches the servo on pin 9 to the servo objectClearly, it does no such thing.

Any clues as to what this comment // syntaxf 21c means?

What is it you are trying to achieve here? If you compiled this stuff, the compiler would give you errors, you would learn the meaning of those errors and move on and correct the code. This is wasting time.

I don’t know what the OP is trying to achieve by ignoring AWOL’s suggestion to simply paste the code in Arduino IDE and hit compile. It’s not helping. Please respect people’s comment if you want to get help.

One final comment:

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

If you were counting objects, would you count 1, 2, 3, or nothing, 1, 2?

If you were counting objects, would you count 1, 2, 3, or nothing, 1, 2?

Well, I've been a programmer for quite some time, so I'd count zero, one, two, obviously.

8)

ok…im still playing with this code…and applying the feedback im receiving yet im still confused…so im tryin once again…this is probably wrong but need me some correction here…help a buddy out…

#include <Servo.h>

Servo myservo;
Servo myservo1;
Servo myservo2; //create servo object to control a servo
int pos = 0 ; // variable to store the servo object
// these constants won’t change:
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment

void setup() {
// initialize serial communication:
Serial.begin(9600);
myservo.attach(9); //attaches the servo to pin 9
myservo1.attach(10); // attaches the servo to pin 10
myservo2.attach(11); // attaches the servo to pin 11
}

void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

// do something different depending on the
// range value:
switch (range) {
case 0: // your hand is on the sensor
Serial.println(“dark”);
break;
case 1: // your hand is close to the sensor
Serial.println(“dim”);
break;
case 2: // your hand is a few inches from the sensor
Serial.println(“medium”);
break;
case 3: // your hand is nowhere near the sensor
Serial.println(“bright”);
break;

for(pos = 0; pos < 179; pos +=1) //goes from 0 to 179 degree
{
myservo.write(pos);
myservo1.write(pos);
myservo2.write(pos);
delay(10); //wait 10ms for the servo to move
}
for (pos = 179; pos>=1; pos-=1)
{
myservo.write(pos);
myservo1.write(pos);
myservo2.write(pos);
delay(10);
}
}

You need to tell us what the problem is.

i am compiling this and towards the end: i am receiving expected '}' at end of input in function 'void loop () ': error: expected ' } ' at end of input

So, you need to match up your opening braces "{" with your closing braces "}". That's what the compiler is telling you.

(Hint: What closes your "switch"?)

@gabe when posting your code select it and use the # icon. That way you get it in a box like everyone else code.

If you put your cursor in the editing window and click just after a brace or bracket the program will highlight the matching brace, if it doesn't then there is not one that matches it.

Please use the “code” button when posting your code. Look at the picture attached. The “code” button is boxed in red.

code_button.png