I am trying to control the CW and CCW rotation of a brushed DC motor with a relay (datasheet found here.)
My problem is that my measured voltage never drops to zero, causing the relay to swap directions. It's at either 6.2 or 1.5 as you will see in pictures below.
This project is to control a dc motor which in turn opens and closes a window.
The circuit control is a slide potentiometer whose range is divided into 3 parts. All the way to the left = start opening window (mapped POT value between 10 - 333), all the way to the right = start closing window (mapped POT value 666 - 989), otherwise set both to low (no movement).
I'm also using the mapped POT value to control the interval between the builtin LED flashes. If you want to learn more about that you can click here.
I put a video on youtube of how the Node MCU is flashing and the serial output.
https://youtu.be/uweEY3No0pg
Below is my circuit diagram and where you see the 2 red stars is where I placed my multimeter prongs to get the 1.5V and 6.2V readings in the pictures below the diagram. and you can see the Yellow POT knob is on opposite sides corresponding with what the voltage should be to either rotate CW or CCW.
So my 3 questions are:
- Why is my voltage at 1.5V and not 0V?
- How do I fix it?
- Is there a more reliable, budget friendly Slide POT you can recommend?
1.5V Slide POT Left should be 0V
1.5V Slide POT Center should be 0V
6.2 V Slide POT Right, OK, But other control pin is 1.5V
int closePin = 16;
int openPin = 5;
int mappedPot;
int potValue; // value from the analog pin
const int trigPin = 9;
const int echoPin = 10;
int potPin = A0;
//mapped pot values 0 333 666 999
int startOpen = 334;
int startClose = 665;
// constants won't change. Used here to set a pin number:
const int ledPin = 2; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
// constants won't change:
unsigned long previousMillis = 0;
int interval = 1000; // interval at which to blink (milliseconds)
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
// initialize digital pin 2 as an output.
pinMode(2, OUTPUT);
pinMode(potPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(closePin, OUTPUT);
pinMode(openPin, OUTPUT);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
potValue = analogRead(potPin); // reads the value of the potentiometer (value between 0 and 1023)
mappedPot = map(potValue, 0, 1023, 10, 989);
//pot values 0 333 666 999 -> map to interval lengths 0 <-> 333, 0 , 333 <-> 0
// 666-333
if(mappedPot < startOpen) { // <334
//led will flash faster as POT moves left. no need to modify interval
interval = mappedPot;
digitalWrite(closePin, LOW);
digitalWrite(openPin, HIGH);
} else if(mappedPot > startClose) { // >665
//interval gets longer as POT moves right, but need it to blink faster as moves right
//startclose = 666, so interval needs to be 999 - mappedPot at 666 = 333 and goes to 999 - potValue at 999 = 0
interval = 999 - mappedPot;
digitalWrite(openPin, LOW);
digitalWrite(closePin, HIGH);
} else {
interval = 100000;
digitalWrite(openPin, LOW);
digitalWrite(closePin, LOW);
}
Serial.print("int: ");
Serial.print(interval);
Serial.print(" mappedPot: ");
Serial.println(mappedPot);
// check to see if it's time to blink the LED; that is, if the difference
// between the current time and last time you blinked the LED is bigger than
// the interval at which you want to blink the LED.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}