0

I am trying to make a human detection robot using D6T omron thermal sensor. However, I am facing some problem here. My Arduino Uno didn't run the sketches until I open up my GUI in processing. The tx/rx pin did not light up when I remove my USB serial cable from my PC and put in an external power supply to my arduino uno board. The tx/rx pin will only light up when I open my GUI in processing and everything works just fine.

I am trying to move my robot away from my PC. Therefore, it is a must for me to provide my board an external power supply but it just does not work. I am confused here. Fyi, it will be interfacing with my PC thru Xbee in the near future.

Ps: this is my final year project. Your effort will be much appreciated and credits will goes to you. Thanks guys!

Attached below is my code (Arduino sketch):

#define E_right 10
#define E_left 11
int RightMotorForward = 9; // Pin 10 has Left Motor connected on Arduino boards.
int RightMotorReverse = 8; // Pin 9 has Left Motor connected on Arduino boards.
int LeftMotorForward = 12; // Pin 12 has Right Motor connected on Arduino boards.
int LeftMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino boards.
float top_sum, bottom_sum, left_sum, right_sum, center_row_sum;
#include <Wire.h>
#include <WireExt.h>
#define D6T_addr 0x0A
#define D6T_cmd 0x4C
int rbuf[35];
float tdata[16];
float t_PTAT;
void setup()
{
 Wire.begin();
 Serial.begin(9600);
 Serial.flush();
 pinMode(E_right, OUTPUT);
 pinMode(E_left, OUTPUT);
 pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
 pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
 pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
 pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
}
//----------------------------------------------------------------------------- 
// The following Loop is to make the Robot move towards heat source.
void loop()
{
int i;
 if (Serial.available() > 0) { 
 int inByte = Serial.read(); 
 if (inByte == 0x0001) { 
 Wire.beginTransmission(D6T_addr);
 Wire.write(D6T_cmd);
 Wire.endTransmission();
 if (WireExt.beginReception(D6T_addr) >= 0) {
 i = 0;
 for (i = 0; i < 35; i++) {
 rbuf[i] = WireExt.get_byte();
 }
 WireExt.endReception();
 t_PTAT = (rbuf[0]+(rbuf[1]<<8))*0.1;
 for (i = 0; i < 16; i++) {
 tdata[i]=(rbuf[(i*2+2)]+(rbuf[(i*2+3)]<<8))*0.1;
 }
 }
 }
 }
top_sum= tdata[0] + tdata[1] + tdata[2] + tdata[3];
bottom_sum= tdata[12] + tdata[13] + tdata[14] + tdata[15];
right_sum= tdata[0]+ tdata[4] + tdata[8] + tdata[12];
left_sum= tdata[3] + tdata[7] + tdata[11] + tdata[15];
center_row_sum= tdata[1] + tdata[2] + tdata[5] + tdata[6] + tdata[9] + tdata[10] + tdata[13] + tdata[14];
if ((left_sum>center_sum)&& (center_sum>right_sum))
{
 analogWrite(E_right, 230); 
 analogWrite(E_left, 205); 
 digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
 digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
 // wait for 0.5 seconds
 delay(500);
 //turn left
}
else if ((right_sum>center_sum)&&(center_sum>left_sum))
{
 analogWrite(E_right, 230); 
 analogWrite(E_left, 205); 
 digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
 digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
 // wait for 0.5 seconds
 delay(500);
 //turn right
}
else if ((center_row_sum>right_sum)&&(center_row_sum>left_sum))
{
 analogWrite(E_right, 230); 
 analogWrite(E_left, 205); 
 digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
 digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
 delay(500); //forward
}
}

Attached below is my code in processing:

import processing.serial.*;
float[] tdata = new float[17]; 
float tptat; // PTAT
String portName; 
//int serialport = 0; 
String buf; 
float colourGreen; //change green in relation to temperature 
int lbTemp = 25; //lowest relative temperature
int hbTemp = 35; //highest relative temperature 
Serial myPort; // Create object from Serial class
void setup() {
 size(640,640);
 //println(Serial.list());
 //portName = Serial.list()[serialport];
 myPort = new Serial(this, "COM7", 9600);
 myPort.clear();
}
void draw() {
 myPort.write(0x01); 
 delay(100); 
 while (myPort.available() > 0) { 
 delay(300); 
 buf = myPort.readString(); 
 myPort.clear(); 
 tdata = float(split(buf, ',')); 
 for (int i = 0; i <16; i++) { 
 colourGreen = map(tdata[i],lbTemp,hbTemp,255,0);
fill (255,colourGreen,0);
 if (i == 0)
 { rect(480,0,160,160);}
 else if (i == 1)
 { rect(320,0,160,160);}
 else if (i == 2)
 { rect(160,0,160,160);}
 else if (i == 3)
 { rect(0,0,160,160);}
 else if (i == 4)
 { rect(480,160,160,160);}
 else if (i == 5)
 { rect(320,160,160,160);}
 else if (i == 6)
 { rect(160,160,160,160);}
 else if (i == 7)
 { rect(0,160,160,160);}
 else if (i == 8)
 { rect(480,320,160,160);}
 else if (i == 9)
 { rect(320,320,160,160);}
 else if (i == 10)
 { rect(160,320,160,160);}
 else if (i == 11)
 { rect(0,320,160,160);}
 else if (i == 12)
 { rect(480,480,160,160);}
 else if (i == 13)
 { rect(320,480,160,160);}
 else if (i == 14)
 { rect(160,480,160,160);}
 else
 { rect(0,480,160,160); }
 if (tdata[i]<5) {fill(255);} else {fill(0);}
 if (i ==0)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]),560, 80);}
 else if (i == 1)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]),400, 80);
 }
 else if (i == 2)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 240, 80);
 }
 else if (i == 3)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]),80, 80); 
 }
 else if (i == 4)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 560, 240); 
 }
 else if (i == 5)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 400, 240); 
 }
 else if (i == 6)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 240, 240); 
 }
 else if (i == 7)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 80, 240); 
 }
 else if (i == 8)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 560, 400);
 }
 else if (i == 9)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 400, 400); 
 }
 else if (i == 10)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 240, 400);
 }
 else if (i == 11)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 80, 400);
 }
 else if (i == 12)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 560, 560); 
 }
 else if (i == 13)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 400, 560); 
 }
 else if (i == 14)
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 240, 560);
 }
 else
 {
 textAlign(CENTER, CENTER);
 textSize(20);
 text(str(tdata[i]), 80, 560); 
 }
 }
 delay(800);
 }
}
rebatoma
5593 gold badges12 silver badges22 bronze badges
asked Mar 21, 2016 at 15:59

1 Answer 1

1

My Arduino Uno didn't run the sketches until I open up my GUI in processing.

How do you know?

The tx/rx pin did not light up when I remove my USB serial cable from my PC and put in an external power supply to my arduino uno board.

That is because the TX/RX LEDs are linked to the USB interface chip. With no USB connection there can be no lights.

The tx/rx pin will only light up when I open my GUI in processing and everything works just fine.

That is because there is USB communication.

Your sketch is running fine. However your sketch looks to be wrong. Major portions of it (i.e., the portion that does any detection at all) relies on serial data coming in. How can you have it working, in that case, if you disconnect the serial interface so that no data ever comes in?

answered Mar 21, 2016 at 16:11
4
  • OHHHH! I see. Thank you so much for pointing out the mistakes. Do you hv any suggestion on how to improve my sketch? Sorry because I am new to these. Thanks a lot Majenko! Commented Mar 21, 2016 at 16:25
  • You don't appear to actually be doing anything with serial in your sketch. Just delete all references to it. Commented Mar 21, 2016 at 16:26
  • Okayyy! I will try it out and update you later. Thanks again Majenko! =D Commented Mar 21, 2016 at 16:31
  • It works! Thanks for pointing out my silly mistakes! Credits goes to you, Majenko~ Thanks!! Commented Mar 21, 2016 at 16:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.