Analog Input Voltage to trigger Digital Pin (newb)

hi there, i have very low programming experience. and i need help on a project i am trying to make.

i have an Arduino Uno.

i have connected a WS2128B led strip and used a code i found out on the internet.

led strip works as intented. now i want to trigger the led strip effect, only when Analog Input reads some voltage. (i want to connect a cable from my turning indicator of my bike to an analog input. i already made the cable extension. i measured it its 8Volts.)

is this doable?

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 30 

#define DATA_PIN 6

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
Serial.begin(9600);
Serial.println("resetting");
LEDS.addLeds<WS2812B,DATA_PIN,RGB>(leds,NUM_LEDS);
LEDS.setBrightness(84);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(200); } }

 void loop(){
Serial.print("x");
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++ ) {
// Set the i'th led to red 
leds[i] = CRGB(255, 255, 0);
// Show the leds
FastLED.show();
   fadeall(); 
// now that we've shown the leds, reset the i'th led to black
//leds[0] = CRGB::Black;


// Wait a little bit before we loop around and do it again
delay(70);
}

}

is this doable?

Yes, of course

Read the analogue input using analogRead(). You will get a value between 0 (0v) and 1023 (5V) proportional to the voltage. Decide what value you want to trigger on, test the value from analogRead() and when it is above the trigger value then execute the code that you want.

would you be able to kindly provide me that code? i tried some stuff i found at google with no success.

the led strip was not powering up no matter what code i tried.

Yes, of course

Did you read ALL of OPs post?

It is NOT do-able AS DESRCIBED.

Feeding 8V into an analog pin on a 5V device is NOT a good idea.

Feeding the 8V to a voltage divider, with the resulting <5V going to an analog pin is do-able.

mitsakos: would you be able to kindly provide me that code? i tried some stuff i found at google with no success.

the led strip was not powering up no matter what code i tried.

The code you posted does nothing with an analog input, so your problem is unrelated to your post.

How is the strip powered? How is it connected to the Arduino? Which Arduino?

PaulS: The code you posted does nothing with an analog input, so your problem is unrelated to your post.

How is the strip powered? How is it connected to the Arduino? Which Arduino?

i left that part out cause it was no success, and i may end up confusing things.

board is arduino UNO r3. the strip is connected to arduino with 3 cables. 5V GND and a cable at 6 PWT digital output.

the strip at the moment is powered by a 5V ac power supply directly from wall socket to test things. i will end up merge it with the power of scooter.

void setup() {
  pinMode(6, OUTPUT) //make sure you have set your pins as inputs or outputs
  pinMode(A5, INPUT)
}

void loop() {
  if(analogRead(A0) > 512) { //if the analog value of A0 is greater than 512 then
    digitalWrite(6, HIGH); //write digital pin 6 high
  }
  else {
    digitalWrite(6, LOW); //if it isn't higher than 512, make pin 6 low
  }
}

PaulS:
Did you read ALL of OPs post?

It is NOT do-able AS DESRCIBED.

Feeding 8V into an analog pin on a 5V device is NOT a good idea.

Feeding the 8V to a voltage divider, with the resulting <5V going to an analog pin is do-able.

why not? i just need the digital pin 6 to trigger when analog input A5 is over 0.1 V, standby is 0V, so even the slight difference at that port on Volts should trigger the digital pin 6

why not? i just need the digital pin 6 to trigger when analog input A5 is over 0.1 V

It is not the 0V or the 0,1V threshold that matters, it is the 8V that you will be feeding into the Arduino pin that matters.

As Paul says, there are ways round it but the voltage going into the pin must not be allowed to exceed 5V

UKHeliBob: It is not the 0V or the 0,1V threshold that matters, it is the 8V that you will be feeding into the Arduino pin that matters.

As Paul says, there are ways round it but the voltage going into the pin must not be allowed to exceed 5V

i understand that i can drop the 8V to 5V with a regulator and a breadboard. but this is not an option, due to the extreme limited amount of space for the project to fit in. any other ideas that you guys may come up?

any other ideas that you guys may come up?

See reply #3

board is arduino UNO r3. the strip is connected to arduino with 3 cables. 5V GND and a cable at 6 PWT digital output.

Do you have a clue how much current your LED strip needs? Do you have a clue how much current the Arduino can supply?

While your Arduino isn't dead yet, you might want to acquire a supply of clues.