Well I'm designing a maze searching robot where one robot attach with it a sensor(PING Ultrasonic Distance Sensor [#28015]) to enter a maze and solve it, it should on the same time map the maze and transmit map to the another robot that doesn't have any sensors for second robot to solve maze based on the information collected. The map is transmitted via Bluetooth (HC-05) and the structure of the maze is in 2D array, I tried to transmit the map but the only thing that I get value can anyone help me out?
//////////// Initializing Libraries ////////////
#include <Servo.h>
#include <SD.h>
#include "Maze_Map.h"
//////////// Initialising Varaibles ////////////
int servoPin = 2;
Servo servo;
const int pingPin = 3;
unsigned int duration,inches;
int leftscan,centerscan,rightscan;
boolean scan = true;
int ledPin = 53; // Status LED connected to digital pin 13
Maze<4,6> maze; // Defining the rows and columns of the maze
//////////// Main Program ////////////
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); // set the Pin to output
servo.attach(servoPin);
Serial.begin(9600);
Serial1.begin(38400); // Turn on Bluetooth Serial
Serial2.begin(38400); // Turn on OpenLogger
delay(1000); // Wait a second for OpenLog to initiate
maze.mouseRow = 4;
maze.mouseColumn = 1;
maze.mouseHeading = NORTH;
Serial.println(" Initial Maze ");
maze.solve();
maze.print();
Serial.println(" Final Maze ");
}
void loop() {
// put your main code here, to run repeatedly:
SensorScan();
maze.solve();
maze.print();
Serial1.write(maze.print());
}
//////////// Functions ////////////
// PING Sensor Function //
int Sensor()
{
pinMode(pingPin, OUTPUT); // Set pin to OUTPUT
digitalWrite(pingPin, LOW); // Ensure pin is low
delayMicroseconds(2);
digitalWrite(pingPin, HIGH); // Start ranging
delayMicroseconds(5); // with 5 microsecond burst
digitalWrite(pingPin, LOW); // End ranging
pinMode(pingPin, INPUT); // Set pin to INPUT
duration = pulseIn(pingPin, HIGH); // Read echo pulse
inches = duration / 74 / 2; // Convert to inches
delay(25); // Short delay
}
// Conversion Function //
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
// Sensor Scan + Direction Change Function //
int SensorScan()
{
// Initialising Varaibles //
int leftscan,centerscan,rightscan;
char Direction;
const int SafeDistance = 5;
// Scanning the Perimeter //
// Scan Left //
servo.write(180); // Rotating the servo to 180 degrees
delay(2000); // Adding Delay to extend the durtation for the servo motor to be at an angle of 180 degrees
leftscan = Sensor(); // Using the Sensor function to detect if there is wall or not
leftscan = inches; // Equating the distance to the leftscan variable
Serial.print("LeftScan: ");
Serial.println(leftscan);
// Scan Center //
servo.write(90); // Rotating the servo to 90 degrees
delay(2000); // Adding Delay to extend the durtation for the servo motor to be at an angle of 90 degrees
centerscan = Sensor(); // Using the Sensor function to detect if there is wall or not
centerscan = inches; // Equating the distance to the centerscan variable
Serial.print("CenterScan: ");
Serial.println(centerscan);
// Scan Right //
servo.write(0); // Rotating the servo to 0 degrees
delay(2000); // Adding Delay to extend the durtation for the servo motor to be at an angle of 0 degrees
rightscan = Sensor(); // Using the Sensor function to detect if there is wall or not
rightscan = inches; // Equating the distance to the rightscan variable
Serial.print("RightScan: ");
Serial.println(rightscan);
// Return To Center //
servo.write(90); // Rotating the servo to 90 degrees
delay(5000); // Adding Delay to extend the durtation for the servo motor to be at an angle of 90 degrees
// Direction Change //
if (centerscan > leftscan && centerscan > rightscan)
{
maze.mouseHeading = NORTH;
maze.mouseRow -= 1;
Direction = 'F';
Serial.print("Direction: ");
Serial.println(Direction);
// Adding Walls //
if (centerscan > leftscan && centerscan > rightscan)
{
maze.addWalls(WEST);
maze.addWalls(EAST);
}
}
if (leftscan > rightscan && leftscan > centerscan)
{
maze.mouseHeading = WEST;
maze.mouseColumn -= 1;
Direction = 'L';
Serial.print("Direction: ");
Serial.println(Direction);
// Adding Walls //
if (leftscan > rightscan && leftscan > centerscan)
{
maze.addWalls(NORTH);
maze.addWalls(EAST);
}
}
if (rightscan > leftscan && rightscan > centerscan)
{
maze.mouseHeading = EAST;
maze.mouseColumn += 1;
Direction = 'R';
Serial.print("Direction: ");
Serial.println(Direction);
// Adding Walls //
if (rightscan > leftscan && rightscan > centerscan)
{
maze.addWalls(NORTH);
maze.addWalls(WEST);
}
}
//// Data Transmission //
// pinMode(ledPin, OUTPUT); // Set pin to OUTPUT
// digitalWrite(ledPin, HIGH); // Turn LED on
// maze.solve();
// maze.print();
// Serial1.write(maze.print());
// delay(2000);
// digitalWrite(ledPin, LOW); // Turn LED off
}
Make certain that you understand how to transmit data from one Arduino to another and get that to work, before you add that feature to an existing program.