So there were several problems with this project. I had a software problem with my Mac. You have to run a program that is included with Arduino to allow the computer to receive the data from the board. Once I solved that problem I had to adjust the if statement through the programing and selecting the resistance in the static resistor. Once that was solved I could not get the motor to turn on and off. This was due to two problems. One was that the power kept on falling out and I did not notice. Second was the resistor leading to the transitor. Once that was removed the motor ran. Unfortunately my cardboard car could not run on the motor due to weight. So I made a boat. It is not waterproof so I need help in creating a water-proof case for the motor. The TIP120 runs VERY hot I need a more powerful transistor. I might post a video of the boat running.
The code:
//Arduino analogRead Code Sample
int sensorPin = 1; // select the input pin for sensor
int motorPin = 13; // select the pin for the LED/Motor
int ledPin = 4; // select the pin for the LED/Motor
int val = 0; // variable to store the sensor value
byte treatedVal=0;
void setup() {
pinMode(motorPin, OUTPUT); // declare the motorPin as an OUTPUT
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(sensorPin,INPUT); //both digital and analog pin set to input
Serial.begin(9600); // connect to the serial port
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor
treatedVal = val/4; //converts to 8-bit numbers
Serial.println(treatedVal, DEC); // send the treated value for sensor
if (val > 700) { //checking againt a treshold 700
digitalWrite(motorPin, HIGH); // turn the motorPin on
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(motorPin, LOW); // turn the motorPin off
digitalWrite(ledPin, LOW);
}
}