Button Pressing

Follow the tutorial they offer.

Soldering is involved.

Connect:

  • 5V to your 5V power pin - don't use 3.3V power, the LCD needs 5V for contrast! The I2C pullups are fairly weak so you can use use 3.3V logic for SDA/SCL even if the board is powered with 5V
  • GND to Ground
  • DAT (SDA) to I2C Data (on the Uno, this is A4 on the Mega it is 20 and on the Leonardo digital 2)
  • CLK (SCL) to I2C Clock (on the Uno, this is A5 on the Mega it is 21 and on the Leonardo digital 3)

Note:
This board can be used with either I2C or SPI, hence the 5 pin terminals.

For your application, you will be using I2C; this uses 4 terminals.

Okay, I've ordered the parts and have another question. I will definitely ask more once the parts have arrived and I've gotten the opportunity to have tested some of the code sent and given the project a try. I will follow the circuit diagram you sent as closely as possible in as great detail as possible.
So, my question is "if I were to do this without buttons but instead do it by having my own homemade buttons using aluminium foil, would it work the same? Would it affect the current, voltage, or charge and make it not work?" Ideally, i want it so the users squeeze some sort of rope and it then completes the circuit sending an output to the arduino. I've tried to just keep it simple so far with classic buttons.

As long as your DIY switches achieve a low resistance path when they are activated, your switches should work fine.

BTW
Your ‘pulldown’ (1k) resistors should be located near the Arduino to prevent any accidental shorting of 5v to GND ‘at’ the distant switch location.

Alrighty, thankyou SOOOO much. I don't get what that end part means but I'll put the resistors close to the arduino anyway. I'm going entirely based on that circuit diagram once i've done the soldering of the backpack onto the LCD. So if you could review that and double check that's totally reliable to go off, of that would be very helpful :slight_smile:
Is that diagram drawn considering that it's a 2 pin backpack that i'm using?

The circuit offered to you works fine.

Could you please explain what's going on in the circuit. I don't understand why the capacitors are necessary and where the current is flowing in certain situations. I get that the 5V current flows out the arduino and to the display and the display makes sense to me. I don't get the capacitors and how the arduino will be able to know how many buttons are being held down at a time as all the wires connect into 1 wire as it returns to the arduino. If i don't understand this i won't be able to code it.

The code for this schematic was given to you in post #17.

The software code that outputs to the serial monitor needs to be changed/updated to accommodate the LCD, this is easily done.


The capacitors are there for two reasons.

  • they filter any possible noise from damaging an input, especially when long cabling is used.
  • they act as a de-bounce feature for each switch.

You might be able to omit these capacitors in your project, however, suggest you leave them in circuit.


The sketch offered in post #17 scans the switches one at a time to see if it is closed.

If the switch is closed, a counter is incremented.

After scanning all the switches, the value of the counter is printed to the serial monitor or LCD.


Note: when a switch is open that associated input sits at zero volts (LOW) because of the 1k resistor going to ground.

When that switch is closed, 5v from the Arduino goes to the top of this resistor and a HIGH is thus presented to the input.

When the sketch sees this HIGH on the input pin, a 1 is added to the software counter.


Please realize the ‘heavy/wide BLUE’ line is not a wire; this blue line is called a bus.

The black lines entering this bus go to the destination that ‘their’ signal name signifies (called a ‘net name’).

For example, the switch circuit (S1) at the far left of the schematic is attached to the Arduino header pin 17.

This switch signal has the net name “D02”, so does the black line coming out of the Arduino pin 17.

Two or more black lines with the same net name are connected together.

Black lines that come together at a ‘black dot’ are to be connected together.

If there is ‘no black dot’ where wires cross, there is no connection between these lines.


Test time.

The switch circuit at the far right side of the schematic (S15) has the net name “D16”.

What pin on the Arduino are you supposed the connect the S15 circuit to?

It would go to pin 11 I think lol.
Could you clarify a bit more about the bus (blue line) I'm unclear how I need to connect it at the bus. Is it essentially just all the wires from each bundles together taking the same path and going to their net named pin? i.e. a bunch of seperate wires taking a similar path?

“ It would go to pin 11 I think lol.”

You graduated!


Yes a bus is essentially a bunch of wires.

If we were to draw each wire connection separately, the schematic would get very messy very quickly :(.

Using ‘net names’ simplifies things immensely, in fact, sometimes the blue buses are omitted and black wires are given ‘net names’ only.

As mentioned, all black lines with the same net name would be connected together so the Blue bus really is not needed.

Sketch with I2C added:

//
//Arduino Voting Machine
//                    YY/MM/DD
//Version     1.04    20/01/05   Added I2C LCD code
//

#include <Wire.h>

//Use I2C library: https://github.com/duinoWitchery/hd44780
//LCD Referance:   https://www.arduino.cc/en/Reference/LiquidCrystal
#include <hd44780.h>  //main hd44780 header

//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O exapander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
hd44780_I2Cexp lcd(0x27);

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

//******************************************************************************

#define switchClosed HIGH

//************************************
byte lastCounter = 1;
byte counter;

unsigned long switchMillis;


//******************************************************************************
void setup()
{
  Serial.begin(9600);

  lcd.begin(LCD_COLS, LCD_ROWS);

  //************************************
  //set up I/O port configuration
  for ( byte x = 2; x < 17; x++)
  {
    //+5V--[ Swtich ]---,---[.1uF ceramic]---,
    //     [InputPin]---'---[1K Pulldown ]---'---GND
    pinMode(x, INPUT);
  }

  lcd.clear();

} //END of setup()

//******************************************************************************
void loop()
{
  //************************************
  //sample switches every 50ms
  if (millis() - switchMillis >= 50ul)
  {
    //resart timing
    switchMillis = millis();

    //go and sample all the switches
    checkSwitches();
  }

  //************************************
  //update the LCD 'if' there was a change in the # of switches being pressed
  if (lastCounter != counter)
  {
    //update to the new value
    lastCounter = counter;

    //remove Serial printing if not needed
    Serial.print("Number of switches pressed = ");
    Serial.println(counter);

    lcd.setCursor(0, 0);
    //                  1111111
    //         0123456789012345
    lcd.print("Pressed =       ");
    //           Col Row
    lcd.setCursor(10, 0);
    lcd.print(counter);
  }

  //************************************
  //other non blocking code goes here
  //************************************

} //END of loop()

//******************************************************************************
void checkSwitches()
{
  counter = 0;

  //************************************
  //scan all switches to see what is being pressed
  for ( byte x = 2; x < 17; x++)
  {
    //is this switch pressed?
    if (digitalRead(x) == switchClosed)
    {
      //we found a pressed switch
      counter++;
    }
    
  }

} //END of checkSwitches()

//******************************************************************************

Edit
Changed capacitor from 1uF to .1uF

Okay firstly I just want to say thank you SOOOO much for this, and idk what I'd do without you, you really know your stuff inside out too. Impressive :slight_smile: .
I noticed you put 1uf ceramic for the capacitor. Does it matter if it's ceramic? I ordered non ceramic ones. In fact I've got all the parts now and I just need to start the making which should be within the next week.

“know your stuff”
I made a mistake so guess not, should be .1uF, however, in this case both will work, not critical.

Non ceramic will work.

Alrightttt, I'm going to use non ceramic 1uf capacities which I ordered, 1k resistors (brown black black black brown) and my general Arduino. I'll get back to you once I've tested it and I'll tell you if it went successful or if I run into any dilemmas during the makings process :slight_smile: thanks again so much.

Give us a web link to the capacitors you ordered.

POPESQ® - 20 pcs. x Electrolytic capacitor 1uF 50V #A854 Amazon.co.uk
I don't really understand what effect a higher or lower uf and voltage on a capacitor means :sweat_smile: so I just went with the first 1uf I could find.

Those capacitors are ‘electrolytic ’ polarized capacitors.

Make sure the negative lead goes to GND (0v), the positive lead, goes to the top of the 1k resistor.


The shorter lead (in this similar capacitor) goes to GND.


The voltage rating on the capacitor is the maximum voltage you can safely apply to it.

We are using 5v in the circuit, therefor a 50v capacitor will be okay.

The uF rating is the size/value in micro farads of the capacitor, the larger the number the more energy it can store.

With 1k and 1uF, it takes ~5milli seconds for the capacitor to fully discharge when you let go of the switch.

T=5*(RC)=5(1k*1uF)~=5ms

“brown black black black brown”

You better check this with a meter, this would be 100Ω, you want 1k.

1st 2nd 3rd M T
brown black black brown brown

Yeah sorry I made a mistake, I meant to say brown black black brown brown :slight_smile: . And regarding the electrolytic capacitors, are you just saying to fit it into the circuit with the right direction (as you described)? No circuit changes need to be made right?

The Positive lead goes to the top of the 1k.

The Negative lead goes to the bottom of the 1k.

No circuit changes; you are just using a 1uF capacitor in place if the .1uF capacitor.

Re-posting of the schematic.

Hello again, I have a quick question. What stops the high voltage being "carried" through the capacitor to the GND and causing it to short? (when the button is closed)