I just got a light and I’m attempting to turn the light on and off with a potentiometer, I followed the example code here.
I added a potentiometer and the light is not turning on. Just to be sure my light is connected to a 14.8V battery that is fully charged, so red to red and back to black. When I touch the yellow wire to the red wire my light turns on at full power. The lights yellow wire is in pin 9. I also tested my potentiometer and am getting accurate readings on that. My code is below, if someone could look over it and tell me what I might be doing wrong that would be awesome, thanks!
#include <Servo.h>
byte poteniometerPin = A0;
byte servoPin = 9;
Servo servo;
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
servo.writeMicroseconds(1100); // send "off" signal to Lumen light
}
void loop() {
int potVal = analogRead(poteniometerPin);
int pwmVal = map(potVal, 0, 1023, 1100, 1900);
servo.writeMicroseconds(pwmVal); // Send signal to Lumen light
}
Nothing looks obviously wrong to me here, although it’s not clear why you’re beginning Serial communication without making use of it.
Ideally programs are created one step at a time, with the functionality verified before each new step gets added. Once you have a program that’s not working the first step of debugging is generally to break down the functionality into what’s new, and how each part of that is expected to behave.
To start with, have you confirmed that the servo functionality is working as expected, without the potentiometer (e.g. just directly running the example you linked to, and seeing whether the Lumen lights up at partial strength, and potentially stepping through the PWM range with some delays in between)?
If that’s working fine then you can try independently testing the analog reading and/or the mapping parts by sending those values to your programming computer over serial.
If the servo output, light, and analog reading are working fine independently but not all together then there may be some kind of interference between them and/or other components of your program (e.g. depending on your Arduino board the Serial and servo functionality could potentially share a clock signal, which may result in unexpected behaviour).
Please follow up if any of those steps help, or any unexpected results you run into while trying them