Relay 12V, npn, pushbutton not working

Talked to a guy on reddit, he made a trickery on his ECU
easy enough, input VSS - output to ECU - use a 12V relay, a button to enable to add delay to the signal, when turned off and back on, it's normallised signal
i do have connection and no errors from ECU, just no function on push the button!

i can't get the relay to switch from NO to NC

Link to simulation, often when hitting reset, the NC reacts. but only S2 blinks and NO lights as it should
wokwi.com simulation
i'll post code he wrote here :slight_smile:

#define push_button 4
#define relay 3
#define signal 2
bool derestriction = 0;
 
void setup() {
pinMode(push_button, INPUT);
pinMode(relay, INPUT);
pinMode(signal, OUTPUT);
digitalWrite(relay, 0);
digitalWrite(signal, 0);
}
 
void loop() {
if(digitalRead(push_button) == 1) {
  digitalWrite(relay, 1);
  derestriction = 1;
}
 
if(derestriction == 1) {
  digitalWrite(signal, 1);
  delay(1);
  digitalWrite(signal, 0);
  delay(3);
}
}
 

components used
arduino nano "Clone"
2x 1/w w 10k resistor
push button
SRD-12VDC-SL-C RELAY
NPN resister 2n2222
diode 1n4007
wire

He then made a diagram on how to wire it all up.
diagram

i got everything wired up exactly, can post pictures if wanted, how ever i noticed he him self had the diode and npn other way around then me. ANYWAY

i can't even get a simulation of code to work probely, guessing something is wrong, and i'm not the best on coding skills yet. so giving the backstory, code and diagram. anyone able to see a flaw or why it wont work ?
Relay is NOT changing to NC, i understand that NO is normally open, and NC is normally closed. and in different simulations, it still doest change when pushing the button.
i'll be happy to provide pictures of my sodlering, just ask! dont want to spam a full article, altho it feels like it now :slight_smile: but im guessin is the code still


  digitalWrite(signal, 1);
  delay(1);
  digitalWrite(signal, 0);
  delay(3);

  • delay(1); this is 1 millisecond !

  • Suggest you isolate the signal going to D3.

  • 40k base resistor is high.

  • derestriction = 1; Where is derestriction ever made 0 ?

This looks as though you are trying to do something that might not be legal.

Have you read section 5.2 of the term and conditions?

5.2 The User is liable for the Content published on Platform and/or provided to Arduino and undertakes not to publish, upload or otherwise make available to the public through the Platform Content that:

  1. is false, illegal, misleading, defamatory, slanderous, intimidating, offensive or in any other way contrary to law and public morality;
  2. offends Users, Arduino or the online community;
  3. may constitute, encourage, promote or incite unlawful conduct;
  4. are in breach, at Arduino sole discretion, of patents, trademarks, trade secrets, copyright (meaning also licenses or license schemes, open source, GPL, Creative Commons or other standards used by Arduino community) or any other intellectual or industrial property rights;
  5. constitutes promotions or trade communications;
  6. at the sole discretion of Arduino, is in any other manner questionable or unconnected to the subject matter of the interactive areas in which the Content is publishedBlockquote

Relay is an input but your writing to it. That may be ok but is that what you intended ?

nothing illegal here, it's not for public road, but track racing, testing etc.
basicclly highjack a signal and put in a delay

i have no idea sadly, just recived the script from the guy on reddit, should i change it ?

I didn't look at your code...

Try changing R2 to about 200 Ohms. That should saturate the transistor (turn it fully-on).

The "absolute maximum" current allowed from an I/O pin is 40mA, which works-out to 125 Ohms. 200 Ohms more in the "safe" range.

Are you sure about the D3 connection to N.O.? Without (me) knowing anything about the scooter, you might fry the Arduino with excess voltage or current.

40k resistor ? it's 10k ? sorry fairly new to all this :slight_smile: trying to understand.

derestriction = 1, as he told me, it gets reset when you turn it of, and have to push button agian to make the delay agian.
hmm it should be enough with 1ms and 3ms according to his tests. but i could be wrong ofc. hence why i'm asking all you great minds :slight_smile:

by my logic and reading the diagram, yes, it doesnt recive on d3, but sends. the relay takes the input, and on push button, it alters to D3 instead.

hmm so lower the resistor on R2. because it's nots getting enough power? can i messure it with multimeter ?

For testing, I would ncrease the ontime for the signal from 1 ms to a few seconds at least. I dont know about the "scooter control unit" and what a few seconds connecting that would do so you might want to disconnect the load. This is just to get the relay to switch.

1 Like

Is that code the one sent you?
If not then please post the ORIGINAL code, if you have edited, then that explains the contradictions in the code.

What is it supposed to do, REALLY, signal from where to where and what is the advantage?

If the reddit supplied a schematic, can you please post that as well.

Can you post a link to the reddit?

Can you please tell us your electronics, programming, arduino, hardware experience?

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

posted original code and diagram, recived them in chat from him, and on pastebin.com. he's post is here original reddit post - no code or diagram there
also i wrote what components i used.

havent change anything AT ALL, just followed it. can post screenshots of our chat on reddit where i recived it all

basic knowledge of programming, and now how to sodler ish, and now to be carefull and that's about it :slight_smile: used to program a lot in early days of xcode, but that's been years since now.

idea is

you recive signal from a magnet sensor that counts cycles from a clutch, 8 magnets are there, that signal is to intercept, and make a delay so i makes the signal slower then it is.

A : signal from clutch 
B: to ECU 
B2: intercept and make delay to ECU

turn on scooter, drive, have limit when hitting 160rpm on clutch, press button while scooter is on, delay intercept but still sends signal; now clutch can spin say 180 rpm or more. as teh VSS "vechaile speed thinks its not hitting the limit it will keep climbing the fuel table, and get adjusted by lambda etc"
the VSS is only for limiting, nothing on combusting or ignition. hence why this works,
my emergency program has a limit way highere then regular, as this is for testing on track. but this a grteat advandtage! as normal procedure has better fuel table etc. then emergency fuel table

at no signal ECU goes to emergency mode witch lowers the rpm on clutch to 100 rpm or less.

roughly translates to 30km/t normal, pushbutton then you can go 50 km/t, emergency if no signal 20km/t
once you turn off the scooter, and turn it on agian, cycle is normal and you can go 30km/t -- until you hit the button agian. rinse and repeat

and well it actully goes to CDI then to ECU, as the signal gets converted from sinus to digital in CDI > ECU

R2 10k is pretty wimpy for what it's doing...

It looks like the relay is switching logic levels only. Then a relay is huge overkill, you can do it with a few logic gates, solid state, small and will never wear out.

Even, running the engines logic signal output into the Arduino, the entire thing could be done exclusively in software...

1 Like

ohh please! enligthen me, i'm just following a good idea on how to accomplish it.

You're following an idea about how to do it. My idea may or may not work, but certain kinds of signals can be switched and delayed by an MCU alone. I don't have a complete picture of how these signals behave, and how they are modified by the relay, but the circuit in itself at face value as a black box, probably can be replaced by a few resistors and diodes. I know that, because I fully understand the circuit itself. I don't pretend to know how it's used.

All it does is switch (multiplex) an output between some software produced signal on D3, and an external source. All that can easily be done inside the software, and can be done using an Arduino sketch.

All that is needed, is a circuit to feed the external signal into some input pin, with the right protection circuits on it (this is not necessary with the relay, a plus on its side). If you look around it is easy to find the circuits, as they exist in millions of real devices such as cars.

D3 is not really protected from induced EMI with any kind of filter circuit. That makes the CPU more likely to take a hit in a power surge, and reset itself. Or, the pin could be burned out. The resistor that was mentioned, doesn't at present supply an optimal amount of current to the relay drive transistor. It may not be fully saturated, which can become a heat dissipation issue. Alternatively, the relay might operate intermittently. Use about 200 ohms.

The transistor is rated at 50V collector base breakdown voltage, which is uncomfortably close to the 42V supply. On a scooter, the supply voltage is not assumed to be perfectly steady.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.