Can you help me in my code please

Hi, i am new to arduino and trying to connect an arduino UNO to a DC motor.
this is my code:

void setup() {
pinMode(A2, OUTPUT);
}

void loop() {
analogWrite(A2, 306);
analogRead(A2);
delay(1000);
analogWrite(A2, 0);
analogRead(A2);
}
it dosnt do anything when i upload it to the arduino using a USB

is it possible to send 6v in arduino uno?
thank you for the help!

check you are using a pin that works with analogwrite
also use code tags

You will need a motor driver. The Arduino can't power a motor directly.

More members will see your code if posted properly. Read the forum guidelines. to see how to properly post code.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post a schematic. Hand drawn, photographed and posted is OK.

Post data sheets or links to where you bought the motor and motor driver.

A2 does not support PWM. Look at the Arduino pinout. Pins preceded by ~ support PWM.

An Arduino UNO is only 5V.

Then you need to understand that an Arduino cannot connect directly to a motor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.