[Fritzing] Circuit help for buttons

A poor quality, worn-out or abused breadboard. Get a new, good quality breadboard and do not abuse it, and it will remain reliable for many, many years.

A simpler solution, which will also cause less drain the battery, would be to use logic-level, n-channel mosfets. With 5V relays, you need the buck converter because the Nano's regulator can't energise the 5V relays without overheating, I suspect. With mosfets, you can run the Nano on 12V, so you won't need the buck converter or the relays.

I hate wasting holes, so use a gouge made from a broken hacksaw blade to make slots between holes. :sunglasses:

Are you sure you even need an arduino for that? If a 555 timer is enough, you can power it with 12 volts directly.

Be careful with that. A pot or a trimmer are not made for current limiting, so they can't handle much current at all, even the relatively small current an LED draws may be too much. If you set the pot to a very low resistance, you risk frying the LED, the µC, or both. Buy yourself a kit of 1/4 W resistors instead.

Say you have a trimpot marked "103". To get the value in ohms, you multiply the first 2 digits (10) by 10 to the power of the third digit (3), which gives

10 × 10^3 = 10 × 1000 = 10,000

so 103 is a 10 kΩ pot, 473 is 4.7K (also spelled 4K7), 104 is 100K and so on. Just to be sure, check with a multimeter across the outer pins of the pot.

Through-hole resistors use a colour coding for the digits, but the principle is similar. There are silly mnemonics to remember the colours, but you always end up not remembering the mnemonics that are supposed to help you remember the colours. Better use the stuff over and over and the brain will take care of memorising it.

A poor quality, worn-out or abused breadboard. Get a new, good quality breadboard and do not abuse it, and it will remain reliable for many, many years.
Poor quality for sure. It's good to know they can be better.

use logic-level, n-channel mosfets. With 5V relays, you need the buck converter
because the Nano's regulator can't energise the 5V relays without overheating

This I really need some clarification on.

Just to be clear, the relay is for supplying power directly to some higher load 12v lights, controlled by the Arduino.

I was under the impression the 'SIP-1B05 DC5V' were some of the most power efficient relays.

Would a mosfet be better suited?

What is the coil current requirement for that relay? What is the current and voltage requirement of the load?

Here is a MOSFET relay driver.

It is more efficient to use just the MOSFET to switch the load, if possible.

Thank you for the schematic.

After forgetting to change the resistors and blowing 1 led, and of course wondering why the button input didn't work (I connected it to positive instead of negative) and cocking up a soldered point.

I managed to get it working. Next time I make this it'll be a hell of a lot prettier from behind. This is the first time I've done anything with an arduino or made a proper circuit. :sweat_smile: I couldn't have done it without you.



Code:

const int PIN_BUTTON_LEFT = 11, PIN_BUTTON_RIGHT = 10;
const int PIN_LED_LEFT = A1, PIN_LED_RIGHT = A0;

void setup() {
  // Buttons
  pinMode(PIN_BUTTON_LEFT, INPUT_PULLUP);
  pinMode(PIN_BUTTON_RIGHT, INPUT_PULLUP);

  // Lights
  pinMode(PIN_LED_LEFT, OUTPUT);
  pinMode(PIN_LED_RIGHT, OUTPUT);
  
  Serial.begin(9600);
  Serial.println("Start");
}

int i = 0;
void loop() {
  const bool BUTTON_LEFT = !digitalRead(PIN_BUTTON_LEFT);
  const bool BUTTON_RIGHT = !digitalRead(PIN_BUTTON_RIGHT);
  
  digitalWrite(PIN_LED_LEFT, BUTTON_LEFT? HIGH: LOW);
  digitalWrite(PIN_LED_RIGHT, BUTTON_RIGHT? HIGH: LOW);

  delay(100);
  
  Serial.println("Left: " + String(BUTTON_LEFT) + " " + String(BUTTON_RIGHT) + " " + String(millis()));
}

I'm well aware I should be able to do something via interrupts instead of in a loop. But I've not looked into that yet.

The relay current requirement is 0.25ma. The indicator lighting voltage will be 12v, currently I have no idea the exact load. As I'm still waiting for 2 more indicators for the handlebars.

It'll be 6 LED's I believe, some quite bright. I doubt it'll exceed 1A very much.

It is more efficient to use just the MOSFET to switch the load, if possible.

I don't quite understand the terminology sorry, please pretend you're speaking to a child. Basically you're saying that instead of a relay as an optocoupler, use one of these MOSFET's?

Or do you mean to power the arduino? I'm actually stepping down from 60-72v for the arduino.

Hi, @turbine101
Good to see you are making progress.
If you are going to do a lot of experimenting it is worth making something like this;


It is just two 10K pots and three SPDT stiches that are wired to header pins to allow reliable connections to these components.
I also have a Veroboard with a number of those tactile switches soldered to it and connected to headers as well.
It makes prototyping that little bit easier.

Tom... :smiley: :+1: :coffee: :australia:

Interrupts are absolutely not required for switched operated by humans. Interrupts are to capture things that happen quickly and unpredictably. Properly written code will run the loop() function thousands or at least hundreds of times a second. A button press will not be missed by polling (what you do in loop()).

You should not use the const modifier there. The BUTTON_LEFT or BUTTON_RIGHT are variables that can change, so const is misleading.

Avoid the use of the String class until you know how to use it. The String class can cause memory problems. See the evils of Strings.
Do it like so:

   Serial.print("Left: ");
   Serial.print(BUTTON_LEFT);
   Serial.print( " " );
   Serial.print(BUTTON_RIGHT);
   Serial.print(" ");
   Serial.println(millis());

I seriously doubt that 0.25mA figure for a relay coil current. Even a reed relay. Can you post where that figure came from?

I found this data sheet. I get a coil current of 10mA which can be driven by an Arduino output (20mA max, recommended) without the MOSFET. But the contact is rated at 0.5A max.

"the relay is for supplying power directly to some higher load 12v lights"
I am afraid that the relay contacts can't handle the load of " higher load 12v lights". You need to know what the current demands of the lights will be in order to pick a driver.
If not, the logic level MOSFET would be better.

The reason that I say that the MOSFET is more efficient is that the MOSFET is voltage operated. It takes only a few milliamps, briefly, at turn on to charge the gate capacitance and thereafter draws virtually zero current. On the other hand a relay is current operated. It will draw coil current the entire time that it is turned on.

And mechanical relays wear out. MOSFETs do not.

What the heck is that? It looks like something out of the original Doctor Who or Blake 7. I mean, what do the dials do?

My perfboard might seem like I'm prototyping, but this is also the real deal for me. Next time, I'll make sure to have a better quality bread board. I don't suppose you have a model/supplier? I'm from NZ, so it might be similar to you over in Aus.

Interrupts are absolutely not required for switched operated by humans

Oh, I figured if it enters the deep sleep state - some kind of subsystem would invoke a kind of interrupt upon an input. I'm not sure how it all works yet.

You should not use the const modifier there. The BUTTON_LEFT or BUTTON_RIGHT are variables that can change, so const is misleading.

It's not going to change as it's defined within the function scope. It's just habit for me to start with const everywhere.

Avoid the use of the String class until you know how to use it. The String class can cause memory problems. See the evils of Strings.
Do it like so:

Thank you, I was wondering if there was a 'put' without line endings.

pots == potentiometers, just add knobs.
330px-Electronic-Component-Potentiometerpot-circuit

SPDT switch;

p3o1hMcKaQGLz9F2MQuAPQ

Tom.... :smiley: :+1: :coffee: :australia:
PS. You may need a sonic screwdriver to assemble it...

Well I'm glad somebody knows what they're talking about.

Someone in a forum mentioned these don't use very much. But I couldn't recall how much exactly.

The reason that I say that the MOSFET is more efficient is that the MOSFET is voltage operated. It takes only a few milliamps, briefly, at turn on to charge the gate capacitance and thereafter draws virtually zero current. On the other hand a relay is current operated. It will draw coil current the entire time that it is turned on.

Interesting. Are mosfets also magnetic?

But the contact is rated at 0.5A max.
Right, so if my lights draw any more than 0.5 - I'll fry the thing.

How many ma did you say switching uses with a 5v control circuit using MOSFET's? And is there a particular kind? NPN, PNP, etc. I'm terrified of misusing a MOSFET, as it's unfamiliar and I believe can amplify.

Oh, I see. You provide these as inputs for a test PCB. Where did you get that box from?

PS. You may need a sonic screwdriver to assemble it...

Fortunately Aliexpress sells such devices, thank you.
(https://www.aliexpress.com/item/1005003356832031.html)

https://www.aliexpress.com/w/wholesale-electronics-case.html

Most electronics suppliers will have them, but you don't necessarily need a case, my first one was on Vero.

Tom... :smiley: :+1: :coffee: :australia:

Well I'm sure you weren't ready for all these responses. So I'd figure I would add another.

  1. Using Fritzing like you are if perfectly fine. Most don't like Fritzing because many folks use it instead of a schematic. If you keep working with Arduinos you will eventually learn about schematics but for now you are fine.

  2. I don't believe your switches are wired correctly. First on most 4 lead switches there are only two circuits. Something like this:
    image

So you should wire on lead to ground and the other lead to the digital input you wish to use to monitor the switch. You then (like mentioned above) enable the pullup.

As for why some folks don't use the internal pullup, I guess random design decisions. You will find there is no "Absolute Best" design. There are always variations.

I misunderstood what you are using an interrupt for. For waking from sleep an interrupt is called for, I guess. I have not done much with the sleep and power down modes.

It is a habit that will, sooner or later, get you in trouble. Use const for things like pi or a pin name that will never change in value in the code. Using const like you do in that code is inappropriate even if it does not cause a warning or an error.

const float PI = 3.141592;
const buttonPin = 9;