Why slave program is not working even if there is no problem while uploading? Please point out the possible errors.
master.txt (3.65 KB)
slave.txt (1.86 KB)
Why slave program is not working even if there is no problem while uploading? Please point out the possible errors.
master.txt (3.65 KB)
slave.txt (1.86 KB)
Please use the AutoFormat tool to indent your code and make it easier to read.
Please post your programs using the code button </> so it looks like this
so that we don't have to download them
Please tell us in detail what is happening. The words "is not working" do not convey any useful info.
There is nothing unusual about programs compiling and uploading and not working properly.
...R
Master
#define IRsensorPin1 11 // right
#define IRsensorPin2 12 // left
#define IRsensorPin3 10 // centre
#define RightIRledPin 4
#define LeftIRledPin 6
#define CentreIRledPin 7
const int RightSensor = 2;
const int LeftSensor = 0;
const int RightMotor = 8; // This pin is used to enable or disable the Right motor. Connected to the base of an NPN transistor.
const int LeftMotor = 9;
int IR1;
int IR2;
int IR3;
int SensorLeft;
int SensorRight;
int SensorDifference;
void IR38Write(byte IRledPin) {
for(int i = 0; i <= 384; i++) {
digitalWrite(IRledPin, HIGH);
delayMicroseconds(13);
digitalWrite(IRledPin, LOW);
delayMicroseconds(13);
}
}
void setup() {
pinMode(RightIRledPin, OUTPUT);
digitalWrite(RightIRledPin, LOW);
pinMode(LeftIRledPin, OUTPUT);
digitalWrite(LeftIRledPin, LOW);
pinMode(CentreIRledPin, OUTPUT);
digitalWrite(CentreIRledPin, LOW);
pinMode(LeftMotor, OUTPUT);
pinMode(RightMotor, OUTPUT);
pinMode(LeftSensor, INPUT);
pinMode(RightSensor, INPUT);
Serial.begin(9600);
Serial.println(" \nBeginning Light Seeking Behavior");
}
void loop(){
SensorLeft = 1023 - analogRead(LeftSensor);
delay(1);
SensorRight = 1023 - analogRead(RightSensor);
delay(1);
SensorDifference = abs(SensorLeft - SensorRight);
IR1 = digitalRead(IRsensorPin1);
IR2 = digitalRead(IRsensorPin2);
IR3 = digitalRead(IRsensorPin3);
delay(50);
Serial.print("Left Sensor = ");
Serial.print(SensorLeft);
Serial.print("\t");
Serial.print("Right Sensor = ");
Serial.print(SensorRight);
Serial.print("\t");
if (SensorLeft > SensorRight && SensorDifference > 5 && IR1== HIGH && IR2== HIGH && IR3== HIGH) {
Serial.println("Left");
digitalWrite(RightMotor, HIGH);
delay(2000);
digitalWrite(LeftMotor, LOW);
delay(150);
Serial.write ('1');
}
IR38Write(LeftIRledPin);
if (IR2 == LOW){
Serial.println("Left Obstacle");
digitalWrite(RightMotor, HIGH);
delay(2000);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('2');
}
if (SensorLeft < SensorRight && SensorDifference > 5 && IR1==HIGH && IR2== HIGH && IR3== HIGH) {
Serial.println("Right");
digitalWrite(LeftMotor, HIGH);
delay(2000);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('3');
}
IR38Write(RightIRledPin);
if (IR1 == LOW){
Serial.println("Right Obstacle");
digitalWrite(LeftMotor, HIGH);
delay(2000);
digitalWrite(LeftMotor, LOW);
digitalWrite(LeftMotor, LOW);
delay(150);
Serial.write ('4');
}
else if (SensorDifference < 5 && IR1== HIGH && IR2== HIGH && IR3== HIGH) {
Serial.println("Forward");
digitalWrite(RightMotor, HIGH);
digitalWrite(LeftMotor, HIGH);
delay(2000);
digitalWrite(LeftMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('5');
}
IR38Write(CentreIRledPin);
if (IR3 == LOW){
Serial.println("Centre Obstacle");
digitalWrite(RightMotor, HIGH);
delay(2000);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('6');
}
IR38Write(RightIRledPin && CentreIRledPin);
if (IR1 == LOW && IR3== LOW){
Serial.println("Left and centre obstacle");
digitalWrite(LeftMotor, HIGH);
delay(2000);
digitalWrite(LeftMotor, LOW);
digitalWrite(LeftMotor, LOW);
delay(150);
Serial.write ('7');
}
IR38Write(LeftIRledPin && CentreIRledPin);
if (IR2 == LOW && IR3== LOW){
Serial.println("Right and centre obstacle");
digitalWrite(RightMotor, HIGH);
delay(2000);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('8');
}
if (SensorLeft < 500 && SensorRight <500) {
Serial.println("SURVIVOR DETECTED");
digitalWrite(LeftMotor, LOW);
delay(2000);
digitalWrite(RightMotor, LOW);
delay(150);
Serial.write ('9');
}
Serial.print("\n");
}
Slave
const int rightMotor = 8; // This pin is used to enable or disable the Right motor. Connected to the base of an NPN transistor.
const int LeftMotor = 10;
void setup() {
pinMode(LeftMotor, OUTPUT);
pinMode(RightMotor, OUTPUT);
Serial.begin(9600);
Serial.println(" \nBeginning Light Seeking Behavior");
}
void loop() {
char a;
if(Serial.available( ) )
{
a=Serial.read();
if(a=='1'){
Serial.println("Left");
digitalWrite(RightMotor, HIGH);
delay(100);
digitalWrite(LeftMotor, LOW);
delay(100);
}
if(a=='2'){
Serial.println("Left obstacle");
digitalWrite(RightMotor, HIGH);
delay(2000);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(100);
}
if(a=='3') {
Serial.println("Right");
digitalWrite(LeftMotor, HIGH);
delay(1500);
digitalWrite(RightMotor, LOW);
delay(100);
}
if(a=='4') {
Serial.println("Right Obstacle");
digitalWrite(LeftMotor, HIGH);
delay(1500);
digitalWrite(LeftMotor, LOW);
digitalWrite(LeftMotor, LOW);
delay(150);
}
if(a=='5'){
Serial.println("Forward");
digitalWrite(RightMotor, HIGH);
digitalWrite(LeftMotor, HIGH);
delay(1500);
digitalWrite(LeftMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(250);
}
if(a=='6'){
Serial.println("Centre Obstacle");
digitalWrite(RightMotor, HIGH);
delay(1500);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(150);
}
if(a=='7'){
Serial.println("Left and centre obstacle");
digitalWrite(LeftMotor, HIGH);
delay(1500);
digitalWrite(LeftMotor, LOW);
digitalWrite(LeftMotor, LOW);
delay(1500);
}
if(a=='8'){
Serial.println("Right and centre obstacle");
digitalWrite(RightMotor, HIGH);
delay(1500);
digitalWrite(RightMotor, LOW);
digitalWrite(RightMotor, LOW);
delay(1500);
}
if(a=='9') {
digitalWrite(LeftMotor, LOW);
delay(1500);
digitalWrite(RightMotor, LOW);
delay(100);
}
}
}
Just post the damned code - don't make people download it.
Hi Techtonic, my first thought is that you need to use a nylon weave rather than hemp or jute. It's much more comfortable, but then I realized you meant computer programs.
The denizens here are not automatons, they are people who like the atmosphere and crowd here. Add to it by engaging folks, rather than just putting your project out to speak for itself. It won't. Especially if you don't use the built-into the IDE formatting tool and forum's code display tags! Tsk.
So if you want to stay and get help and opinions here (unlike 80ish percent of other first time posters) come back and tell us about those 'master' and 'slave' Arduino devices you have. What do they do? How don't they work?
Sorry for the inconvenience.
Master is a light seeking bot, which uses ldr(2 no.) and it also avoids obstacle in its path using IR sensors(3 no.)...
Slave just mimics the actions of the master and we have given just motor connections in slave as output.
Problem is even after receiving the transmitted signal from master. Slave is not perfectly mimicking the master.
Board- arduino uno
Communication - via cc2500.
Hi Techtonic, I try not to learn anything about "IR sensor", "obstacle avoiding". "swarm" bots. Arduino, PIC and Lego robot kits and students who use them for projects are part of my job, and I don't want to be a target of all those questions. "I don't know anything about that." is my perfect answer.
This post is lousy with search terms though.
Techtonic:
Problem is even after receiving the transmitted signal from master. Slave is not perfectly mimicking the master.
Board- arduino uno
You are still being remarkably coy about providing useful information. Is someone charging you for every keypress?
Do you mean that the slave is receiving the data correctly? So we can rule out problems in that area.
And "is not perfectly mimicking the master" suggests that it is doing a lot of stuff correctly - but you have not told us what it is doing right and what it is doing wrong.
If you want help you need to help us to help you.
...R
The slave is working randomly.. Not at all in tandem with master. The receiver led on the slave is glowing, though..
In the beginning of the master loop, you send a string.
SensorLeft = 1023 - analogRead(LeftSensor);
...
...
Serial.print(SensorLeft);
If the left sensor reading is e.g. 900, the value that you send is 1023 - 900 = 123. This is send as array of characters ('1' followed by '2' followed by '3').
Your slave is checking the received characters and will react on them. You expect the slave to only react on what was send using the Serial.write statements.
Note:
No Arduino at hand to verify, but I think that this is the cause of your problem.
Techtonic:
The slave is working randomly.. Not at all in tandem with master. The receiver led on the slave is glowing, though..
A glowing LED does not tell you much.
Don't you have some debugging code in your slave so that you can verify that the different parts of the program work properly?
If not, now is the time to add it.
...R