Your codes are small, and they are better posted in line. You will get more people looking at them. As attachments, people on phones can't see them, and others don't like the extra steps involved in downloading and getting into a viewer.
// ichi411-------_TX_-- RC - contorls two motor and a led laser
int xAxis, yAxis;
int GuideLaserbuttom = A2;
int GuideLaser;
void setup() {
Serial.begin(9600);
pinMode(GuideLaserbuttom, INPUT);
digitalWrite(GuideLaserbuttom, HIGH);
}
void loop() {
xAxis = analogRead(A0); // Read Joysticks X-axis
yAxis = analogRead(A1); // Read Joysticks Y-axis
GuideLaser = digitalRead(GuideLaserbuttom);//Turning on/off the led laser
Serial.write(xAxis / 4); // Dividing by 4 for converting from 0 - 1023 to 0 - 256, (1 byte) range
Serial.write(yAxis / 4);
Serial.write(digitalRead(GuideLaser));
delay(30);
}
// ichi411-------_RX_-- RC - contorls two motor and a led laser
int x_pos;
int y_pos;
int x = 0;
int y = 0;
//Motor Pins
int EN_A = 11; //Enable pin for first motor
int IN1 = 9; //control pin for first motor
int IN2 = 8; //control pin for first motor
int IN3 = 7; //control pin for second motor
int IN4 = 6; //control pin for second motor
int EN_B = 10; //Enable pin for second motor
int motor_speed1;
int motor_speed2;
//GuideLaser
int GuideLaser;
int GuideLaserP = 4; //control pin for GuideLaser
void setup ( ) {
Serial.begin (9600); //Starting the serial communication at 9600 baud rate
//Initializing the motor pins as output
pinMode(EN_A, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(EN_B, OUTPUT);
pinMode(GuideLaserP, OUTPUT);
}
void loop () {
x_pos = 510;
y_pos = 510;
while (Serial.available() == 0) {}
x = Serial.read();
delay(10);
y = Serial.read();
delay(10);
GuideLaser = Serial.read();
delay(10);
if (GuideLaser == HIGH) {
digitalWrite(GuideLaserP, HIGH); ////LED control part.
}
else {
digitalWrite(GuideLaserP, LOW);
}
x_pos = x * 4;
y_pos = y * 4;
if (x_pos < 400) { //Rotating the left motor in clockwise direction
motor_speed1 = map(x_pos, 400, 0, 0, 255); //Mapping the values to 0-255 to move the motor
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(EN_A, motor_speed1);
}
else if (x_pos > 400 && x_pos < 600) { //Motors will not move when the joystick will be at center
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
else if (x_pos > 600) { //Rotating the left motor in anticlockwise direction
motor_speed1 = map(x_pos, 600, 1023, 0, 255);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(EN_A, motor_speed1);
}
if (y_pos < 400) { //Rotating the right motor in clockwise direction
motor_speed2 = map(y_pos, 400, 0, 0, 255);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(EN_B, motor_speed2);
}
else if (y_pos > 400 && y_pos < 600) {
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else if (y_pos > 600) { //Rotating the right motor in anticlockwise direction
motor_speed2 = map(y_pos, 600, 1023, 0, 255);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(EN_B, motor_speed2);
}
}
Some comments.
What laser are you using? Many of the 5v laser pointers I see online are 40ma devices, and that is more than an Arduino pin can provide.
On the TX, you are using INPUT_PULLUP for your button.
pinMode(GuideLaserbuttom, INPUT);
digitalWrite(GuideLaserbuttom, HIGH);
If wired properly, this will read LOW when pressed.
The RX code appears to be looking for a HIGH when pressed
GuideLaser = Serial.read();
delay(10);
if (GuideLaser == HIGH) {
digitalWrite(GuideLaserP, HIGH); ////LED control part.
}
else {
digitalWrite(GuideLaserP, LOW);
}
Your comminication protocol is very weak, and is likely to get out of sync. Look at Robin2's tutorial on [Serial Communications Basics.
](Serial Input Basics - updated - Introductory Tutorials - Arduino Forum)