I am working off of this code, and I got the initial code to work perfectly. However, I am trying to control 2 LEDs ,independently and simultaneously , with separate potentiometers. I used the same resistors, LEDs, and potentiometers as this website. do I need to create a seperate loop function to achieve this goal? Lesson 11: Arduino Circuit to Dim LED with Potentiometer | Technology Tutorials
int potPin= A0; //Declare potPin to be analog pin A0
int potPin1 = A1;
int LEDPin= 9; // Declare LEDPin to be arduino pin 9
int LEDPin2= 10;
int readValue; // Use this variable to read Potentiometer
int readValue1;
int writeValue; // Use this variable for writing to LED
int writeValue1;
void setup() {
pinMode(potPin, INPUT); //set potPin to be an input
pinMode(potPin1, INPUT);
pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT
pinMode(LEDPin1, OUTPUT);
Serial.begin(9600); // turn on Serial Port
}
void loop() {
readValue = analogRead(potPin); //Read the voltage on the Potentiometer
readValue1 = analogRead(potPin1);
writeValue = (255./1023.) * readValue;
writeValue1 = (255./1023.) * readValue1;
analogWrite(LEDPin, writeValue); //Write to the LED
analogWrite(LEDPin1, writeValue1);
Serial.print("You are writing a value of "); //for debugging print your values
Serial.println(writeValue);
Serial.println(writeValue1);
i updated it and it worked great. My next question is, Instead of LED bulbs, What if I put in a 12V-600RPM motor in place of each LED. What size resistor will I need(compared to the 220ohm), what type of power supply? can I use the same potentiometer/ slope formula?
i updated it and it worked great. My next question is, Instead of LED bulbs, What if I put in a 12V-600RPM motor in place of each LED. What size resistor will I need(compared to the 220ohm), what type of power supply? can I use the same potentiometer/ slope formula?
if you are using an arduino just to generate a PWM, seem a bit overkill to me. if not, the circuit on that link should give you an idea of what additional parts you would require.
You will need more than just a resistor. What kind of motor? Brushless, brushed?
For a brushed DC motor, the motor will need a driver and separate power supply. The type of driver depends on if the motor needs to be reversible. If only one direction of rotation is required, a logic level MOSFET driver with flyback diode could be used. If you want to run the motor in both directions use a H bridge. You will need to know the stall (starting) current of the motor(s) to be able to pick a driver of either kind. The stall current should be listed on the motor data sheet or you can estimate the stall current using the measured coil resistance and the rated voltage. Stall current = rated voltage / coil resistance. The driver must be able to supply the stall current and the power supply must be able to supply the stall current times the number of motors (or, at least, times the number of motors that might start at the same time).
Your program could stay much the same to control the motors speeds, though if you want direction control you will have to add it.
I am using DC Brushed Motors 12V-600 RPM. I do not necessarily want direction control. I only want to control the speed(in forward/acceleration). Therefore, I think the motors should be directly replaceable with the LED lights. Although, Maybe some differences with potentiometers, resistors, (and/or) power. I am wrong? why?
The LEDs are powered directly by the digital pins which can only supply limited current. LED current of around 20mA is fine. Your motors will need A LOT more current than that, more than enough to damage the Arduino.
I'm certain you've been told this several times before. If you don't want to take our advice just give it a try. And then go and buy yourself a new Arduino.
slipstick:
The LEDs are powered directly by the digital pins which can only supply limited current. LED current of around 20mA is fine. Your motors will need A LOT more current than that, more than enough to damage the Arduino.
I'm certain you've been told this several times before. If you don't want to take our advice just give it a try. And then go and buy yourself a new Arduino.
Steve
So are you suggesting that it is not possible to use a twelve volt motor with an aruduino at all? I have dual H-bridges as well. Your advice here is telling me I'm wrong. Not steps to get on the right track. Steve, I would appreciate some guidance here.
BullEngineer:
So are you suggesting that it is not possible to use a twelve volt motor with an aruduino at all? I have dual H-bridges as well. Your advice here is telling me I'm wrong. Not steps to get on the right track. Steve, I would appreciate some guidance here.
Thanks in advance,
Bull Engineer
YES YOU ARE WRONG. you DEFINITELY need a H-bridge for bidirectional motor control
for monodirectional, both me and @GroundFungus have provided you with hardware advice! it should be enough to get you going.
It is unrealistic to expect us to write a complete tutorial for every question that comes up. Especially since, in this case, there must be hundreds (or thousands) of pages dedicated to using the L298 motor driver with Arduino on the net.
Since the stall current of the motor is not listed in the ad I would have to guess if the L298 driver is capable of driving that motor and the engineer in me hates to guess. The driver must be able to supply the stall current every time the motor starts.
My advice is to find out the stall current of the motor that you want to use and choose a motor driver that will handle that current at the motor supply voltage. Also, if you are going to buy a driver, use a more modern driver like the ones that Pololu offers.. The ancient L298 drivers, while plentiful and cheap, are crap motor drivers compared with the modern drivers.
BullEngineer:
I was told arduino wouldnt work by other people, i have seen this article. However, I am trying to control 1 motor by each H-bridge.
BullEngineer:
slip stick
Am I correct to guess this is what you are referring to?
slipstick:
The LEDs are powered directly by the digital pins which can only supply limited current. LED current of around 20mA is fine. Your motors will need A LOT more current than that, more than enough to damage the Arduino.
I'm certain you've been told this several times before. If you don't want to take our advice just give it a try. And then go and buy yourself a new Arduino.
if Yes, CLEARLY you did not get his point...
BullEngineer:
Just google everything? great advice man
Well thank you. I do that myself, and if I'm still stumped, I try to get help from the the great minds here!