IR SENSOR AND TOWER PRO - CONNECT TO SAME UNO

I have one UNO board, which i going to connect to IR sensor and Tower Pro.
However, its not working.

Any idea why??

Any idea why??

I have a bunch of ideas why but to narrow it down we need more information. "its not working." is a poor description of the problem.

Read the "how to use this forum-please read" sticky to see how to ask a question (see #11).

I know exactly what's wrong. Either it isn't connected up correctly, it's not powered properly or the code isn't doing what you think it should.

If you show us all those things then it may be possible to narrow the problem down even further.

Steve

//define pins. I used pins 4 and 5
#define irLedPin 4          // IR Led on this pin
#define irSensorPin 5       // IR sensor on this pin

int irRead(int readPin, int triggerPin); //function prototype

void setup()
{
  pinMode(irSensorPin, INPUT);
  pinMode(irLedPin, OUTPUT);
  Serial.begin(9600); 
  // prints title with ending line break 
  Serial.println("Program Starting"); 
  // wait for the long string to be sent 
  delay(100); 
}
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
              // a maximum of eight servo objects can be created
int pos = 0;    // variable to store the servo position
void setup() {
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
void loop() {
 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
 }
 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(15);                       // waits 15ms for the servo to reach the position
 }
}

You have two setup functions and only one loop function, plus a function prototype, but no corresponding function definition - what are you trying to tell us?

have 2 sketch in 2 different files.
I need to combine them and how to do it?

The motor should work once the sensor detect the item.

You said "it's not working", so I assume you've tried to combine the code - why not post that attempt?

Your servo code is just the example Sweep program. Your IR sensor code doesn't do anything but print "Program Starting", it never looks at the IR sensor.

So if you combine them you'll have a program which prints "Program Starting" then sweeps a servo forward and backward for ever. Is that really what you're trying to do?

Steve