LSA08 digital output sensor reading

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

LSA08 digital output sensor reading

Postby Choon » Thu Nov 01, 2018 5:55 pm

i want to make my own logarithm but what parameters should i define to get the value for each of the sensor as 1 and 0? The code that i use fail to make the sensor to read the line. Pls tell me what i did wrong in this code. :cry: :cry:

Code: Select all
float Kp=0,Ki=0,Kd=0;
float error=0, P=0, I=0, D=0, PID_value=0;
float previous_error=0, previous_I=0;
int sensor[5]={0, 0, 0, 0, 0};
int initial_motor_speed=50;

void read_sensor_values(void);
void calculate_pid(void);
void motor_control(void); 
void setup()
{
 pinMode(11,OUTPUT); //PWM Pin 1
 pinMode(10,OUTPUT); //PWM Pin 2
 pinMode(13,OUTPUT); //Left Motor Pin 1
 pinMode(8,OUTPUT); //Left Motor Pin 2
 pinMode(12,OUTPUT); //Right Motor Pin 1
 pinMode(9,OUTPUT);  //Right Motor Pin 2
 Serial.begin(9600)  ; //Enable Serial Communications
}

void loop()
{
    read_sensor_values();
    calculate_pid();
    motor_control();
}

void read_sensor_values()
{
  sensor[0]=digitalRead(0);
  sensor[1]=digitalRead(1);
  sensor[2]=digitalRead(2);
  sensor[3]=digitalRead(3);
  sensor[4]=digitalRead(4);
  sensor[5]=digitalRead(5);
  sensor[6]=digitalRead(6);
  sensor[7]=digitalRead(7);
Choon
Greenhorn
 
Posts: 3
Joined: Thu Nov 01, 2018 5:37 pm

Re: LSA08 digital output sensor reading

Postby ober » Thu Nov 08, 2018 11:33 am

Sorry, cannot check your code because I am not compiler.

My suggestion is do not put PID algorithm to your program first, just do simple detection first.

With your question, there are limited information. Is the hardware connection correct? Have you choose the correct mode on LSA05? Is it being calibrate properly?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1378
Joined: Wed Apr 15, 2009 1:03 pm


Return to Sensor

Who is online

Users browsing this forum: No registered users and 3 guests