Hello, whilst I consider myself a very good software engineer, electronics is not my strong point and I'm very much a newb when it comes to electronics.
I have been working on a project which I want to connect to my car at some point. The links to the demos to show what it does are below:
Right indicator animation
Left indicator animation
Reversing animation
Hazards animation
Brakes animation
The plan is to interface these to the CAN bus network in my Audi A5, when complete I will fix it in the top of the rear window. I want to right up a demo using push buttons of this type:
Push button
So far I've used an Arduino Uno for the prototype, but I will probably move over to a smaller Arduino based board for the final setup. I have a Can Bus adapter which I'm not currently using. I've got the neopixels connected to pin 6. My problem is this, I want to use a number of push buttons to simulate signals from the car before I implement the can bus interface.
I've hooted up a single switch to pin 7 with the GND and 5V either side of the switch. I haven't modified my code yet to implement the switch, however when I push the button, the neopixels stop animating.
I'm not sure what I've done wrong and how I can power the neopixels and the button without the button effecting the pixels?
Can you post a picture of the switch and how the switch is wired? It sounds, to me, like the switch is shorting the 5V to ground.
Wire the switches so they connect the pin to Gnd when pressed.
Turn on the internal pullup resistors:
pinMode (pinX, INPUT_PULLUP);
and then look for a LOW to indicate button press:
if (digitalRead(pinX) == LOW){
// button pressed, do something
}
or
pinXstate = digitalRead(pinX);
if (pinXstate == LOW){
// do something
}
Sorry I don't have any place to upload images.
The connection information is:
push button connected to 5v, GND and pin 7, via resistor.
Neopixel strip is connected to 5V, GND and pin 6.
@CrossRoads, but why when I press the button does it interfere with the neoxpixoel strip on pin 6?
How to wire a momentary switch to work with CrossRoads code:
How to upload images.
Thank you, I don't have a capacitor, I'll have to pick one up.
You don't need the cap. It is optional. You can deal with switch bounce (the reason for the cap) in software. You don't need the 10K resistor either, if you enable the internal pullup with
pinMode(pin, INPUT_PULLUP);
Then I still don't understand why in my original set-up, without any software modifications, just adding the switch to the circuit causes the power to the neopixels to stop when the button is pressed.
SPlatten, there should be no 5V connection. Just to Gnd, The internal pullup resistor is usually sufficient unless there is a long wire run from the button to the Arduino.
To post a picture: Use Reply, scroll down and use the Attachment and other options button. Browse to your locally store file and Attach it. Post it.
Once posted, right click on the name icon and Copy Shortcut.
Select More:Modify, and paste in the shortcut with the Image tage (looks like a monitor in the menu), or use img & /img tags.
Reads worse than it actually is to do it.
Then I still don't understand why in my original set-up, without any software modifications, just adding the switch to the circuit causes the power to the neopixels to stop when the button is pressed.
And we don't know, exactly, how the switch was wired.
@CrossRoads & @groundfungus,
I suspect the switch is not wired correctly, at the moment I have the 5v connected to one side of the switch with GND connected to the other side of the switch.
I've attached a photograph taken of the set-up.
There are a myriad of types of "switches". In the schematic that I posted is a single pole single throw momentary switch (unambiguous description). From your description it is not possible to know what type of switch you are referring to. Hence the request of a picture or schematic.
I posted a link to the switch I'm using but unfortunately the RS web-site appears to be down, the part number is 479-1441, White Button Tact Switch, SPST 50 mA@ 24 V dc
This site is up: RS
I agree the circuit certainly does look wrong, I'm pretty sure I followed some online guide for connecting up the switch, but I probably followed it wrongly.
To use that switch safely:
Thank you, I will try it now.
Ok, now it works, thank you for your help.
I've hooted up a single switch to pin 7 with the GND and 5V either side of the switch

Most power supplies don't like being shorted out. It's possible that you might have damaged it by doing this depending on how good its short circuit protection is (if it even has such a luxury).