convert analog read to range to time

Hi All

I'm trying to blink a led with analog sensor between 8 and 40 times a minutes

I have try this code but I realize that I had to convert the valorSensor to time. How is the way to do it?

int led = 13;
int pinAnalogo = A0;
int analogo;
int valorSensor;

void setup() {
pinMode(led, OUTPUT);

void loop() {
analogo = analogRead(pinAnalogo);
valorSensor = map(analogo, 0, 1023, 4, 80);
digitalWrite(led, HIGH);
digitalWrite(led, LOW);


T = 1/F.

"times a minute" is a frequency, F.
delay() takes a time interval, T.

You have to do your unit conversions, minutes to milliseconds.

Delay() is in milliseconds. There are 60000 milliseconds in a minute. You need 2 delays, one for ON and one for OFF. So if you divide 60000/2 and then by valorSensor (after the map) that gives you the delay time you need.


Please read "Read this before posting a programming question" at the top of the forum and post your sketch using code tags.

You code looks OK, but you math doesn't look right. To get 40 flashes per minute you need to turn the LED on and off every 1500ms, so your delay would be 750ms on and 750 ms off. A range of 4 to 80 would blink, but just too fast to see it.

Next lesson- after you get this sketch to work, learn to avoid using delay() in a loop.