HI guys
i am begginer in writting code and arduino
i try to write this code
it's a code for (detection system motorcycle timming ) using ldr sensor to detect the motocycle when it cross the line so The four parts of the code are as follows
1/ make sure the sensor is alligned or not if its alligned( loop for ) counting 3 second just to be sure that the sensor is alligned
2/if the sensor is alligned the system ask me to write the number of bike
3/ if i write the number i go to waitting part // this is mean everything is ok the sensor is alligned and the number of bike is save so All that remains is the bike cross the line
4/ when the bike cross the line the part 4 excuted by what ever i want .. display timming on lcd on monitor printing ....
I JUST NEED HELP AND ADVICE HOW CAN I WRITE THIS CODE CORRECTLY I AM BEGGINER IN ARDUINO AND CODE .. TAKE A LOOK IN THE CODE .
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include "LiquidCrystal.h"
const int RS = 34, EN = 36, D4 = 38, D5 = 40, D6 = 42, D7 = 44;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
int x = 0 ;
String inputString;
String num;
int i ;
int sensorPin = A1 ;
int sensorValue = 0 ;
boolean alligned ;
boolean numb =false ;
const byte ROWS = 5; //five rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'q', '0', 't', 'i'},
{'7', '8', '9', 'a'},
{'4', '5', '6', 'z'},
{'1', '2', '3', 'e'},
{'y', 's', '#', '*'},
};
byte rowPins[ROWS] = {9, 10, 11, 12, 13}; //connect to the row pinouts of the keypad {11,10,9,8,7,6} // {10,9,8,7,6};
byte colPins[COLS] = {5, 6, 7, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600) ;
lcd.begin(16, 2);
Serial.println("WELCOME!");
delay(500);
Serial.println("POINT THE LAZER");
delay(500);
}
void loop() {
sensorValue = analogRead(sensorPin);
if (sensorValue <500 && numb == false) {
Serial.println("SYSTEM ALLIGNED");
Serial.println("Wait:");
sensorValue = analogRead(sensorPin);
for (int i = 1 ; i> 0 ; i --){
x = i ;
Serial.println (x);
delay(500);
sensorValue = analogRead(sensorPin);
delay(250);
sensorValue = analogRead(sensorPin);
alligned = true;
}
} else {
Serial.println("SYSTEM NOT ALLIGNED POINT THE LAZE PLEAZE!");
delay(700);
}
sensorValue = analogRead(sensorPin);
while(alligned){
Serial.println("enter the number of bike");
char key = keypad.getKey();
if (key != NO_KEY){
inputString += key;
Serial.println(key);
if (key == '#') {
num = inputString.toInt();
numb = true;
break;
}
}
while (numb){
sensorValue = analogRead(sensorPin);
Serial.println("WAITING FORT tHE BIKE!");
while(sensorValue >500){
numb = false ;
Serial.println("part4 display timming on lcd ");
break;
}
}
}
}