Hello.
I am a certified electrician and wanted to learn more about controlling signal for various purposes, and mostly to code.
My DC motor is connected to its own 9V circuit, I use a potensiometer for controlling the current to the motor.
Now this works all dandy on its own.
However, when I upload my code WITH these four last lines of code;
-
lcd.print(voltage);*
-
lcd.print (" V");*
-
lcd.print(prosent);*
-
lcd.print(" %");*
the motor simply does not rotate when given current through the potensiometer.
However, the LCD screen is not displaying anything. I have set it up on its own circuit with a simple sketch to check the screen was functioning properly.
I am very new to the coding aspect of this, any help is greatly appriciated.
#include <LiquidCrystal.h>
// Motor Control Integers
int pwmPin = 6;
int pot = A0;
int c1 = 0;
int c2 = 0;
// LCD Integers
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int prosentin = A3;
int prosent = 0;
const int voltagein = A5;
void setup() {
// Motor Control
pinMode(pwmPin, OUTPUT);
pinMode(pot, INPUT);
// LCD Screen
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(voltagein, INPUT);
pinMode(prosentin, INPUT);
}
void loop() {
// Motor Control
c2= analogRead(pot);
c1= 1024-c2;
digitalWrite(pwmPin, HIGH);
delayMicroseconds(c1);
digitalWrite(pwmPin, LOW);
delayMicroseconds(c2);
// LCD Screen
lcd.setCursor(0, 1);
int voltageVal = analogRead(voltagein);
float voltage = (voltageVal/1024.0) * 5.0;
int prosentVal = analogRead(prosentin);
prosent = map(prosentVal, 0, 1024, 0, 255);
lcd.print(voltage);
lcd.print (" V");
lcd.print(prosent);
lcd.print(" %");
}