Help Matrix Keypad with 7 segment display

So here's the deal.

I have to build a circuit with a matrix keypad, 7 segment display and a proximity sensor.

The user has to identify how many boxes he want to send [0 to 9] and validate it with key "#" of the keyboard. After that everytime the sensor identifies a box it has to show up on the display.

E.g.:
I want to ship 5 boxes. I type 5 and then # to validate the number. I pass the first box through the proximity sensor it shows 1 in the display, i pass the second it shows 2. When it reaches 5 after 4 seconds the counter goes back to 0.

I'm having issues with the connections of the 7 segment display as I never worked with it before.

Here is what I have until now:

As for the code I did not much yet because I'm having issues with the display.

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//define the cymbols on the buttons of the keypads
char keypadArray[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 1, 0}; //connect to the column pinouts of the keypad

Keypad myKeypad = Keypad(makeKeymap(keypadArray), rowPins, colPins, ROWS, COLS); 

void setup() {
}
  
void loop() {
 
    
  }

The sensor I'm using isn't the one in the picture, Im just trying to simulate it in tinkercad.
Also I'm using Arduino Uno R3

bump

You appear to have only three wires going to your seven seven segment display. That is not enough to display the digits between 0 and 9 (omitting the decimal point).
This is clearly a school assignment so you should be gently guided in the right direction but should not expect a full, tested solution.

Yes I understand, the thing I need help the most is with the seven segment display. I have no wires yet on my display because i really dont know what connect with what. As I said i never worked with this display before.

The first important question about a seven segment display is whether it is a common anode or common cathode type. This you find in the data sheet. You then have to find 7 free arduino pins to drive it. You can, incidentally, use analog pins (A0 to A5) also for this task as well as digital pins.

The 7-segment display should be easy to connect in TinkerCAD. Choose whether it is common anode or common cathode and then just connect the common to +5 or GND depending on what you chose and connect the segment pins.

The best way to proceed with your coding is to code and test each individual component separately. For example, write a sketch that does nothing but reads input from the keypad. Once that is working then write a sketch that does nothing but detects a box. Once that works write a sketch that can display numbers on the 7-segment display. Finally combine everything you have tested with the additional logic needed to meet the requirements of your project.

Ok so I have a delay of 4h to answer because I'm a new user.
I've followed your advice and so far I've been able to use the decoder with 7 segment display and keypad matrix. Everytime I hit a number on the keypad it shows up on the display.
Now the real issue I'm having is how do I lock down the answer of the user? For example, the user wants to ship 5 boxes so he clicks on number 5 and then he clicks on # to lock in, after that it should count how many times a box has passed through the sensor until it reaches 5 so when it does after 4s the counter gets back to 0.
This is all I've been able to do yet

P.S. I'm going to use a button in tinkercad to substitute the sensor

Code:

#include <Keypad.h>
const int buttonPin = 13;
int codA = 9;
int codB = 12;
int codC = 11;
int codD = 10;
const byte ROWS = 4; 
const byte COLS = 3; 

char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  pinMode(codB, OUTPUT); //A1
  pinMode(codC, OUTPUT); //A2
  pinMode(codD, OUTPUT); //A3
  pinMode(codA, OUTPUT); //A0
  Serial.begin(9600);
}

void loop()  
{
 char key = keypad.getKey();
  
  if (key == '0'){
    Serial.println(key);
  
      digitalWrite(codA, LOW);
      digitalWrite(codB, LOW);
      digitalWrite(codC, LOW);
      digitalWrite(codD, LOW);
  }   
    
  if (key == '1'){
    Serial.println(key);
  
   
      digitalWrite(codA, HIGH);
      digitalWrite(codB, LOW);
      digitalWrite(codC, LOW);
      digitalWrite(codD, LOW);
  }    

    if (key == '2'){
    Serial.println(key);
  
 
      digitalWrite(codA, LOW);
      digitalWrite(codB, HIGH);
      digitalWrite(codC, LOW);
      digitalWrite(codD, LOW);
    } 
     
     if (key == '3'){
    Serial.println(key);
  
      digitalWrite(codA, HIGH);
      digitalWrite(codB, HIGH);
      digitalWrite(codC, LOW);
      digitalWrite(codD, LOW);
      
     }
    if (key == '4'){
    Serial.println(key);
  
 
      digitalWrite(codA, LOW);
      digitalWrite(codB, LOW);
      digitalWrite(codC, HIGH);
      digitalWrite(codD, LOW);
          
    }
    if (key == '5'){
    Serial.println(key);
  
 
      digitalWrite(codA, HIGH);
      digitalWrite(codB, LOW);
      digitalWrite(codC, HIGH);
      digitalWrite(codD, LOW);
      
    } 
    if (key == '6'){
    Serial.println(key);
  
 
      digitalWrite(codA, LOW);
      digitalWrite(codB, HIGH);
      digitalWrite(codC, HIGH);
      digitalWrite(codD, LOW);
      
    }  
      
    if (key == '7'){
    Serial.println(key);
  
 
      digitalWrite(codA, HIGH);
      digitalWrite(codB, HIGH);
      digitalWrite(codC, HIGH);
      digitalWrite(codD, LOW);
      
    
    }
   if (key == '8'){
    Serial.println(key);
  
      digitalWrite(codA, LOW);
      digitalWrite(codB, LOW);
      digitalWrite(codC, LOW);
      digitalWrite(codD, HIGH);
     
   }  

    if (key == '9'){
    Serial.println(key);
  
      digitalWrite(codA, HIGH);
      digitalWrite(codB, LOW);
      digitalWrite(codC, LOW);
      digitalWrite(codD, HIGH);
      
    }  

  }

Interesting! :grin:

Between #1 and #8 with no prompting here that i can see, you have corrected the really bad blunder with the keyboard wiring. :thinking:

I'm having some coding issues atm.

I've set up a counter, buttonstate and prestate. The thing is how do I make it lock in a number after you press the key '#'?
E.g. User wants 5 boxes, he presses key 5 and then # to lock in number 5.

At the time you write a digit on the display, you could store its value in a global variable, called say lastDigit.
When you detect a '#' on the keypad you can use lastDigit for your counter.

I see, so this last digit would be inside the if of each number, right?
I would to lastDigit = key (?)

In principle yes. To avoid repeating the statement 9 times, you could instead check if key has a value between 1 and 9 and if so set the value of lastDigit.

Hi
These school works are getting simpler....

This is a school work just to practice not for evaluation and also it's in a degree of biomedical engineer, none of us had any experience related to coding, programing or electronics :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.