Page 1 of 1

LSA08 digital output sensor reading

PostPosted: Thu Nov 01, 2018 5:55 pm
by Choon
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_CODE
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);

Re: LSA08 digital output sensor reading

PostPosted: Thu Nov 08, 2018 11:33 am
by ober
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?