I have a problem senting my codes to my zumo bot. I have attached a RN42 to arduino uno board and the board is connected to a zumo shield which has two motors. When i sent the code the arduino uno is not receiving any data. is there any codes i need to add in order to receive the codes from my bluetooth module?
//online resources and library :
#include <QTRSensors.h>
#include <ZumoReflectanceSensorArray.h>
#include <ZumoMotors.h>
#define LED_PIN 13
// Change record
// Change second left turn (m= 2) to go forward before left turn.
ZumoMotors motors;
ZumoReflectanceSensorArray reflectanceSensors;
// Define an array for holding sensor values.
#define NUM_SENSORS 6
unsigned int sensorValues[NUM_SENSORS];
int proportional= 0;
int integral=0;
int last_proportional=0;
int derivative=0;
float K1, K2, K3;
float error_value;
int m = 0;
int s;
int wait = 2500; // Standard junction wait time
void setup()
{
s= 70;
reflectanceSensors.init();
digitalWrite(2, LOW);
delay(500);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // turn on LED to indicate we are in calibration mode
unsigned long startTime = millis();
while(millis() - startTime < 10000) // make the calibration take 10 seconds
{
reflectanceSensors.calibrate();
}
digitalWrite(13, LOW); // turn off LED to indicate we are through with calibration
// print the calibration minimum values measured when emitters were on
Serial.begin(9600);
for (byte i = 0; i < NUM_SENSORS; i++)
{
Serial.print(reflectanceSensors.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
// print the calibration maximum values measured when emitters were on
for (byte i = 0; i < NUM_SENSORS; i++)
{
Serial.print(reflectanceSensors.calibratedMaximumOn[i]);
Serial.print(' ');
}
Serial.println();
Serial.println();
delay(1000);
}
void sensor()
{
// read calibrated sensor values and obtain a measure of the line position.
// Note: the values returned will be incorrect if the sensors have not been properly
// calibrated during the calibration phase.
unsigned int position = reflectanceSensors.readLine(sensorValues);
// To get raw sensor values instead, call:
//reflectanceSensors.read(sensorValues);
for (byte i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensorValues[i]);
Serial.print(' ');
}
Serial.print(" ");
Serial.println(position);
delay(250);
}
//code down by Song Hui. PID CONTROL
void turn() {
unsigned int position = reflectanceSensors.readLine(sensorValues);
float K1 = 0.1;
float K2 = 0;
float K3 = 0;
proportional = position - 2450;
integral = integral + proportional;
derivative = proportional - last_proportional;
last_proportional = proportional;
error_value = proportional* K1 + integral * K2 + derivative *K3;
Serial.print(' ');
Serial.print(proportional);
Serial.print(' ');
Serial.print(integral);
Serial.print(' ');
Serial.print(derivative);
Serial.print(' ');
Serial.print(error_value);
Serial.print(' ');
if (error_value < - s) {
error_value = -s;
}
if (error_value > s) {
error_value = s;
}
if (error_value <0 ) {
motors.setRightSpeed(-s +error_value );
motors.setLeftSpeed(-s -error_value );
}
else {
motors.setRightSpeed(-s +error_value);
motors.setLeftSpeed(-s - error_value);
}
}
//what should the car do when it meets the junctions and how it gonna remember it
void loop(){
unsigned int position = reflectanceSensors.readLine(sensorValues);
// **************** Comment out the first Y junction, to place the car after it
// if (sensorValues[0] > 50 and sensorValues[5] < 50 and m==0){
// motors.setRightSpeed(0);
// motors.setLeftSpeed(0);
// delay(wait);
//
// motors.setRightSpeed(-s);
// motors.setLeftSpeed(-s);
// delay(1200);
// m=m+1;
//
// turn();
// }
// *******************************************************************
if (sensorValues[0] > 50 and sensorValues[5] < 50 and m==0){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(wait);
// ************** Insert move forward to clear the grass patch on left, with a more aggressive turn
motors.setRightSpeed(-s);
motors.setLeftSpeed(-s);
delay(700);
// ****************
motors.setRightSpeed(-180); // change from -130
motors.setLeftSpeed(80);
delay(600);
motors.setRightSpeed(-50);
motors.setLeftSpeed(-50);
delay(2000);
motors.setRightSpeed(-50);
motors.setLeftSpeed(30);
delay(450);
m=m+1;
turn();
}
if (sensorValues[0] > 50 and sensorValues[5] > 50 and m==1){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(wait);
motors.setRightSpeed(-s);
motors.setLeftSpeed(-s);
delay(1200);
m=m+1;
turn();
}
if (sensorValues[0] > 50 and sensorValues[5] > 50 and m==2){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(wait);
// *********** Change in Rev 2 to move forward x msec before turning ***************
motors.setRightSpeed(-s);
motors.setLeftSpeed(-s);
delay(1200);
// **********************************************************************************
motors.setRightSpeed(-200); // change from -130
motors.setLeftSpeed(100);
delay(1000);
motors.setRightSpeed(-50);
motors.setLeftSpeed(30);
delay(1200);
motors.setRightSpeed(-50);
motors.setLeftSpeed(-50);
delay(500);
m=m+1;
turn();
}
if (sensorValues[0] > 50 and sensorValues[5] > 50 and m==3){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(wait);
// *********** Change in Rev 2 to move forward 300msec before turning ***************
motors.setRightSpeed(-s);
motors.setLeftSpeed(-s);
delay(850);
motors.setLeftSpeed(-150); // change from -130
motors.setRightSpeed(80);
delay(2000);
// Added straight
motors.setRightSpeed(-80);
motors.setLeftSpeed(-80);
delay(1500); // change from 1500
motors.setRightSpeed(20);
motors.setLeftSpeed(-90);
delay(1200);
m=m+1;
turn();
}
if (sensorValues[0] > 50 and sensorValues[5] > 50 and m==4){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(wait);
motors.setRightSpeed(-s);
motors.setLeftSpeed(-s);
delay(1200);
m=m+1;
turn();
}
if (sensorValues[0] > 50 and sensorValues[5] > 50 and m==5){
motors.setRightSpeed(0);
motors.setLeftSpeed(0);
delay(30000);
m=0;
}
else{
turn();
}
}