[SOLVED] Help with a circuit design

Hello everyone,

I am here in search of help and advice. My understanding of electronics baseline is somewhere between a toddler and a 7 year old. I am pretty familiar with automotive and motorcycle wiring, but when it comes to the basics, its pretty much over my head.

I am working on a project for a friend who has a bunch of $10 green/red laser lights from WalMart that he uses to light up trees in his yard. He asked me if there is a way to automate them, and I committed to help him out because I needed a project to work on. Everything is going to be controlled by Blink app and I figured that instead of running a bunch of wires to each light, We can just shove a D1 Mini into each one (there is plenty of space), power the D1 by incoming 5V, use 3 GPIO pins to get status of green laser, red laser, motion status and then use 2 more GPIO pins to control 2 buttons that change colors and turn motion on and off.

[PLEASE SEE THE ATTACHED IMAGE]

Getting state of green laser, red laser and motion was easy. I set pins 13, 14, 15 to INPUT_PULLUP and everything is working as expected.

What I am having trouble is buttons and I am 100% sure that I am doing is all wrong, but I’m having trouble understanding how to fix it. I was able to get the Color Control Button to work by attaching P1 off the Color Control Button to D5, but that stops actual physical button from working. I had 0 luck with Motion Control button. Adding diodes between D4/D5 and both buttons made physical buttons work, but my ESP lost status of button states, which is expected with diodes.

Both buttons get 5V on P1/P2 pins. When button is pressed, P1/P2 pin voltage drops to 0.

I would really appreciate some guidance on this.

Thank you!

Hi,

pruchai:
Both buttons get 5V on P1/P2 pins. When button is pressed, P1/P2 pin voltage drops to 0.

If that statement is always true, i.e.
measure color button you get 5v (even if the motion button is pressed) and then you get 0v when color button is pressed
measure motion button you get 5v (even if the color button is pressed) and then you get 0v when motion button is pressed

Then this should work:

// to read the button:
//
pinMode( COLOR_BUTTON_PIN, INPUT );
delay(10);
color_button= digitalRead( COLOR_BUTTON_PIN );

// to 'press' the button:
pinMode( COLOR_BUTTON_PIN, OUTPUT );     // make pin an output
digitalWrite(  COLOR_BUTTON_PIN, LOW );
delay( 200 );                            // pulse pin LOW
pinMode( COLOR_BUTTON_PIN, INPUT );      // turn pin back into an input

Yours,
TonyWilk

TonyWilk:
Hi,If that statement is always true, i.e.
measure color button you get 5v (even if the motion button is pressed) and then you get 0v when color button is pressed
measure motion button you get 5v (even if the color button is pressed) and then you get 0v when motion button is pressed

Hi Tony,

Thank you for your reply! I am not having issues with the code. I am having trouble wiring this thing up to work reliably.

I need to be able to use pins on the Arduino to change the state of these buttons, and I am pretty convinced that just connecting D4/D5 on the Arduino directly to the button pins is not something I should be doing.

Also, I do not need to detect the state of these buttons, but I do need to be able to trigger them from Arduino as well as pressing buttons physically. If I run a wire from the button to D5, I am able to trigger the button with my code, but the actual physical button stops working completely.

If you have not already done so, do those measurements. You need to confirm those buttons aren't multiplexed or something. Even better if you have a 'scope, just make sure they're not wiggling.

I am not having issues with the code.

Did you read each line of my code snippet?

There is no reason why a high impedance digital input should affect a button when both devices are running off the same Gnd/5V rails.

If you've set it as output, then...

Yours,
TonyWilk

Tony, you are a life saver!

I re-read your first reply and realized that the initial state of the button pins has to be INPUT, instead of OUTPUT, which was the root cause of disabling buttons! Also, adding delay after digitalWrite() and changing pinMode() back to INPUT was essential.

Thank you so much for your help!