Other Parts Discussed in Thread: ENERGIA
im having some issue that this sensor is not measuring exactly the distance... the first reading is fine until a minute the reading goes up like it increment by 1.. im new here . i need some advise guys. :) i
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Other Parts Discussed in Thread: ENERGIA
im having some issue that this sensor is not measuring exactly the distance... the first reading is fine until a minute the reading goes up like it increment by 1.. im new here . i need some advise guys. :) i
const int numReadings =100;
int readings[numReadings];
int readIndex = 0;
int total = 0 ;
float average = 0;
int inputPin = P6_0;
float pw1;
void setup () {
Serial.begin(9600);
pinMode(P6_1,OUTPUT);
pinMode(P6_0,INPUT);
digitalWrite(P6_1,LOW);
for (int thisReading = 0; thisReading < numReadings ; thisReading ++)
readings[thisReading] = 0;
}
void loop ()
{pw1=pulseIn (P6_0,HIGH);
if (pw1 !=0){
pw1= (pw1/10)-5;
Serial.println(pw1);
}
delay(20);
total = total + analogRead (inputPin);
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
average = total/numReadings;
Serial.println(average);
Serial.print("average:");
delay (100);
total = 0;
}
}
i measure a distance of 43 cm but it gives me 40,41,42,43,44 even though i already average it.
ive already controlled the 3 sensors .. works perfectly fine but i need to get the average of each sensor im lost in the middle of my programming.. here take a look. i want to learn more because im new here.
const int numReadings = 5;
int readings[numReadings];
int readIndex = 0;
int total = 0;
int average = 0;
int ave1,ave2,ave3;
unsigned long lsrdistance ;
int Lsr1,Lsr2,Lsr3;
void setup ()
{
Serial.begin(9600);
pinMode(P3_6,OUTPUT);
pinMode(P6_1,INPUT);
digitalWrite(P3_6,LOW);
pinMode(P3_5,OUTPUT);
pinMode(P6_2,INPUT);
digitalWrite(P3_5,LOW);
pinMode(P7_0,OUTPUT);
pinMode(P6_3,INPUT);
digitalWrite(P7_0,LOW);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop()
{
Lidarlite (P6_1,HIGH);
Lsr1=lsrdistance;
Lidarlite (P6_2,HIGH);
Lsr2=lsrdistance;
Lidarlite (P6_3,HIGH);
Lsr3=lsrdistance;
Serial.print("Lsr1=");
Serial.println(Lsr1);
Serial.print("ave1=");
Serial.println(ave1);
Serial.print("Lsr2=");
Serial.println(Lsr2);
Serial.print("ave2=");
Serial.println(ave2);
Serial.print("Lsr3=");
Serial.println(Lsr3);
Serial.print("ave3=");
Serial.println(ave3);
}
void Lidarlite ( int Pin , int pin3)
{
lsrdistance = pulseIn (Pin,HIGH);
if(lsrdistance != 0){
lsrdistance=(lsrdistance)/10;//cm na output nya ni//
}
delay(20);
total = total - readings[readIndex];
readings[readIndex] = analogRead (Pin);
total = total + readings[readIndex];
readIndex = readIndex + 1;
if(readIndex >= numReadings){
readIndex = 0;
}
average = total / numReadings;
delay(1);
}
**Attention** This is a public forum