Need help with this code

What is wrong?

#include <LiquidCrystal.h>

// built in arduino library
#include <liquidcrystal.h></liquidcrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int motorPin = 9;
void setup()
{
pinMode (motorPin, OUTPUT); // make pin 9 an output pin

lcd.begin(16, 2);
// clear old screen data
lcd.clear();
// text to be dispalyed on the screen
lcd.print(“Vibro”);

}
void loop()
{
lcd.begin(16, 2);
// clear old screen data
lcd.clear();
// text to be dispalyed on the screen
lcd.print(“Vibro”);

int speed = map(analogRead(A0), 0, 1024, 0, 255); // map the potentiometer to the range of the motor speed

analogWrite (motorPin, speed);

int voltage = speed/2554.5;
float motorSpeed = voltage
140/4.5; // calculating motor speed, 140 rpm for 4.5V

// (column 0) of the second line (line 1):
lcd.setCursor(0,1);
lcd.print (“Speed is:”);

char myStg[10];
sprintf(myStg, “%d”, motorSpeed);
for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg*);="" } <="" p=""></strlen(mystg);>*

  • lcd.setCursor (13,1);*
  • lcd.print (“RPM”);*
  • delay(100);*
    }

I give up. What is wrong? Is this a multiple answer question?

I suggest one thing wrong is the way you posted the program on the forum.

Paul

What is wrong?

You didn’t read this before posting a programming question hence some of your code appears to be in italics and you have given no indication of what the program should do and the problems that you are having.

Start by putting code tags around your code in your post then tell us what is wrong

#include <liquidcrystal.h></liquidcrystal.h>

This looks wrong for a start (note the use of code tags)

I'm guessing that your program either doesn't compile or it doesn't load or if it loads it doesn't do what you want it to.

If you tell us which of those it is and post (in full) any error messages you get and/or describe (in detail) what happens and what should happen that's different...then we may be able to help.

Steve

I want to use this code to control a dc engine with a potentiometer and be able to see the speed of the LCD screen. this is the error code.

Arduino:1.8.5 (Windows 10), Kort:“Arduino Nano, ATmega328P”

C:\Users\robin\Documents\Arduino\vibrator_matare\vibrator_matare.ino: In function ‘void loop()’:

vibrator_matare:39: error: ‘mystg’ was not declared in this scope

for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg*);="" } <="" p=""></strlen(mystg);>*

  • ^*
    vibrator_matare:39: error: expected primary-expression before ‘=’ token
    _ for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg*);="" } <="" p=""></strlen(mystg);>_
    _
    ^_
    vibrator_matare:39: error: assignment of read-only location ‘""’
    _ for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg);="" } <="" p=""></strlen(mystg);>
    ^
    vibrator_matare:39: error: invalid array assignment
    vibrator_matare:39: error: expected primary-expression before ‘<=’ token
    for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg);="" } <="" p=""></strlen(mystg);>
    ^
    vibrator_matare:39: error: expected primary-expression before ‘>’ token
    for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg);="" } <="" p=""></strlen(mystg);>
    ^
    exit status 1
    ‘mystg’ was not declared in this scope*

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File → Preferences._

for(int i=0; i<strlen(mystg); i++)=""  ="" {="" lcd.print(mystg);="" } <="" p=""></strlen(mystg);>Can you explain what this line of code is supposed to do and how ?

Note how it has been put into code tags

I am completely new to programming. I have tried to copy this.

Or can anyone recommend another project I can use that is similar?

I_surf:
Or can anyone recommend another project I can use that is similar?

This will sound radical, but have you considered writing it yourself ?

What exactly are you trying to do ?

If I had the knowledge, I would have written it myself. As I wrote earlier, I am completely new to this. I’m going to build a vibrator feeder for fine powder. The DC engine I will use as a vibrator motor.

I am completely new to this

We all had to start somewhere

It sounds like you want to control the speed of a motor using a potentiometer. Is that about it ?

If you are willing to pay someone to write this then please post a request in the Gigs and Collaborations section of this forum.

Yes, I want to control the speed with a potentiometer and see the speed in the LCD screen. I want to use this code

What's wrong with the code? I can not make it work with my Arduino nano ATmega 328P

I_surf:
Yes, I want to control the speed with a potentiometer and see the speed in the LCD screen. I want to use this code
https://www.instructables.com/id/Motor-LCD-Arduino-Motor-Speed-Controller-With-Spee/

What’s wrong with the code? I can not make it work with my Arduino nano ATmega 328P

The glaring errors are in this line
for(int i=0; i<strlen(mystg); i++)=""  ="" {="" lcd.print(mystg);="" } <="" p=""></strlen(mystg);>but there are others.

Where did you get the code from ?

Was my guess as to your goal in reply #10 correct ?

How should the code be written instead?
I got the code from this website

It looks like something got badly mangled, and you managed to copy part of the HTML.

CtrlAltElite:
It looks like something got badly mangled, and you managed to copy part of the HTML.

Nope !

That line
for(int i=0; i<strlen(mystg); i++)=""  ="" {="" lcd.print(mystg[i]);="" } <="" p=""></strlen(mystg);>is in the code on the page linked to

Looks like the page is corrupted in someway. The code below compiles. No guarantee it works correctly.

//built in arduino Library.
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
const int motorPin=9;
void setup()
{
  pinMode(motorPin,OUTPUT);//make pin 9 an output pin

lcd.begin(16,2);
//clear old screen data
lcd.clear();
//text to be displayed on the screen
lcd.print("UnicornClockworks");
}
void loop()
{
lcd.begin(16,2);
//clear old screen data
lcd.clear();
//text to be displayed on the screen
lcd.print("UnicornClockworks");

int speed = map(analogRead(A0),0,1024,0,255);//map the potentiometer to the range of the motor speed
analogWrite (motorPin,speed);
int voltage = speed/255*4.5;
float motorSpeed=voltage*140/4.5; //calculating motor speed, 140 rpm for 4.5v
//(column 0) of the second line (line 1)
lcd.setCursor(0,1);
lcd.print("Speed is:");

char myStg[10];
sprintf(myStg,"%d",motorSpeed);
for(int i=0;i<strlen(myStg);i++)
{
lcd.print(myStg[i]);
}
lcd.setCursor(13,1);
lcd.print("RPM");  
delay(100);
}

G

If that works then we can set about improving it.

For instance

  char myStg[10];
  sprintf(myStg, "%d", motorSpeed);
  for (int i = 0; i < strlen(myStg); i++)
  {
    lcd.print(myStg[i]);
  }

could be replace by

  lcd.print(motorSpeed);

There are also several other improvements that could be made.

As a matter of interest, how is the motor powered ?

Thank you so much for all the help!
Everything seems to work now besides a problem I can not read the speed of the LCD screen?
what other improvements to the code do you think I’m going to do?

//built in arduino Library.
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
const int motorPin=9;
void setup()
{
  pinMode(motorPin,OUTPUT);//make pin 9 an output pin

lcd.begin(16,2);
//clear old screen data
lcd.clear();
//text to be displayed on the screen
lcd.print("Vibro motor");
}
void loop()
{
lcd.begin(16,2);
//clear old screen data
lcd.clear();
//text to be displayed on the screen
lcd.print("Vibro motor");

int speed = map(analogRead(A0),0,1024,0,255);//map the potentiometer to the range of the motor speed
analogWrite (motorPin,speed);
int voltage = speed/255*4;
float motorSpeed=voltage*140/4; //calculating motor speed, 140 rpm for 4v
//(column 0) of the second line (line 1)
lcd.setCursor(0,1);
lcd.print("Speed is:");

char myStg[10];
sprintf(myStg, "%d", motorSpeed);
for (int i = 0; i <strlen(myStg); i++)
{
 lcd.print(myStg[i]);
}
lcd.setCursor(13,1);
lcd.print("RPM");  
delay(100);
}

I can not read the speed of the LCD screen?

I am not sure what you mean by this

As to improvements, what happens if you simply position the cursor and print motorSpeed ? Do you actually need to turn it into a string using sprintf() then print each character separately ?