I am very sorry to bother you. I have tried to search the answer to what must be a very simple problem but have had no luck.
Obviously I am new to Arduino and have little understanding of it. I am learning but very slowly.
I have a set of traffic lights. I can do the lesson and work the leds on the breadboard.
My traffic lights I have for my model railway though have the polarity around the opposite way.
The common wire is positive. The red, amber and green are negative.
I think my question is, can I get the negative to come through the digital (pwm)?
I know it must be a silly question.
Easy.
In your original sketch, you set the PWM value in the range 0-255
— to invert the polarity, simply use 255-{your originalPWMvalue}
Thanks very much lastchancename. I appreciate your quick reply.
I have not set a PWM in my sketch. Below is my sketch.
The lights have 4 wires. One common that must be powered by a positive current, and the three others that when connected to the negative of a battery light. I believe that the only way to do this is to reverse the output on the Arduino but it seems very strange.
I tried a set of railway control lights and they work the same. A common wire is connected to the + and - to the different coloured LEDs.
int red=10;
int yellow=9;
int green=8;
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
changeLights();
delay(5000);
}
void changeLights(){
//green off, yellow on
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay (3000);
//turn off yellow, then turn on red
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(22000);
// Turn red off and green on
digitalWrite(red, LOW);
delay (500);
digitalWrite(green, HIGH);
delay (20000);
}
Not strange, perfectly normal. Just follow the path of the current.
Positive power supply - common pin - LED - specific LED pin - Arduino pin - GND.
Arduino pins can sink (set to LOW) and source (set to HIGH) current. It may be easier to imagine this as "connection to GND" resp. "connection to +5V".
In your case your LEDs are on when set LOW, off when set HIGH. Beginners often find this odd but you'll quickly get used to it. Low side switching (which is what you're basically doing here) is actually more common than high side switching.
Thanks very much wvmarle. Most of that goes completely over my head
Maybe a schematic will help. It sounds like your circuit would be R10-D9, one output per LED, at the top, just left of center.
I use similar traffic lights for our layout.
I put the common wire to the 5v pin on the arduino (with a current limiting resistor between) and then each of the 3 wires for the 3 LEDs go to an output pin on the arduino. Setting the pin high turns off the light. Setting the pin low turns on the light.
Thank you VinceHerman, you have me motivated ! There are lights changing and you have me on the right track. I think it will be downhill (easy) from here.
Thanks very much.
Cool! Now post some pics. Even if it is just a work in progress and no, I don't care if your layout is not complete. Pics of projects are always a good idea. And especially so if it involves railway layouts!
Just curious...
In the OP, without showing code, you ask “”my question is, can I get the negative to come through the digital (pwm)? ””
What happened there?
You later said you’re not using PWM...! “”I have not set a PWM in my sketch”” ??!
Not to complicate it but it's also possible to invert the signal using a switching transistor.
wolframore:
Not to complicate it but it's also possible to invert the signal using a switching transistor.
From my reading of the datasheet one can also invert the output by manipulating bits in the Timer Counter Control Register.
Thanks vinceherman. One step closer! I really appreciate your help and people like yourself. I couldn’t do it without you all. Here is a video of a welding scene and the start of the traffic lights.
Cheers
Thanks vinceherman. I have it working with a mega but having troubles getting a nano to work.
I have also got two speedometers and a welding light working. I am having alot of trouble using Nanos.
Thanks for your help.
richardvanraay:
The common wire is positive. The red, amber and green are negative.
You could feed the common wire PWM (+) and make the pins for the colors you want OUTPUT LOW, HIGH for the ones you don't want lit.
But why bother with PWM? Why not just use resistors on the color lines?
Soon reply #1 will make sense...
richardvanraay:
Thanks vinceherman. I have it working with a mega but having troubles getting a nano to work.
I have also got two speedometers and a welding light working. I am having alot of trouble using Nanos.
Thanks for your help.
The pic of your layout looks great! That is some really good work!
What is the trouble with the Nanos?
GoForSmoke:
But why bother with PWM? Why not just use resistors on the color lines?
This seems to be adding to the total confusion here (not entirely unusual! ).
PWM and current limiting resistors are not alternatives, they are entirely different matters.
Current limiting resistors are required to control the current through the LEDs. Apparently these lights are in fact LEDs (otherwise the polarity would be irrelevant); we need to know their specifications in order to discuss the matter. It is somewhat unlikely that they incorporate current limiting resistors in such a small assembly so we need to know from the original product description, how they are supposed to be used.
PWM is used to vary brightness. This is a most improbable requirement on a model railway as traffic lights and railway signals in real life do not vary. The brightness is pre-set by the resistors. I suspect the OP is not really aware of what PWM is by the sound of it.
The video never got posted, so I have no idea what a "welding scene" or "welding light" might be but certainly an Arduino (Nanos are most suitable) can generate an excellent simulation of welding in miniature, with the right code.
We simply need a circuit schematic to sort out any further matters. And a full citation of the traffic lights from the vendor.
Paul__B:
PWM and current limiting resistors are not alternatives, they are entirely different matters.Current limiting resistors are required to control the current through the LEDs. Apparently these lights are in fact LEDs (otherwise the polarity would be irrelevant); we need to know their specifications in order to discuss the matter. It is somewhat unlikely that they incorporate current limiting resistors in such a small assembly so we need to know from the original product description, how they are supposed to be used.
PWM is used to vary brightness. This is a most improbable requirement on a model railway as traffic lights and railway signals in real life do not vary. The brightness is pre-set by the resistors. I suspect the OP is not really aware of what PWM is by the sound of it.
No freaking DUH to all of that. PWM was brought up and I pointed out that YES it can be used but WHY use it when it's not needed?
Putting the resistor(s) in the product would limit use to a narrow voltage range.
GoForSmoke:
Putting the resistor(s) in the product would limit use to a narrow voltage range.
You may recall when the currency in model railway systems was "grain of wheat" bulbs.
They most certainly had a narrow voltage range. A (modern) LED with a resistor sized for (20 mA at) 12 V will work quite well at 5 V.
The problem is that the discussion has tried to advance without adequate - indeed any genuine specification of the parts in question.
GoForSmoke:
But why bother with PWM? Why not just use resistors on the color lines?
Your sentence looks to me as if it is comparing PWM and resistors.