Step control with potentiometer.


I am studying Arduino and is still a beginner. Please help in the development. rew the scheme here using the Fritzing program.

I th

Fritzing itself issues the firmware code after the reset is completed (as I understand it)

That’s all it takes to verify the correctness of this code.

Could you verify the correctness of such code?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // adress and format LCD

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
lcd.init(); // init LCD
lcd.setCursor(5, 0); // place static text
lcd.print("ADC = ");
lcd.setCursor(15, 0);
lcd.setCursor(0, 1);
lcd.print(“LED : “);
lcd.setCursor(12, 1);
Serial.begin(9600); // optional serial monitor

void loop() {
int sensorValue = analogRead(analogInPin); // read analog A0 en store in sensorValue
float voltValue = 5.0 / 1024.0 * sensorValue; // calculate volt at analog A0 and store in voltValue
float percentValue = sensorValue / 1024.0 * 100.0; // calculate percentage analog A0 and store in percentValue
outputValue = map(sensorValue, 0, 1023, 0, 255); // map analog input to analog output and store in outputValue
analogWrite(analogOutPin, outputValue); // write outputValue to analogOutPin

lcd.setCursor(0, 0); // set cursor at deserid position
leadingZeros(sensorValue, 4); // print sensorvalue with number of leading-characters (0 or space as specified in function leadingZeros)
lcd.setCursor(10, 0); // set cursor at deserid position
lcd.print(voltValue); // print voltValue
lcd.setCursor(6, 1); // set cursor at deserid position
lcd.print(percentValue); // print percentValue

Serial.print(“sensor = " ); // print the results to the serial monitor:
Serial.print(”\t output = “);
Serial.print(”\t procent = ");

delay(1000); // set delay

void leadingZeros( int value, int width) { // display result with leading characters
char valueStr[6]; // large enough to hold an int
itoa (value, valueStr, 10); // itoa converts int to string
int len = strlen(valueStr); // calculate length of valueStr
if (len < width) {
len = width - len;
while (len–)
lcd.print(’ '); // for leading zeros place ‘0’ between (), for leading spaces place ’ ’ between ()

Welcome aboard! From you comments I assume you are trying to load the code in to the Arduino from Fritzing. I used to say that the code download for Arduino doesn’t work, but with later revisions of the Arduino IDE some folks have gotten it to work (but on Linux.) So I would suggest that you copy the code for blink (that flashes a led when loaded successfully) in to Fritzing, try loading that to the Arduino and make sure the LED blinks to make sure the Fritzing code load is working. Alternately try downloading the code via the Arduino IDE which will probably give you better diagnostics if something goes wrong. I assume your code isn’t working when loaded from Fritzing?


Good The picture shows a diagram and this diagram must be put into practice. But doesn’t fritzing reproduce the code?

Fritzing will not compile the code, it needs the Arduino IDE for that (the code tab in Fritzing calls the Arduino IDE to do the work.) So if you don’t have the Arduino IDE available this won’t work. As noted it used to be that downloading the code to the Arduino also didn’t work because the functionality was not in the Arduino IDE at the time. With the latest Arduino IDE it may or may not work, you need to test with a code like blink to see if it will work.