Lights for cheap with Arduino 2 - more code!!

Lights for cheap with Arduino 2

Hello again! Since my first article about lights has caught few eyeballs, I have decided to make a second one!

I got few people asking me about what my wiring and coding was for that blinks shown on the video, so here it is.

And as a bonus, I have put together one of my suggestions and now I am switching the lights from my RC transmitter!


If you missed the first article of Lights for cheap with Arduino, please read it first. I have explained there how to put the Arduino setup together and start shining.

First see the video of what our Arduino can do.


If you remember the wiring scheme from the first article, there were 4 LEDs for the front lights connected to one pin of Arduino and 4 LEDs for the rear lights connected to another pin. That was it.

Arduino and LEDs wiring diagram
On my NSX it is quite more complex. There are 6 LEDs for each headlight and another 6 LEDs for the rear light. Also I have connected the third wire from my receiver to forward the 3rd channel signal to Arduino.

Ok, so we want them LED's to do something more interesting. The strobe light was not really great. After few minutes of sliding, I had to unplug the Arduino, because it would cause me an epilepsy.

I wanted some effect to occur every few seconds, but I did not want the program to be stuck in delay command in the meantime. So I came up with this:
In our loop cycle we are using a command millis(), which tells us how many milliseconds it's been since we have started the program.

In each cycle, we are comparing this value to the moment we have previously triggered the action (previousMillis). If the difference is more than 4 seconds, we update the previousMillis counter and trigger our custom function.

The custom function turns on the inner LEDs, leaves them on for the duration od delay() function, which we have set to 50 milliseconds, turns them off and continue with the middle LEDs and outer LEDs. This is repeated 3 times in a for cycle. Which creates an effect of stream light.

Like this you can create any cycle you want using only analogWrite and delay commands with or without using cycles.



As promised I have also tried connecting the Arduino to my RC receiver. Surprisingly it was very easy and it works very well!

Arduino and RC receiver connection
After connecting the PWM wire from the receiver, I have configured digital pin 3 as an input pin and created a serial connection.
What it does is, that it allows us to send messages to a console in Arduino IDE.

In the loop function we first read the signal from receiver using pulseIn(3, HIGH) command, where 3 is our input pin and send it to the console.

Here comes a bit tricky part. To be able to receive the signal from the receiver and send the value trough the USB cable at the same time we need to:

  1. Disconnect the arduino from both
  2. Connect it via USB and wait till we see an output in the console
  3. Switch on your transmitter and receiver
  4. Connect arduino to the receiver
Now you should see the actual value of the signal from your receiver (whatever that number means).

Move the 3rd channel on your receiver (in my case an on/off button) and read the values in the console. Then set a condition based on that values and VOILA!!!

If you want to check the complete program, follow the link.

Comments

Popular Posts