Pulse votage input to run code

I have a basic car alarm and i want to replace the blinking led with a attiny85 (or something similar) and a neopixel strip to run when the alarm is active. But the power to the factory led is not constant. It is a pulsed 5v. Is it possible to still use the pulsed voltage to trigger the attiny85 to run my code when the alarm is active and stop it when the alarm is deactivated?

Yes.

Write your sketch such as to create a retriggerable TIMER.

Off for x seconds = no action
On = action, code runs.
If on occurs in last x seconds runState = true

X>blink cycle time

Ie look for the blinkPin input to go high (led has gone on) and then change runState to true. If runState true {code}. When blinkPin goes high store millis (timerOn variable = millis). If millis - timerOn > blinkPeriod set runState false

I have no idea how to write code from scratch. I usually just find what i need and modify it for my purposes.. This is the code i'm wanting to run when the alarm is active and stop when it's not.

#include <Adafruit_NeoPixel.h>
#define PIN D1
#define NUMPIXELS 11
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delay_time = 125; // 200 msec = 1/5th of a second

void setup() {
  pixels.begin();
}

void loop() {

  // from left to right
  for(int i=0; i<NUMPIXELS; i++){
    pixels.setPixelColor(i, 0, 0, 255);
    pixels.show();
    delay(delay_time);
    pixels.setPixelColor(i, 0, 0, 0);
    pixels.show();
  }

  // from right to left
  for(int i=NUMPIXELS; i>0; i--){
    pixels.setPixelColor(i, 0, 0, 255);
    pixels.show();
    delay(delay_time);
    pixels.setPixelColor(i, 0, 0, 0);
    pixels.show();
  }


}

Put the code you want to run in a function

void myFunction (){
Your code}

Look at reference for syntax

Then make 3 variables eg
Bool runState = false;
Unsigned long timerOn =0;
Int blinkPeriod = 1000

Look up if statements in reference

If digitalread inputPin == HIGH {
RunState = true
TimerOn=millis
}
If runState == true
myFuntion

If millis - timerOn > blinkPeriod
RunState = false

Note I am on a phone, my code is pseudocode for concept and the syntax is available on the reference I have left out many ({;s

I have no idea how to combine your sketch with mine.. Sorry.. New to this

I never thought I would need it again, but does this sketch a very similar logic like you want?

https://werner.rothschopf.net/202010_arduino_switch_by_time_en.htm

The car alarm's led is on a on/off 5v current, meaning it is at 0v then 5v for 0.5 seconds, then 0v for 0.5 seconds, then 5v again for a 0.5 second and repeats. Basically it's just a ordinary led that's only on when it receives the 5v pulse. I'm wanting to use this current for an arduino or attiny85 to run a sketch as long as it recevies a 5v trigger every 0.5 seconds. If the arduino or attiny85 does not receive this 5v trigger it will stop running the code.

I have not provided code just the concepts you need. If you don’t know how to code that then you need to start with the basic examples in the ide and start learning. Use the language reference for correct syntax and use a logical iterative approach always working on only one thing at a time and saving sketches regularly to new appropriate names.

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