Receiver code void loop is not correctly looping it show's only continuous sequence of 0's in serial monitor

//Transmitter Side:
#include <Keypad.h>
const byte ROW = 4;
const byte COL = 4;
char keyscode[ROW][COL] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPin[ROW] = {A5, A4, A3, A2};
byte colPin[COL] = {A1, A0, 12, 11};
Keypad customKeypad = Keypad( makeKeymap(keyscode), rowPin, colPin, ROW, COL);
char keycount = 0;
char code[5];
void setup() 
{
  Serial.begin(9600);
  pinMode(8,OUTPUT);
  digitalWrite(8,LOW);
}
void loop()
{
  char customKey = customKeypad.getKey();
  if (customKey) {
    Serial.println(customKey);
   if (customKey == '1')
  {
    digitalWrite(8,HIGH);
    delay(10);
    digitalWrite(8,LOW);
  }
  else if (customKey == '2')
  {
    digitalWrite(8,HIGH);
    delay(20);
    digitalWrite(8,LOW);
  }
  else if (customKey == '3')
  {
    digitalWrite(8,HIGH);
    delay(30);
    digitalWrite(8,LOW);
  }
  else if (customKey == '4')
  {
    digitalWrite(8,HIGH);
    delay(40);
    digitalWrite(8,LOW);
  }
  else if (customKey == '5')
  {
    digitalWrite(8,HIGH);
    delay(50);
    digitalWrite(8,LOW);
  }
  else if (customKey == '6')
  {
    digitalWrite(8,HIGH);
    delay(60);
    digitalWrite(8,LOW);
  }
  else if (customKey == '7')
  {
    digitalWrite(8,HIGH);
    delay(70);
    digitalWrite(8,LOW);
  }
  else if (customKey == '8')
  {
    digitalWrite(8,HIGH);
    delay(80);
    digitalWrite(8,LOW);
  }
  else if (customKey == '9')
  {
    digitalWrite(8,HIGH);
    delay(90);
    digitalWrite(8,LOW);
  }
  else if (customKey == '*')
  {
    digitalWrite(8,HIGH);
    delay(100);
    digitalWrite(8,LOW);
  }
  else if (customKey == '0')
  {
    digitalWrite(8,HIGH);
    delay(110);
    digitalWrite(8,LOW);
  }
  else if (customKey == '#')
  {
    digitalWrite(8,HIGH);
    delay(120);
    digitalWrite(8,LOW);
  }
  else if (customKey == 'A')
  {
    digitalWrite(8,HIGH);
    delay(130);
    digitalWrite(8,LOW);
  }
  else if (customKey == 'B')
  {
    digitalWrite(8,HIGH);
    delay(140);
    digitalWrite(8,LOW);
  }
  else if (customKey == 'C')
  {
    digitalWrite(8,HIGH);
    delay(150);
    digitalWrite(8,LOW);
  }
  else if (customKey == 'D')
  {
    digitalWrite(8,HIGH);
    delay(160);
    digitalWrite(8,LOW);
  }
  else;
  } 
}

———

//Receiver Side:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SoftwareSerial.h>
#include <Keypad.h>
void setup()
{
 pinMode(8, INPUT);
 Serial.begin(9600);
 lcd.init();
 lcd.backlight();
 //lcd.backlight();
 lcd.setCursor(0, 0);
 lcd.print("   WELCOME TO    ");
 lcd.setCursor(0, 1);
 lcd.print(" CIRCUIT DIGEST    ");
 delay(2000);
 lcd.clear();
}
void loop()
{
 unsigned long duration = pulseIn(8, HIGH);
 Serial.println(duration);
 if (duration > 10000 && duration < 17000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 1          ");
 }
 else if (duration > 20000 && duration < 27000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 2          ");
 }
 else if (duration > 30000 && duration < 37000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 3          ");
 }
 else if (duration > 40000 && duration < 47000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 4          ");
 }
 else if (duration > 50000 && duration < 57000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 5          ");
 }
 else if (duration > 60000 && duration < 67000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 6          ");
 }
 else if (duration > 70000 && duration < 77000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 7          ");
 }
 else if (duration > 80000 && duration < 87000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 8          ");
 }
 else if (duration > 90000 && duration < 97000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 9          ");
 }
 else if (duration > 100000 && duration < 107000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: *          ");
 }
 else if (duration > 110000 && duration < 117000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: 0          ");
 }
 else if (duration > 120000 && duration < 127000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: #          ");
 }
 else if (duration > 130000 && duration < 137000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: A          ");
 }
 else if (duration > 140000 && duration < 147000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: B          ");
 }
 else if (duration > 150000 && duration < 157000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: C          ");
 }
 else if (duration > 160000 && duration < 167000)
 {
   lcd.setCursor(0, 0);
   lcd.print("Received: D          ");
 }
}

for details visit Li-Fi based Text Communication between Two Arduino

The loop is probably working well, you see 0 because this pulseIn() likely returns 0…

Why is that depends on all the information you did not give us.

Well, if you look at the comments on that site where you found the code, you'll see you are not alone.

I'd suspect that the LDR / 10k divider is not producing a clean digital 0 or digital 1 as required in response to the transmitter's led.

Ambient light may play a role. Try putting the transmitter led and receiver LDR very close and covering these with a dark cloth etc.

You may have to do some experiments with a simpler program on each side and maybe use the LDR to drive, indirectly, the base of a transistor to get reliable results.

This post looks remarkably similar:

Why did you double post and make us loose our time!

Shame on you.

(post deleted by author)

Hi, @kabiuo
Please explain what your code is supposed to do?
What your code actually does?

Does your code compile?
Have you written this code yourself?

Have you developed it in stages.
Have you code that JUST uses the LCD to prove the circuit and code?
Have you code that JUST writes and reads from the EEPROM?
Have you code that JUST communicates with the RTC?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

@kabiuo

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

Hm very different code in post #7.
Did you paste the wrong code by accident?