r/ComputerEngineering • • 37m ago

Beginner with hardware-please help

Post image

Hi everyone, so I am an intermediate level developer who has developed several different kinds of applications and deployed websites, etc. I am wanting to now do some C programming on some hardware, but I honestly don’t really know where to start with this particular project. I have some LEDs that I’m going to be wiring up and I’ve already built the entire program that will deploy the iterations of different animations onto the development board but when it comes to the hardware, I have no idea what I’m doing. My first task is to simply connect this button to the ESP 32 so that I can get some understanding of how it works just in general and from there, I will move over to doing some more looking into the LEDs considering that they need a separate power supply that is going to be another deal that I am not sure what to do with.

TLDR: if you have hardware experience, please help me wire this simple project. I want to connect a button to an SP 32 and make it to something like turn the light on or off or print.

0 Upvotes

8 comments sorted by

1

u/johndcochran 29m ago edited 7m ago

The button looks like a simple keyboard switch. But, having 4 wires instead of 2 is a bit surprising. Do you happen to have a link to the datasheet?

I am going to assume that you have a momentary contact SPST switch with an internal LED to light it. Before you do anything else, you need to identify what those 4 wires are. I assume you have a 5V power supply, and a resistor in the range of 470 to 1000 ohms.

So, let's first identify the wires for the LED. it may take as many as 12 attempts to identify which 2 wires, and the polarity.

Connect one of the 4 wires to ground via the resistor. Then touch, one at a time, the remaining three wires to +5V. The resistor should limit the current to a low enough value to prevent damaging anything. If they keycap lights up, take note of which wire was connected to ground and which to +5V. If nothing lights up, try again, using another wire connected to ground. It may take up to 12 total attempts.

After you've identified the pair of wires for the LED, the other 2 wires should be for the switch itself. Test it by connecting the +5V to one of switch wires. Connect the other switch wire to the wire for the LED that needs +5V. And connect the other LED wire to the resistor, and finally the resistor to ground. You should be able to make the LED turn on and off by simply pressing the button. If you can do that, they you've identified all 4 wires for your switch.

1

u/ColoredRunes 17m ago

Hmm good question. I will look that up. I think the button lights up so it might be data in and out?

1

u/ColoredRunes 4m ago

Got it so the wires are LED power black LED ground and then green and white are power SW

1

u/ColoredRunes 3m ago

Do I need a 5 V power supply to power this button or will the ESP 32 power it?

1

u/Ill_Engineering_9625 11m ago

First use a multimeter to determine which contacts are connected when you push the button, then you want to wire it to an input on the ESP32 so that pressing the button connects a pin to either high (3.3V) or low (GND). Then you want to add a pull up or pull down resistor (10k) to hold the pin in the other state until you press the button. Then you should be able to read the state in software, and you might have to apply debouncing to get it working reliably, basically only accept the button press when the value has stabilized for a few milliseconds.

1

u/ColoredRunes 7m ago

Ok so the resistor is actually the switch that keeps the data consistent? So for example, it keeps it from sending a constant signal and flips it whenever you press.?

1

u/johndcochran 1m ago

If you've identified the 2 wires to the actual switch, what he's saying is attach the 10K resister to one of the power rails at one end and to the switch at the other end. Then connect that same wire to the ESP32 input. That will give the ESP32 a known value. Finally, connect the other wire for the switch to the opposite power rail.

Basically, when the switch is open, the high value resistor gives a trickle of current to give a known state to the ESP32 pin. But when the switch is closed, it provides a dead short to the other power rail, completely overpowering the resistor, forcing the opposite state to the ESP32. I may be using the wrong term by saying dead short, because the current flow from rail to rail is limited by the 10K resistor, so nothing harmful will happen.

1

u/brotherterry2 23m ago

When I took embedded systems a couple quarters ago, we used free rtos. They have extensive documentation that will allow you to get your project done. That, along with reading the data sheet and watching some tutorials on you tube will help you get it done. Also, if you dont know how breadboards are connected, look that up. Good luck :)