Reading DC motor's value

Hello,
this is my first post on the forums. I am having problems with reading the value of my dc motor that came in the starter kit. I'm basically trying to turn on more or less LED's depending on the speed of rotation. But every time I try to set the treshold lower all the LED's turn on and not back off. the value on the serial monitor shows that it gets stuck on too high of a value.

const int analogPin = A0;   // pin that the sensor is attached to
const int yellow = 13;      // pin that the LED is attached to
const int green = 8;
const int red = 7;
const int threshold1 = 709;
const int threshold2 = 730;
const int threshold3 = 709;
void setup() {
    pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
   pinMode(red, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  delay(200);
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (3.3 / 1023.0);
  Serial.println(sensorValue); 

  // if the analog value is high enough, turn on the LED:
   if (sensorValue > threshold1) {
    digitalWrite(yellow, HIGH);
  } 
    delay(10);
   if (sensorValue < threshold1) {
    digitalWrite(yellow, LOW);
   }
 if (sensorValue > threshold2) {
    digitalWrite(green, HIGH);
  } 
    delay(10);
   if (sensorValue < threshold2) {
    digitalWrite(green, LOW);
   }
if (sensorValue > threshold3) {
    digitalWrite(red, LOW);
}
  else {
    digitalWrite(red, HIGH);
   }}

This is the last value set that I can get to work anything lower the problem mentioned above happens.
My DC motor is pluget into 3.3V and A0.
I would apriciate some help

Welcome to the best Arduino forum.

To make it easier for us to help, post a schematic of your project
and provide more details about what type of sensor you are using in A0.

It looks like he/she is trying to read the voltage output of the motor when it is rotated

@era_big your sketch prints out the value read on A0. What values is it showing?

it's odd the way you have separate if/else tests for each theshold/LED and that 2 of your thresholds are the same value

look this over which is easier to read because only the first true if condition is executed and sets all LEDs

const int analogPin = A0;   // pin that the sensor is attached to

const int yellow = 12;      // pin that the LED is attached to
const int green  = 11;
const int red    = 10;

const int threshold1 = 709;
const int threshold2 = threshold1 + 10;
const int threshold3 = threshold2 + 10;

void setup () {
    pinMode (yellow, OUTPUT);
    pinMode (green,  OUTPUT);
    pinMode (red,    OUTPUT);

    Serial.begin (9600);
}


void loop () {
    delay (200);
    int sensorValue = analogRead (A0);
    float voltage = sensorValue * (3.3 / 1023.0);
    Serial.println (sensorValue);

    if (sensorValue > threshold3) {
        digitalWrite (yellow, LOW);     // LOW == ON
        digitalWrite (green,  LOW);
        digitalWrite (red,    LOW);
    }

    else if (sensorValue > threshold2) {
        digitalWrite (yellow, HIGH);
        digitalWrite (green,  LOW);
        digitalWrite (red,    LOW);
    }

    else if (sensorValue > threshold1) {
        digitalWrite (yellow, HIGH);
        digitalWrite (green,  HIGH);
        digitalWrite (red,    LOW);
    }

    else  {
        digitalWrite (yellow, HIGH);
        digitalWrite (green,  HIGH);
        digitalWrite (red,    HIGH);
    }
}

No don't do that, it will burn out your Arduino.

How should I do it than?

I have changed the code to your liking but the main problem is still there I cant lower treshold1 even tho I would like to do that.

You have not explained exactly what you want the sketch to do. Are you turning the motor by hand and trying to measure its output voltage, for instance ?

If not, then what are you trying to do ?

See @UKHeliBob post #9

So the motor has a windmil on it the way te code is written now the red light is on until there is enought (specificated in threshold1) wind to turn on yellow than green and at last if there is too much wind the red one starts blincking. I'd like to lower the value of threshold1 but doing that destroys all the code and just permenantly lights up green and yellow
These are the reeding I'am getting:

those are the values I'm getting ^^^^^

looks like your thresholds should be 680 and 750 base on value in post #11

I want my thrashole to be 680 but if I set it to that the LED doesn't automaticaly turn off whene the motor stops spinning. And we come back to the start HOW DO I FIX THAT???

isn't that covered by the final else condition in the code i posted that turns off all the LEDS?
does HIGH turn the LEDs OFF or ON.

high turns LED's on

then the else condition should set the LEDs LOW

The final condition does not solve that as soon as the yellow LED is on and the motor stops spinning it does not turn off. Whene the yellow LED is on the reading does not drop bellow 695 even tho the motor stopped spinning therefor with this code I have to use threshold at atleast 696 and I need the solution to get that to 680

why does it matter what the LEDs are doing?

are you saying that the measured value > 600 even when the motor is stopped?

what exactly are you measuring, a voltage applied to a motor or the voltage (BEMF) generated by a motor when it is spun by some other means?

I wonder if that is because the OP said back in post #1:

I'm not a motors expert by any means, but I would have thought that the motor would go between 0V and A0 - all assuming that the motor doesn't generate a voltage exceeding the max voltage on a pin and damage the chip.