Hi, I've newly got my first Arduino and I already did some basic LED projects.
Now I would like to control a DC Motor (Igarashi 20G-150) and for that i decided to use the motor controller Pololu Trex jr coupled to the Arduino 2009.
The main goal of this small Projekt is to build a sun tracking system.
The tasks are quite simple:
The difference between to two photodiodes determines if the DC motor rotates full speed to the left or to the right.
I have already made a simplified sketch with two LEDs simulating the motor direction using simply the Arduino and it works properly.
//Project SUN Tracking1
//Pin assignment
int GreenPin=10;
int RedPin=11;
int PD1Pin=0;
int PD2Pin=1;
//Variable declaration
int DifValue=0;
int PD1Value=0;
int PD2Value=0;
int Range=15;
void setup(){
Serial.begin(9600);
Serial.flush();
pinMode(GreenPin, OUTPUT);
pinMode(RedPin, OUTPUT);
}
void loop(){
// Read and display Phododiode Values
PD1Value = analogRead(PD1Pin);
Serial.print("PD1 Value: ");
Serial.println(PD1Value);
PD2Value = analogRead(PD2Pin);
Serial.print("PD2 Value: ");
Serial.println(PD2Value);
// Difference value between Photodiodes
DifValue = PD1Value-PD2Value;
Serial.print("Dif Value: ");
Serial.println(DifValue);
// Decison Logic
if(DifValue < -Range ) {
digitalWrite(GreenPin,LOW);
digitalWrite(RedPin,HIGH);
Serial.print(" ");
}
if(DifValue > Range ) {
digitalWrite(RedPin,LOW);
digitalWrite(GreenPin,HIGH);
Serial.print(" ");
}
if(DifValue >= -Range && DifValue <= Range) {
digitalWrite(RedPin,LOW);
digitalWrite(GreenPin,LOW);
Serial.print("Maximum intensity ");
}
delay(1000);
}
Now my questions reside in:
-
the code for Serial interface code between the Arduino and the Trex jr
-
the code with specific commands to send to TRex jr
-
Rotate Motor 1 to the Left
-
Rotate Motor 1 to the Right
-
The Trex jr jumper settings for this case
I would be very thankfulif someone could provide me an example for this configuration.
I know that for this purpose i could simple use a H-Bridge connected to the Arduino, but this way (with the Trex jr) i can learn the basics of Serial communication.
Thanks in advance for you help!
See ya...
Tom D