Sensor Debug for Black Magic Mini Sumo Robot

Sensor Debug for Black Magic Mini Sumo Robot

The code below is the sensor debug code for black magic. While building the robot, we load this type of code and control the sensors. If the sensors do not work correctly, it will affect the operation of the entire robot.

/* JSumo Mini Sumo Robot Code
* Model Type: Black Magic
* Sensor DEBUG CODE
*/
//// Opponent Sensors Pin Definitions ////
#define LeftSensor 0
#define LeftDiagonalSensor 1
#define FrontSensor 2
#define RightDiagonalSensor 4
#define RightSensor A5
//// Line Sensor Pin Definitions ////
#define LeftLine A2
#define RightLine A1
//// Main Setup Function for Defining Inputs////
void setup() {
pinMode(LeftSensor, INPUT); // Digital sensors declared as input
pinMode(LeftDiagonalSensor, INPUT);
pinMode(FrontSensor, INPUT);
pinMode(RightDiagonalSensor, INPUT);
pinMode(RightSensor, INPUT);
Serial.begin(9600); // Serial communication is opened and speed is 9600 bits per second.
}
void loop() { // This section will make infinite loop
//// Main Sensor Debug Code Routine ////
Serial.print(“Line Sensors: “); // ML1 Line Sensors Read as Analog (Values will change between 0 to 1023)
Serial.print(analogRead(LeftLine));
Serial.print(” “);
Serial.print(analogRead(RightLine));
Serial.print(” “);
Serial.print(“Opponent Sensors: “); // Opponent JS40F Sensors Read as Digital (Values will be 0 or 1)
Serial.print(digitalRead(LeftSensor));
Serial.print(” “);
Serial.print(digitalRead(LeftDiagonalSensor));
Serial.print(” “);
Serial.print(digitalRead(FrontSensor));
Serial.print(” “);
Serial.print(digitalRead(RightDiagonalSensor));
Serial.print(” “);
Serial.println(digitalRead(RightSensor)); // Send last Right Sensor Value and return to new line.
delay(300); // 300mS Delay slowing down for better reading at serial monitor
}

To upload the code, select the leonardo board (the processor on the XMotion is Atmega32u4, the same series as the Arduino Leonardo) in the Arduino IDE and also select the relevant port.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>