Void loop doesn't work on my recevirer code

//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 " );

}

}

code in code tags works better for those who are wanting to help you.

What does "Void loop doesn't work for my receive code" mean?

1 Like

You can cover the character from 1 to 9 with just a little math.

  if (customKey >= '1' && customKey <= '9')
  {
    digitalWrite(8,HIGH);
    delay(10 * (customKey - '0'));
    digitalWrite(8,LOW);
  }

(You can also cover all of the characters with a lookup table of delay values.)

1 Like

Hi kabiuo,
welcome to the Arduino-user-forum. Well done to post your code.

Still you have to learn some things about how to post effective and in a convenient manner.
You posted a very loooooong posting that is 15 pages long. This forumwebsite has a function to combine posting long codes and still keep postings easy to read. This feature is called code-section

There is a very easy way to create a code-section:

Click the pencil-icon under your post to activate edit-mode of your posting.
mark all your code
then click on the </>-button in the headline and you are done

for future postings there is a even faster method for posting sketches

There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

You have a style to write code that stretches the code to the max
in your posting the code has 476 lines.

This can be reduced over 50% to 205 lines and the code ist still very readable

//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 ;
  }

and these are two different sketches so here is the receiver-sketch

//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.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 " );
  }
}

best regards Stefan

to determine what the reason is that your receiver-code is not working is to look into the serial monitor.

What is printed to the serial monitor?
If you compare the values with the values inside your if-conditions what do you conclude?

best regards Stefan

And with a little math, reduced further down to 69 lines:

//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 != NO_KEY)
  {
    Serial.println(customKey);

    if (customKey >= '1' && customKey <= '9')
    {
      digitalWrite(8, HIGH);
      delay(10 * (customKey - '0'));
      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' && customKey <= 'D' )
    {
      digitalWrite(8, HIGH);
      delay(130 + (customKey - 'A'));
      digitalWrite(8, LOW);
    }
  }
}

serial monitor shows only running 0's

You have a sender and a receiver. That's all we (the other users here ) know until now.
I can think of a lot of different reasons what could cause this.

I will not write down a three pages tutorial listing up all possible reasons that might cause this!

We need more information from you to change from wild guessings to analysing the problem.

What exact type of microcontroller are you using as the sender?
What exact type of microcontroller are you using as the receiver?

Make a picture of sender and receiver in a way that it is easy to see which IO-Pin do you use to connect sender and receiver? For this you have to take the picture from vertical above.
And you have to look at the picture and ask yourself
can a stranger who has only this picture clearly see which IO-pins are connected?

You might think "eh guys this is clear the one I have programmed"
Well if you would have done everything right it would work and you wouldn't need to ask
so please post the picture.

You can have a ping-pong-game of always new small answers and small questions asking back
then it will take weeks to solve this problem. I think you are interested in proceeding quicker.
Well this requires detailed information provided by you.

best regards Stefan

Hi,
Can you post a picture(s) of your project?
So we can see your component layout.

How are the tx and rx connected, wired, IR, RF, light?

Can you post circuit diagrams of your project?

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

Double posting is NOT cool.

I’m out.

To give you additional hints how to analyse what the problem might be.

If a system does not work:

  • add visual feedback about what your program is doing
    this can be switching on/off a led or serial debug-output

  • reduce the complexity of the system.

You might think eh guys this is a very simple system.

Well if you would have done everything right it would work and you wouldn't need to ask
so please follow this advice.

Depending on the microcontroller-type you are using (which you haven't told us yet) you can use the onboard-led for indicating.
And you can add serial-debug-output to see and read what is going on in your code

Your receiver-code is using the pulsIn-function. If you only receive 0's what does that mean?
You should look-up the reference what information the reference of the function pulseIn provides
https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/

EDIT:

this is not funny to start a second thread on the same question.
In this other thread you have - at least - provided some additional information what your project is about. Still you haven't provided how

YOUR

project is looking like
so please read this guide. And follow the given advice there.

I will only support you if you have posted detailed information like describe in this link

best regards Stefan

Here is a version of the receiver code that fits in 53 lines.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const byte InputPin = 8;

char Characters[] = "_123456789*0#ABCD";

void setup()
{
  pinMode(InputPin, INPUT);

  Serial.begin(9600);

  lcd.init();
  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(InputPin, HIGH);
  Serial.println(duration);

  if (duration == 0) // Timeout
    return; // Try again

  // Round off to the nearest tens of milliseconds
  unsigned index = (duration + 5000) / 10000;

  lcd.setCursor(0, 0);
  lcd.print("                "); // Clear the top line
  lcd.setCursor(0, 0);

  if (index > 0 && index < 17)
  {
    lcd.print("Received: ");
    lcd.print(Characters[index]);
  }
  else
  {
    lcd.print("Invalid: ");
    lcd.print(duration);
  }
}