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.
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.



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).
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.
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.
stk500_getsync(): not in sync: resp=0x00 #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); } 


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