So I’m very new to arduino and programming and basically have just been piecing together parts of code to get where I am so far. So please be patient in my ignorance. So far I have everything working but I’m trying to refine it a little further, which is where I’m getting stuck.
What I’m trying to accomplish is to use an UNO and two potentiometers to independently control the ON and OFF time of a pulsing DC motor. I would like to use an LCD to display to show what the ON and OFF times are. Right now I have all that working. What I would like to refine more is the updating of the values on the LCD. Right now the LCD only updates the values after the code ends and the start of the loop begins again. So if I’m making an adjustment I have no idea what I’m adjusting the value to, unless I press reset immediately after or until the code loop ends and restarts or pressing (which can be awhile as I plan to adjust the code to allow for up to 5 mins of ON or OFF time). What I would like is for the LCD to update “live” as I adjust the potentiometers.
You’ll also see some switches on the LCD to turn off the screen and the backlight (I know, not the best solution as I have to press reset to bring back the LCD after cutting power to the VCC terminal). Is there a way to eliminate the switches and have the LCD “wake up” after one of the potentiometers changes value? Then turn back off after 5 seconds? Just trying to save power to maximize battery life.
Please feel free to point out my mistake in the circuit or programming, like I said I’m new to Arduino and my only programming experience is with GCode which is unrelated.
Thanks for the help, my code is below, attached is a diagram and schematic
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set LCD driver pins
int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10
int sensorPin = 0; // The potentiometer is connected to analog pin 0
int gatePin = 13; // The MOSFET GATE is connected to digital pin 13
void setup()
{
lcd.begin(16,2); // set LCD as a 16 column, 2 row display
digitalWrite(lcdbl, HIGH); //turn on LCD backlight
pinMode(lcdbl, OUTPUT); // set pin 11 to output
pinMode(gatePin, OUTPUT); //set MOSFET GATE pin to output
lcd.print("Motor Control"); //display text
delay(5000);
lcd.clear();
}
void loop()
{
int sensorValueon = analogRead(A0); // read the ON input on analog pin A0:
int sensorValueoff = analogRead(A1); // read the OFF input on analog pin A1:
float secondson = sensorValueon/204.6; //convert sensorValueon to seconds (1023/delay(sensorValueon multiplication factor)
float secondsoff = sensorValueoff/204.6; //convert sensorValueoff to seconds(1023/delay(sensorValueoff multiplication factor)
lcd.print(secondson); //display ON time value on display
lcd.setCursor(8,0); //move cursor to column 8 on top row
lcd.print("ON Sec."); //display ON Sec. behind value
lcd.setCursor(0,1); //move cursor to the first column on bottom row
lcd.print(secondsoff); //display OFF time value on display
lcd.setCursor(8,1); //move cursor to column 8 on bottom row
lcd.print("OFF Sec."); //display OFF Sec. behind value
digitalWrite(gatePin, HIGH); // Turn the LED on
delay(sensorValueon*5); // Pause for sensorValueon seconds(multiplication factor = MAX On time)(recalculate float secondson when changing value here)
digitalWrite(gatePin, LOW); // Turn the LED off
delay(sensorValueoff*5); // Pause for sensorValueoff seconds(multiplication factor = MAX OFF time)(recalculate float secondsoff when changing value here)
lcd.clear();
}