📜 ⬆️ ⬇️

Flashing LED string for stop light on Arduino Pro Mini

Flashing LED string for stop light on Arduino Mini I just did not want to stick any stickers on the rear window of the car - it’s not known who passes by the car at night and what will be the reaction to the inscription. It was decided to make the inscription LEDs under the rear window. In the inactive time it is not visible at all (tinted glass behind), besides, you can turn it off / on when necessary. Well, a little later the idea came to include the inscription only when the stop signal lights up and make an inscription out of red LEDs - it turns out a simple duplication of the stop signal, but with additional information. All work took 3 pm, that's what happened.

Of course, you can simply buy a running line or a light board and put it under the rear window ... But quickly running through the prices of these devices immediately immediately felt like a little money and it was decided to do everything with your own hands.

First, I decided on the iron - this is the Arduino Pro Mini, which costs $ 4 on eBay. Why precisely she? Because it is quite enough, even in abundance. The LEDs were planned to be connected to the PWM channels so that the brightness of the LEDs could be controlled. The Arduino Mini has only 6 such outputs - quite enough for us. In fact, absolutely any Arduina will be suitable for our task.

Arduino Pro Mini Then I decided on the inscription and broke it into 6 independent sections. This turned out to be even a lot, so I left only 5 active and one channel had planned for “prozapas”. In each section it turned out from 2 to 4 letters, for each letter you need about 10-20 LEDs.
')
As you know, the Arduino output pulls only 40ma, because of this, connecting such a horizon of LEDs directly to the Arduino outputs will not work. To solve the problem, the P16NF06 mosfets were used - powerful field workers, whom I found in the store of 20 pieces. Of course, using mosfets for such a task is a brute force, since They can switch currents up to 1 amp (for example, they pull quietly LED strip of good length). Instead, you can use simple bipolar transistors, which are cheaper. But the mosfets can be connected directly to the Arduino terminals, since they have a high input resistance and for the same reason they do not require a body kit in the form of a resistor (s).

Then I had to select about 130 red LEDs from the stock of 5mm. Unfortunately, I didn’t have that many red LEDs, so I had to make some letters green. As you know, LEDs need to be connected through a resistor to limit the current. It was decided to connect in series of 6 pieces and connect this block of LEDs through a resistor to + 12V. It was calculated and chosen empirically that for 6 LEDs and a supply voltage of 12V, a resistor of approximately 50 Ohms is needed.

The main points of the future device are marked, now let's get down to business.

As a basis for the panel was taken plain cardboard from the old box. Two strips of 80x15 cm were cut out. This size turned out to be optimal for placement under the rear window of the car. Next, the printer printed a text line and selected a font for letters - Calibri, 300 in size. By attaching to the cardboard, the inscription was transferred to a strip. With the help of tweezers holes were made for LEDs. Here it is necessary to take into account that the LEDs are connected in blocks of 6 pieces, so each channel must be connected to a number of LEDs multiple of 6. In principle, this can be circumvented by creating a series of LEDs from any other number and calculating a resistor for connecting them to 12V.

LED panel do it yourself

Also for me it was very important to keep the legs of the LEDs safe and sound, so that you can use them in other designs. Therefore, to connect the legs only slightly bent back and soldered to each other. In short, the construction was assembled and sealed in about 3 hours.

LED panel do it yourself

Arduino Mini is usually sold without legs, so the first thing soldered to her legs. It turns out almost Arduino Nano, but without 3.3V :)

image

Connectors are also soldered onto the breadboard to insert the controller board. Next, the mosfets are soldered so that a single heat sink can be screwed to them (although no heat sink is needed here, since very small currents). The PWM outputs 3, 5, 6, 9, 10, and 11 from the Arduino Mini are soldered to the corresponding inputs of the corresponding mosfets.

image

DC to DC converter Next came the challenge of providing the Arduino Mini with stable power. As you know, from the cigarette lighter car, we have 12V, but this voltage may well be 13 and 14 volts at certain points in the use of the car. The Arduino Mini documentation says that the maximum supply voltage can be no more than 12V, and the forum read that even a small excess can damage the board. Therefore, it was decided to use a separate adjustable DC-DC stabilizer to power the Arduino. It can also be ordered on EBay (costs $ 1), but you can collect it yourself. I have such blocks, so I used ready. Thus, 12V is supplied to a separate stabilizer (or maybe up to 30V), and the output is set to, say, 6V, which are fed to the RAW output of the Arduino Mini. Power LEDs also comes directly from 12V (via mosfets).


As a result of the PCB design in mind, the following arrangement of the elements was obtained:

image

Now it is time to decide on what signal all this will turn on. At first, it was planned to connect the entire device directly parallel to the brake light on the car. But, unfortunately, when the voltage is applied to the Arduino, the controller initializes and lasts for quite a long time> 1 sec. Moreover, immediately after switching on, the Arduino outputs are in the Z state and the Mosfets react to this in a very random way. As a result, after switching on, an arbitrary indication occurs during the entire period of the controller initialization. Of course, with the help of an additional body kit, you can set the initial state of the keys, but this requires more details and time ...

The second option was to connect to the digital input of the Arduino signal from the car's brake light. To do this, it was necessary to lower the voltage on the stoplight lamp to 5V, which, in principle, is not difficult. But this option was also impractical due to the fact that it would have had to unwind the back panel and somehow connect to the stoplight ...

Photoresistor I wanted a very simple solution and it was found! It was decided to use a simple photoresistor connected to the analog input of the Arduino. The photoresistor itself is simply placed in a box with a stoplight. It turns out such a kind of opto-couple :) This solution allows you not to intervene in the electric car. True, this is only possible when the brake light is in the cabin under the glass and you can push our photoresistor to it. In short, I have such access, so I did just that.

Moreover, the option with a photoresistor made it possible to solve one more problem - the brightness of the glow depending on the ambient light. Using the photoresistor, you can roughly estimate the illumination on the street and turn on the backlight brighter in the daytime and darker at night. I took this into account in the program, although in practice it turned out that even at night LEDs are far from blind behind riding drivers.

The photoresistor is connected to the output of A0 and to + 5V. A resistor of 10 kΩ from A0 to ground is also required. The type of photoresistor and the value of the resistor in the divider affect the constants that will be specified in the program (they can be selected experimentally).

As a result, such a fee was obtained:

image

FTDI Basic Now we will start the most favorite occupation - programming. In order to fill the program in the Arduino Pro Mini, we need a USB Serial converter. I use FTDI Basic for this purpose, which can also be purchased on eBay.

This is how the Arduino Pro Mini should look like before starting the firmware:

Arduino Pro Mini Firmware

To do this, load the Arduino development environment. If everything is set correctly for you, then the COM port should appear in the Service / Serial Port menu. If it is not there, then you need to install the appropriate driver from the drivers folder of the platform itself.

After selecting the port, you must select the Service / Card / Arduino Mini. Unfortunately, it is not so simple. Depending on the version of the bootloader, you may not be able to write a program to the controller. If after compilation an error of the type will be issued

stk500_getsync(): not in sync: resp=0x00

, then most likely the COM port speed of the development environment does not match the same parameter specified in the bootloader. To fix this, it is recommended:

  1. Select Service / Board / Arduino Nano. This usually helps, but if it doesn't work, then see the next paragraph.
  2. In the folder of the development environment we find the file "\ hardware \ arduino \ avr \ boards.txt". In this file we find the section “mini.name = Arduino Mini” and further the parameter “menu.cpu.mini.atmega328.upload.speed = 57600”. Here we are trying to change the value 57600 (you may have something else) to others. All possible values ​​of speeds can be found in the monitor: the menu Service / Port Monitor and here the choice is in the lower right corner. Before testing, you need to overload the development environment.


The program itself is hidden here.
 #define pinZA 3 #define pinNA 5 #define pinVAL 6 #define pinNO 9 #define pinGO 10 #define pinEMPTY 11 #define pinSTOPSIGNAL 0 #define sensValue 900 //  .  0-1024 #define sensNight 200 //    ,    .  0-1024 #define lightDay 255 //  .  0-255 #define lightNight 150 //  .  0-255 int currentMaxValueLight = 255; void setup() { Serial.begin(9600); pinMode(pinZA, OUTPUT); pinMode(pinNA, OUTPUT); pinMode(pinVAL, OUTPUT); pinMode(pinNO, OUTPUT); pinMode(pinGO, OUTPUT); setAll(0); } int currentEffect = 1; int maxEffects = 2; //     void loop() { if(checkState()){ switch(currentEffect){ case 1: //  1 effect_1(); delayWithStateCheck(2000); effect_off(); break; case 2: //  2 effect_2(); delayWithStateCheck(2000); effect_off(); break; case 3: //  3...  . // ................... break; } currentEffect++; if(currentEffect > maxEffects){ //   ,    currentEffect = 1; } } } void effect_2(){ for(int i=0; i <= 1; i++){ fade(pinZA, 3, true); fade(pinNA, 3, true); fade(pinVAL, 3, true); fade(pinNO, 3, true); fade(pinGO, 3, true); fade(pinZA, 3, false); fade(pinNA, 3, false); fade(pinVAL, 3, false); fade(pinNO, 3, false); fade(pinGO, 3, false); fade(pinGO, 3, true); fade(pinNO, 3, true); fade(pinVAL, 3, true); fade(pinNA, 3, true); fade(pinZA, 3, true); fade(pinGO, 3, false); fade(pinNO, 3, false); fade(pinVAL, 3, false); fade(pinNA, 3, false); fade(pinZA, 3, false); } setAll(currentMaxValueLight); delayWithStateCheck(200); setAll(0); delayWithStateCheck(100); setAll(currentMaxValueLight); delayWithStateCheck(200); } void effect_1(){ fade(pinZA, 10, true); fade(pinNA, 10, true); fade(pinVAL, 10, true); fade(pinNO, 10, true); fade(pinGO, 10, true); fade(pinGO, 3, false); fade(pinGO, 3, true); fade(pinGO, 3, false); fade(pinGO, 3, true); } void effect_off(){ fade(pinGO, 3, false); fade(pinNO, 3, false); fade(pinVAL, 3, false); fade(pinNA, 3, false); fade(pinZA, 3, false); } void fade(int pin, int d, boolean side){ // /   fade if(side){ for(int value = 0 ; value <= currentMaxValueLight; value+=5){ if(!checkState()) break; analogWrite(pin, value); delay(d); } }else{ for(int value = currentMaxValueLight; value >=0; value-=5){ if(!checkState()) break; analogWrite(pin, value); delay(d); } } } void delayWithStateCheck(int d){ //         for(int value = 0 ; value <= d; value++){ if(!checkState()) break; delay(1); } } boolean checkState(){ //    - int val = analogRead(pinSTOPSIGNAL); boolean state = val > sensValue; if(!state){ // -   setAll(0); if(val < sensNight){ //       currentMaxValueLight = lightNight; //    }else{ currentMaxValueLight = lightDay; //   } } return state; } void setAll(int val){ //      analogWrite(pinZA, val); analogWrite(pinNA, val); analogWrite(pinVAL, val); analogWrite(pinNO, val); analogWrite(pinGO, val); } 




The main "complexity" in the program is a detour of the standard delay function. The fact is that we need to turn everything off immediately after the brake light goes out. To do this, you need to use either interrupts or constantly poll the luminance of the photoresistor. Since humanity has not yet invented interruptions on the analog input (or we need to make a body kit and sew up threshold values ​​into the circuit), then we simply use the self-made delayWithStateCheck function that “flies out” when the stop signal goes off.

The result is the following:



Device assembly, ready to install:

image

Brake light with integrated photoresistor:

image

Night view:

image



Cost of


All components were bought on eBay in China or Hong Kong in advance.

Total: 403 rubles.

findings


Good luck and success in the development of Arduino. And, of course, do not lie and steal :)

Source: https://habr.com/ru/post/189146/


All Articles