Arduino not Recognizing Input Signal & Servo Help!

Hi Everyone!

I am looking for some help regarding two things on my Arduino project. The first and most important question that I have is why is it that when I give my Arduino the signal on pin 2, the led connected to pin three doesn't turn on.

The second question I have is how do I make it so that when I send a signal to pin 4, the servo will go right and when a signal is applied to pin 5 the servo will go left?

I am somewhat new to the Arduino and I have not used a servo with it yet so this is all new to me.

Here is the code that I have so far:

// This code is the basic first steps of the Go-Kart drone.
////////////////// Written by: Max Kulik //////////////////

#include <SoftwareSerial.h>
#include "TinyGPS.h"                 // Special version for Arduino IDE 1.0
#include <Servo.h>                   // Include Servos

TinyGPS gps;
SoftwareSerial nss(6, 255);          // Yellow wire to pin 6

Servo myservo; 
int pos = 0;                         // variable to store the servo position
int in = 2;                          // Forward Movement Input pin
int out = 3;                         // Forward Movement Output pin

void setup() {
  Serial.begin(115200);
  nss.begin(4800);
  Serial.println("Reading GPS");      // Just Serial Info
  Serial.println("Lat. | Lon.");      // Just Serial Info
  pinMode(in, INPUT);                 // GoKart Forward Movement Input Pin
  pinMode(out, OUTPUT);               // GoKart Forward Movement Output Pin
  myservo.attach(9);                  // Attaches the servo on pin 9 to the servo object
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) {   // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);
  if (digitalRead(in) == HIGH)        // If RPi Sends Forward Sig...
  {
  digitalWrite(out, HIGH);            // Then Move Forward...
  } 
  else {
  digitalWrite(out, LOW);             //If nothing, then do nothing
  }
  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 
  } 
  }
}

// Get and process GPS data
void gpsdump(TinyGPS &gps) {
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  Serial.print(flat, 4); Serial.print(", "); 
  Serial.println(flon, 4);
}

// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

Thanks in Advance
Max Kulik

What output do you get from from gpsdump() ?
What do you see if you print newdata or feedgps() before testing its value ?

You should note that your while loop blocks execution of the program for the majority of the time so the button will only be checked every 2 seconds at most and even then only if feedgps() returns true, hence the need to know what its value is. You should consider using the principle used in the BlinkWithoutDelay example to make the program more responsive.

As to the servo

if (digitalRead(4) == HIGH)
{
  myservo.write(180); 
}
else if (digitalRead(5) == HIGH)
{
  myservo.write(0); 
}

Note that if both pins 4 and 5 are HIGH the first part of the if/else will be executed and not the second part

Well right now I only have the GPS support in the code more for a place holder right now more then anything. The "Drone" will have GPS support later down the road, but to answer you question this is all it will print as far as GPS status goes (And this is because that is all I programmed it to do as well):

Reading GPS...
Lat. | Lon.
latcoordhere, loncoordhere
latcoordhere, loncoordhere
etc.

Also about what you were saying with the 2 second delay that I have set up for the GPS Module to get a fix, are you saying that it will not check to see if the button is pressed for the two second delay that is written in the code for the GPS to find a fix?

Replace the while with an if so that the program will continue if 2 seconds have not passed. If 2 seconds have passed read the gps and only then reset the start variable to millis()

As it stands your program resets newdata to false every time through loop() whereas it would probably be a better idea to set it to true if the GPS data has changed since the last time it was read else set it to false. That way you can act on a change of GPS data.

Currently the signal from the RPi is only read if newdata is true but I expect that you would like it to be read each time through loop() to make it more responsive, so put the code in the loop() function and remove the dependency on the GPS signal unless it is crucial that there is a GPS signal before reading the input from the RPi.

It might help if you were to describe what the program should do based on the GPS data and input from the RPi and what the servo should do and when.

Alright so the idea behind the GPS is somewhat complex right now. I am going to be making a "Drone type" vehicle that will be controlled over a Web Interface that will be resting on the Raspberry Pi. Before I go any further, I have made a video explaining some of the ideas I have in mind and could give you a better understanding on what I am thinking of doing:

The reason I have GPS on the system right now is because I am planning for the Arduino get a GPS fix of it's current location. So once it finds that fix, I will then go on the Web interface and type the new location/choord in that I want the drone to move to. It will use the GPS to guide its self to the correct location. Of course this will not work without some ping sensors telling the Arduino when there is a curb nearby. My idea is that when the Drone is moving to the GPS choords that it has been given, it will have ping sensors on the left, right, and front that will let it know if it is starting to steer off the road. Then It will correct it's position a few feet away from the curb and then begin heading towards the GPS choords that I have given it.

The reason I had the GPS just in there getting a fix was because I just wanted to start off with getting the "drone" to move back and forth as a start, then steering, then GPS.