# To program output on and off

**URL:** <https://forum.arduino.cc/t/to-program-output-on-and-off/1342836>\
**Category:** Programming\
**Created:** [January 15, 2025, 6:55am UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836 "2025-01-15T06:55:51Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [January 15, 2025, 1:48pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/21 "2025-01-15T13:48:38Z")

</div>

look this over  
trying to verify what you want by giving you possible solutions

- code measures time between events
- updates a period by averaging
- recognizes "sync" when time between events \> 1.9 \* period
- generates "tdc" 5 events after "sync" (needs to be 17 ??)

```arduino
         msec msecLst msecPeriod
   5: 2359 152 140
   6: 2659 145 141
   7: 2946 133 139
   8: 3251 150 141
   9: 3535 139 141
  10: 3828 148 142
  11: 4105 154 145
            sync
   0: 4751 483 229
   1: 5143 232 229
   2: 5434 151 210
   3: 5754 156 197
   4: 6027 126 180
            tdc
   5: 6312 132 168
   6: 6605 140 161
   7: 6904 151 159
   8: 7183 134 153
   9: 7474 135 149
  10: 7752 133 145
  11: 8030 142 145
  12: 8345 164 149
  13: 8625 132 145
  14: 8936 158 148
  15: 9222 142 147
  16: 9486 128 143
  17: 9801 171 150
            sync
   0: 10386 447 224
   1: 10727 193 217
   2: 11014 123 194
   3: 11323 171 189
   4: 11593 139 177
            tdc
   5: 11871 140 168
   6: 12177 142 162
   7: 12464 135 156
   8: 12735 164 158
   9: 13008 148 156
            sync
   0: 13463 332 200
   1: 13755 150 188
   2: 14071    

```

```arduino
const byte PinOut = LED_BUILTIN;
const byte PinInp = A1;

byte inpLst;

const long MsecDebounce = 20;
      long msecLst;
      long msecInp;
      long msecPeriod;

char s [90];

// -----------------------------------------------------------------------------
const int Cnt = 5;
      int cnt;

void
loop (void)
{
    unsigned long msec = millis ();

    byte inp = digitalRead (PinInp);
    if (inpLst != inp && msec - msecLst >= MsecDebounce) {
        if (LOW == inp) {
            msecInp = msec - msecLst;

            if (Cnt == ++cnt) {
                Serial.println (" tdc");
                digitalWrite (PinOut, HIGH);
            }
            else if ((Cnt + 2) == cnt)
                digitalWrite (PinOut, LOW);

            if ((1.9 * msecPeriod) <= msecInp) {
                Serial.println (" sync");
                cnt = 0;
            }

            msecPeriod += (msecInp - msecPeriod) / 4;

            sprintf (s, " %3d: %6lu %6lu %6lu", cnt, msec, msecInp, msecPeriod);
            Serial.println (s);
        }

        inpLst = inp;
        msecLst = msec;
    }
}

// -----------------------------------------------------------------------------
void
setup (void)
{
    Serial.begin (115200);

    pinMode (PinInp, INPUT_PULLUP);
    pinMode (PinOut, OUTPUT);
}

```

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 15, 2025, 2:14pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/22 "2025-01-15T14:14:25Z")

</div>

[quote="gcjr, post:15, topic:1342836"]

Could the Arduino output go high when is recognizes the 17th tooth in the gear and go low after 20th teeth ? And when 2 missing teeth is switching next injector bank.

Next injector bank is next engine revolution output go high when is recognizes the 75th tooth in the gear and go low after 78th tooth.

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [January 15, 2025, 2:17pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/23 "2025-01-15T14:17:21Z")

</div>

> [@andrew1q](#):
>
> Could the Arduino output go high when is recognizes the 17th tooth in the gear and go low after 20th teeth ?

`Cnt` needs to change to 17 and

> [@gcjr](#):
>
> ` else if ((Cnt + 2) == cnt)`

needs to change to `+ 3`

the other issued is does this processing occur when the input becomes HIGH or LOW

> [@gcjr](#):
>
> ` if (LOW == inp) {`

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [January 15, 2025, 2:21pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/24 "2025-01-15T14:21:19Z")

</div>

I'm not going to play here and I'll try to not watch.

Anyone who wonders why can see

> [@Create code for Arduino](https://forum.arduino.cc/t/create-code-for-arduino/1339715):
>
> What type of the code need for Arduino to turn on one time a day one LED light by using input signal of the sensor which provides digital square wave form ?

If you didn't know, now you know.

a7

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 15, 2025, 3:42pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/25 "2025-01-15T15:42:29Z")

</div>

This is diagram that shows and describes the relation between tooth number and IO pin On/Off

1. Input pin 2 will read 116 pulses of the crankshaft reluctor wheel. Two engine revolution is 720 degrees of the crankshaft position. 720 degrees equals to 116 pulses or 116 teeth of the crankshaft reluctor wheel. One engine revolution is 360 degrees with 58 teeth or 58 pulses.
2. Input pin 3 will be reference for injector bank 1 with injectors 6-2-4. Every time when cylinder number six fires that is the reference that injector bank is in TDC. The reference must be used for injector bank 6-2-4. If reference will be not provided then for an example one of the injector bank when go to exhaust and output pin goes high. Will be no performance. Injector bank must inject fuel when intake valve is closed.
3. At start up by cranking starter the first engine revolution when injector bank 1 with 6-2-4 injectors referenced by voltage from 0.25-1.5 at 120 degrees or 20th tooth then that time coming revolution another injector bank with 1-5-3 injectors should be activated by output pin 10 at 222 degrees or at 75th tooth till 240 degrees or 78th tooth .
4. Two missing teeth should be skipped every engine revolution. Otherwise could be also reference for to switch high or low coming injector bank.
5. Cylinder number 6 makes the reference to input pin 3. Cylinder number six is related to the injector banks 6-2-4.
6. First engine revolution at cranking starter at 120 degrees activated injector bank 2 pin 10 with injectors 1-5-3 at 222 degrees or 75th tooth till 240 degrees or 78th tooth.
7. Second engine revolution is activated by output pin 9 at 102 degrees or 17th tooth till 120 degrees or 20th tooth for injector bank 1 with injectors 6-2-4.
8. Here is the trick when injector bank with 6-2-4 injectors is activated at 120 degrees or 20th tooth then next engine revolution pulse width should not be activated at 222 degrees or 75th tooth till 240 degrees or 78th tooth for injectors 1-5-3 output pin 10 is not active.
9. Next engine revolution pulse width should be activated by output pin 9 at 102 degrees or 17th tooth till 120 degrees or 20th tooth for injector bank 6-2-4 then next engine revolution pulse width should be activated by output pin 10 at 222 degrees or 75th tooth till 240 degrees or 78th tooth and so on loop.
10. At start up only first engine revolution should be one injector bank with 6-2-4 injectors is not active because this is reference point after that referenced by input pin 3 then next engine revolution injector bank with 1-5-3 injectors should be activated by output pin 10.
11. If you notice any mistakes on this diagram please correct it any time. Thanks in advance for your answer !

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 15, 2025, 3:50pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/26 "2025-01-15T15:50:14Z")

</div>

> [@andrew1q](#):
>
> This is diagram

I see no diagram

Your post is much easier to read that the first one but from its contents this topic looks like it might be going in the same direction as your previous ones. Did you write it yourself ?

We are already 25 post in and seem to be making little or no progress towards understanding your problem and how to solve it

---

<div class="post-metadata">

**Author:** ![koikeeper](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koikeeper/32/1127461_2.png) [@koikeeper](https://forum.arduino.cc/u/koikeeper)\
**Post date:** [January 15, 2025, 3:59pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/27 "2025-01-15T15:59:41Z")

</div>

The problem is not solvable.  
Looked at a Bosch FI block diagram there are several items related to the firing and duration of pulse from injector.  
If the OP was going to do his own ECU with controls he would have a chance.

But my bets are on the cost to fix the M30 is above what he can afford so he is trying a hack work around.  
But as I have said before trying to out engineer Bosch is not gonna happen.

These threads are proving that AI is not the cat's whiskers.

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 15, 2025, 4:21pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/29 "2025-01-15T16:21:43Z")

</div>

Yes I did write by myself.

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [January 15, 2025, 4:29pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/30 "2025-01-15T16:29:24Z")

</div>

I don't believe you. You convinced me that you are a troll. You continued for 300 postings in the other thread to ignore questions beeing asked and here you are again ignoring questions very consequently. You seem to have fun with trying to test how many trying to be helpful answers you can get with ignoring answers.

The other explanation is: You have such a big mental problem that you are unable to understand what your problem is.

I recommend to the moderators to ban this user for a week.  
I recomend to all other users to put user @andrew1q on the ignorelist.

As a final advice: take another person that you like and that you trust. Show this person your two threads and make this person to explain to you what you are doing wrong in your threads. If this person is able to explain to you what you shall do come back with adequate postings.

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 15, 2025, 4:33pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/31 "2025-01-15T16:33:47Z")

</div>

I did not make drawing diagram yet. I am on my way to make a one more diagram. Which answer I did not answer remind me please ?

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [January 15, 2025, 4:34pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/32 "2025-01-15T16:34:55Z")

</div>

[tips how to improve your posting style](https://forum.arduino.cc/t/generalised-posting-explaining-how-to-change-from-a-llt-writing-style-to-a-productive-style/908944)

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [January 15, 2025, 5:48pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/33 "2025-01-15T17:48:59Z")

</div>

> [@andrew1q](#):
>
> This is diagram

where is the diagram?

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 15, 2025, 5:57pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/34 "2025-01-15T17:57:18Z")

</div>

I can’t make better diagram that is final diagram and simple as possible. Based on this information the programming code can be made.

 ![IMG_1385](https://europe1.discourse-cdn.com/arduino/original/4X/e/b/8/eb8bbaff07bd21411106926e2303e78c0a2eb0a9.jpeg)

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [January 15, 2025, 7:00pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/35 "2025-01-15T19:00:02Z")

</div>

> [@andrew1q](#):
>
> I can’t make better diagram that is final diagram and simple as possible

No you can do such a diagram

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/d/1/1/d11097e0f479758660379f4e028245e9337f020c.png)  
you are just too lazy to draw one

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 15, 2025, 7:50pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/36 "2025-01-15T19:50:43Z")

</div>

> [@andrew1q](#):
>
> make better diagram

@StefanL38 made a blank "60 tooth diagram" (it's huuuge!). I added your Input and Output pins. Add lines to show highs and lows above the tooth numbers.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/d/e/9/de9ffe0d2f7adedc9b968218730e6dcdf3684a13.png)

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [January 15, 2025, 9:04pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/37 "2025-01-15T21:04:45Z")

</div>

> [@andrew1q](#):
>
> This is diagram that shows and describes the relation between tooth number and IO pin On/Off

does this illustrate what you're looking for?

red the output pulse, 17 teeth after the missing teeth for 3 periods  
yellow, the missing 2 teeth  
cyan represents the 60 possible teeth

 ![Capture](https://europe1.discourse-cdn.com/arduino/original/4X/a/f/3/af3c20ac260f8142bb62feab71e46101b02d29b7.png)

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [January 15, 2025, 9:11pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/38 "2025-01-15T21:11:32Z")

</div>

Hi,

Is this system a two or four stroke?

Four stroke will need a camshaft sync to identify if TDC is about to become power stroke or inlet stroke.

Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![koikeeper](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koikeeper/32/1127461_2.png) [@koikeeper](https://forum.arduino.cc/u/koikeeper)\
**Post date:** [January 15, 2025, 11:09pm UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/39 "2025-01-15T23:09:29Z")

</div>

Here are two questions you need to answer.

How will the throttle pedal control this?

How will you make motor run when you take fuel injectors out of system it is an integrated system.

Answer these if this project has any validity. If you can't you should stop wasting bandwidth.

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 16, 2025, 5:13am UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/40 "2025-01-16T05:13:42Z")

</div>

1. How will the throttle pedal control this system ?

---

<div class="post-metadata">

**Author:** ![andrew1q](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/andrew1q/32/1151684_2.png) [@andrew1q](https://forum.arduino.cc/u/andrew1q)\
**Post date:** [January 16, 2025, 5:17am UTC](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836/41 "2025-01-16T05:17:29Z")

</div>

M30 engine does not have camshaft position sensor. M30 engine runs on crankshaft position sensor only. Even running if cylinder identification sensor is disconnected.

[Previous page](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836.md?page=1)

[Next page](https://forum.arduino.cc/t/to-program-output-on-and-off/1342836.md?page=3)
