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
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 ?
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:
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???
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
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.