# Automated car LCD issues

I cannot figure out how to implement this LCD sketch into the main loop without messing up the cars functions. It displays the voltage on the LCD, but the car wont function. The car functions fine without the LCD in the loop. This is a project I am working on for school, any help would be appreciated.

//DO NOT CHANGE
// Pin Declarations
int LeftMotorDir = 12, LeftMotorPower = 3;
int RightMotorDir = 13, RightMotorPower = 11;

//DO NOT CHANGE
int left_light = A0, right_light = A1;

//CHANGE LIGHT SENSOR CALIBRATION VALUES
// Light Sensor Calibration Values
// These you need to set manually (use the LCD to read the values). Make sure to give yourself a buffer
// If line reads 999, may use something like ~925 for your dark value (so you don’t miss it).
int dark = 820;

//CHANGE MOTOR SPEEDS
// Motor maximum and minimum speeds
// Adjust these within the 0-255 range to try and make your bot faster
//CHANGE MOTOR MIN AND MAX SPEEDS
int motor_max = 200, motor_min = 75;

//DO NOT CHANGE
// Milliseconds per cycle → 10ms would yield loop speed of 100Hz
int ms_per_cycle = 10;
// This is updated each time the motors are updated to make sure everything runs exactly at desired loop speed
unsigned long previous_time = 0;

/*
The motor speeds are often not matched meaning that the car won’t travel straight.
You will need to adjust so the faster motor goes the same speed as the slower motor.
The range of speed is from 0 to 255. 255 is the maximum speed.
Change the values of leftMotor and rightMotor until the car will travel straight.
To find the values that make the car go straight, determine the radial velocity of each wheel and adjust
proportionally. That or it can be accomplished by trial and error.
Try lowering the duty cycle of the faster motor, little by little.
Be patient!
*/

// Tells arduino to include the lcd library
#include <LiquidCrystal.h>
int vdcPin = 5;

LiquidCrystal lcd(12,11,5,4,3,2);
// Change these values to CALIBRATE MOTORS SEPARATELY
int leftMotor = 255, rightMotor = 255;

void setup() {
pinMode(LeftMotorDir, OUTPUT);
pinMode(RightMotorDir, OUTPUT);
pinMode(LeftMotorPower, OUTPUT);
pinMode(RightMotorPower, OUTPUT);
// starts serial communication
Serial.begin(9600);
// sets up the LCD’s number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
}

void loop() {

if (millis() - previous_time >= ms_per_cycle) // if time since last motor update is >= desired delta t then update motors
{
previous_time = millis(); // Update the cycle timer

if (right_reading >= dark && left_reading < dark) // See the line on the right side of the robot.
{ // Need to turn the robot right to keep the line over the robot.
digitalWrite(LeftMotorDir, HIGH); // Left motor forward
analogWrite(LeftMotorPower, motor_min); // Max power for left motor
digitalWrite(RightMotorDir, HIGH); // Right motor forward
analogWrite(RightMotorPower, motor_max); // Minimum power for right motor
}
else if (right_reading < dark && left_reading >= dark) // See line on the left side of the robot
{
digitalWrite(LeftMotorDir, HIGH); // Left motor forward
analogWrite(LeftMotorPower, motor_max); // Min power for left motor
digitalWrite(RightMotorDir, HIGH); // Right motor forward
analogWrite(RightMotorPower, motor_min); // Max power for right motor
}
else if (right_reading < dark && left_reading < dark) // Neither sensor sees line, must be straddled… Go straight
{
digitalWrite(LeftMotorDir, HIGH); // Left motor forward
analogWrite(LeftMotorPower, motor_max); // Max power for left motor
digitalWrite(RightMotorDir, HIGH); // Right motor forward
analogWrite(RightMotorPower, motor_max); // Max power for right motor
}
else
{
// Both sensors must see black or there is a problem. Turning motors off
digitalWrite(LeftMotorDir, HIGH); // Left motor forward
analogWrite(LeftMotorPower, 150); // Turning motor off
digitalWrite(RightMotorDir, HIGH); // Right motor forward
analogWrite(RightMotorPower, 150); // Turning motor off
}

float voltage = voltReading * (5.0 / 1024.0);
// ----------------
//This is for the LCD readout
lcd.print(" VDC ");
lcd.setCursor(4, 0);

lcd.print(voltage);
delay(100);
lcd.clear();
} // End of cycle timer if statement

// If the if statement is false (hasn’t been enough time since last motor update) then the program will simply skip the if statement
// and loop around very very quickly.

}

Hi,
Please do not CROSS_POST , it makes it confusing to forum members trying to help.