Hello there!
I’m a Absolute beginner and new to Arduino,
I was making " A Robot which detects Light (with two LDR - Left & Right - which compare values to change robot direction) and Avoid Obstacle ( IR recover and IR transmitter - which avoid obstacle by changing robot direction) and a Servo motor ( attacks on obstacles come in its path).
And LDR & IR values → are showed in → Serial Monitor.
And I successfully made it ,but… :o
I need a help, I want to add a 16x2 LCD on my Robot, so that I can see LDR and IR values directly on 16x2 LCD, instead of seeing them in Serial Monitor…
Its Working : LDR & IR values -->> showing on -->> serial Monitor.
I want to : LDR & IR values -->> to show on -->> 16x2 LCD…
The Sketch is below : (as I’m beginner , I don’t know much about it and trying to learn, { I need sketch for adding LCD which show values}).
#include <Servo.h>
Servo myservo;
#define IRsensorPin 11
#define IRledPin 10
const int RightSensor = 2;
const int LeftSensor = 0;
int IR;
int SensorLeft;
int SensorRight;
int SensorDifference;
void IR38Write() {
for(int i = 0; i <= 384; i++) {
digitalWrite(IRledPin, HIGH);
delayMicroseconds(13);
digitalWrite(IRledPin, LOW);
delayMicroseconds(13);
}
}
void setup() {
myservo.attach(5);
pinMode(IRledPin, OUTPUT);
digitalWrite(IRledPin, LOW);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(LeftSensor, INPUT);
pinMode(RightSensor, INPUT);
Serial.begin(9600);
Serial.println(" \nBeginning Light Seeking Behavior");
}
void loop() {
IR38Write();
IR = digitalRead(IRsensorPin);
delay(50);
SensorLeft = 1023 - analogRead(LeftSensor);
delay(1);
SensorRight = 1023 - analogRead(RightSensor);
delay(1);
SensorDifference = abs(SensorLeft - SensorRight);
Serial.print("Left Sensor = ");
Serial.print(SensorLeft);
Serial.print("\t");
Serial.print("Right Sensor = ");
Serial.print(SensorRight);
Serial.print("\t");
if (SensorLeft > SensorRight && SensorDifference > 75 && IR == HIGH) {
Serial.println("Left");
digitalWrite(8, HIGH);
delay(250);
digitalWrite(8, LOW);
delay(100);
}
if (IR == LOW){
delay(500);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
myservo.write(30);
delay(200);
myservo.write(130);
delay(200);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(250);
}
if (SensorLeft < SensorRight && SensorDifference > 75 && IR == HIGH) {
digitalWrite(9, HIGH);
delay(250);
digitalWrite(9, LOW);
delay(100);
}
else if (SensorDifference < 75 && IR == HIGH) {
Serial.println("Forward");
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(250);
}
Serial.print("\n");
}
Below are the connections of Motors & LDR & IR sensor & Servo Motor: (how can I add LCD?)
https://cdn.instructables.com/F1R/M3WI/ … MEDIUM.jpg
https://cdn.instructables.com/FBY/X3OS/ … MEDIUM.jpg
https://cdn.instructables.com/FQD/3KPC/ … MEDIUM.jpg
https://cdn.instructables.com/FY4/8IVX/ … MEDIUM.jpg
Thanks. Any help will help me a lot!