arduino mega 2560 with sweep scanse

i tried running my code but it either cant shows the reading of my sweep scanse or it shows the reading of the sweep scanse but i am unable to control it using my bluetooth module HC06. i’m trying to programme the irobot create to do the what the bluetooth commends and also able to make it run autonomous while avoiding obstacle using the sweep scanse

the attachment below is my code

#define rxPin 10
#define txPin 11
#include "roombaDefines.h"
#include <Sweep.h>

unsigned long previousMillisBT1=0;
unsigned long previousMillisSweep=0;
const unsigned long intervalBT1 = 500;
const unsigned long intervalSweep = 1000;

SoftwareSerial softSerial = SoftwareSerial(rxPin,txPin);

SoftwareSerial BT1(12, 13);

Sweep device(Serial1);
uint8_t scanCount = 0;
uint16_t sampleCount = 0;
bool syncValues[500];   
uint16_t distances[500];
uint16_t angle[500];

void setup() {

 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);

 BT1.println("Hello from Arduino");




Serial.println("Display numbers:");


char c;

void loop() {
  unsigned long currentMillis = millis();
  if ((unsigned long)(currentMillis - previousMillisBT1) >= intervalBT1) {  
  if(BT1.available() > 0){
    c =;
  previousMillisBT1 = currentMillis;

  if ((unsigned long)(currentMillis - previousMillisSweep) >= intervalSweep) {
     previousMillisSweep = currentMillis;


i even tried using millis() to divide the loop into 2 activities running together

void gatherSensorReading()
  // attempt to get the next scan packet
  // Note: getReading() will write values into the "reading" variable
  bool success = false;
  ScanPacket reading = device.getReading(success);
  if (success)

    // store the info for this sample
    syncValues[sampleCount] = reading.isSync();
    distances[sampleCount] = reading.getDistanceCentimeters();
    angle[sampleCount] = reading.getAngleDegrees();

    // increment sample count

void printCollectedData()

  int indexOfFirstSyncReading = 0;
  // don't print the trailing readings from the first partial scan
  while (!syncValues[indexOfFirstSyncReading])
  // print the readings for all the complete scans
  for (int i = indexOfFirstSyncReading; i < sampleCount; i++)
    Serial.println(String(distances[i]) + "," + String(angle[i], 3));

this is the code for the sweep

void movement(char c)
    state = c;
    BT1.println(" Moving forward ");

    BT1.println(" Turning right ");

    BT1.println(" Turning left ");

    state = c;
    BT1.println(" Moving backward ");

    BT1.println(" Stop ");

    while(distances[sampleCount]<100 && angle[sampleCount]> 45 && angle[sampleCount]< 135){
    state = c;  


this is the code for the movement

SoftwareSerial softSerial = SoftwareSerial(rxPin,txPin);

SoftwareSerial BT1(12, 13);

You have a Mega which has 4 hardware serial interfaces. Using SoftwareSerial on a Mega is not very clever and it's quite (sorry to say) stupid to use two instances of this horrible library.


Using SoftwareSerial above 19600 baud very seldom results in success, only if the counterpart is extremely timing tolerant. And if you get a communication all other task on the Arduino will be blocked because the library is blocking the hardware during very long time periods.

You forgot the links to your hardware and you forgot the wiring diagram of your setup!

haha i'm sorry i did such stupid mistakes. It's because this is my first time using arduino. i dont know what you mean by the links to my hardware, but i guess you meant the component that i used for this project that i'm doing?

i uses HC06 which is the bluetooth module

a arduino mega 2560

a sweep scanse

a irobot create

sorry but i cant get you a wiring diagram of my project right now

sorry but i cant get you a wiring diagram of my project right now

Then sorry but the help you can expect to receive will be very limited.

Without knowing what hardware you have and how it is wired up it is impossible to tell if the code is correct.

this is my wiring diagram i dont know if you can see it properly or not

This is not exactly a schematic, more of a physical layout diagram.

I can not reconcile the Roomba connections with the iRobot create.
The Roomba needs a USB connector or a 25 Way DIN connector. Nether of which match your diagram. In your diagram you seem to have connected some SPI signals to the Roomba and you seem to be wanting it to run off 5V from the Arduino.

The unidentified blue thing at the bottom right seems to want 3V3 signals to it and yet you are connection 5V signals to it.

the blue thing at the bottom is the HC06 bluetooth and i’ve checked the bluetooth part of the system works just fine with it running at 5V

The bluetooth device still connects to the SoftwareSerial pins. Fix that.

The post your complete code, define what you expect from it and what you get. Otherwise we don't know how to help you.