Go Down

Topic: room scaning project need a bit of help to get it to work (Read 763 times) previous topic - next topic


Feb 04, 2011, 02:54 am Last Edit: Feb 05, 2011, 10:10 am by magicman5511 Reason: 1
my project consists of two servos ,a distance sensor and a prossessing code the servos are ment to goto mouseX and mouseY which they do then the distance sensor is ment to send the distance to the prossessing and it creates a box at mouseX and mouseY and it  coulor depends on how
far the distance is but it is geting weird distances which repeat so i am unsure of the problem

Code: [Select]

import processing.serial.*;
int Y;
int X;
Serial myPort;  // Create object from Serial class
int D;
int C;
void setup()
 size(660, 660);
 String portName = Serial.list()[8];
 myPort = new Serial(this, portName, 9600);
 background(255);    // Setting the background to white          // Setting the outline (stroke) to black    

void draw() {
 if ( myPort.available() > 0) {  // If data is available,
   D = myPort.read();         // read it and store it in val
C = D*2;



Code: [Select]

#include <Servo.h>
int pingPin = 7;
Servo x;
Servo y;
int X = 0;
int Y = 0;
int a = 0;
void setup()
void loop()  
 if ( Serial.available() > 0 )
a = Serial.read();
if (a<=90){
if (a>=91 & a<182){

 // establish variables for duration of the ping,
 // and the distance result in inches and centimeters:
 long duration, inches, cm;

 // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
 // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
 pinMode(pingPin, OUTPUT);
 digitalWrite(pingPin, LOW);
 digitalWrite(pingPin, HIGH);
 digitalWrite(pingPin, LOW);

 // The same pin is used to read the signal from the PING))): a HIGH
 // pulse whose duration is the time (in microseconds) from the sending
 // of the ping to the reception of its echo off of an object.
 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin, HIGH);

 // convert the time into a distance
 inches = microsecondsToInches(duration);
 cm = microsecondsToCentimeters(duration);



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;


You need to break the problem down. First off just send the data to the monitor window and see if the data you ate recording looks ok. Only then proceed to do something with it. Without the hardware schematic and more information about what you are getting it is hard to tell what is wrong.


the ardiuno side of the project works fine because the serial monitor gives the correct reading then i open the prossing code it is wrong it is saying that the value that i sent from the ardiuno is 50 55 10 13 not in that order  but it was 228 then when i make it smaller it remain the same could it just be that it is reading the data in the wrong format or is it just the script     the problem is that yesterday it was more stable eg 228 read 56 and  190 read 56 but 170 read 55 and soon at no particular interval

Go Up