Jump to content
  • Join our community

    Sign-up for free and join our friendly community to chat and share all things R/C!

Arduino Light Controller project for my TRX-4


Jens

Recommended Posts

Background is that I was looking into a proper light controller for my TRX-4, but couldn't find anything suitable.
I think my expectations were way too high for what is currently provided.
 

Then searching the web I found some guys using Arduino to control RC cars.
I taught myself some basics in the last week and found that the Arduino could very well satisfy my expectations.
 

Now I came up with this idea:
(   Even though I do it for my TRX-4, I think it can be used on any RC car )

 

Hardware:
- Arduino Nano (Compatible)
- Breakout Board (just to avoid soldering anything around the circuit)
- Darlington Transistor Array ( I don't to connect LEDs directly to the Arduino )
- 4 Channel Pocket Remote Control with 4 receivers
- Photosensitive Sensor with adjustable sensitivity
- Traxxas Light Kit for my TRX-4 G500
- Some Jumper cables
- 12 pin JST plug as connection between the chassis and the body.
 

The Inputs are:
- Remote Control Channel 1
- Remote Control Channel 2
- Remote Control Channel 3
- Remote Control Channel 4
- Photosensitive Sensor
- RC Throttle (CH2)
- RC Steering (CH1)
- RC Transmission (CH3)
- RC Diff Lock Front (CH4)
- RC Diff Lock Rear (CH5)
 

And the Outputs are:
- Daytime Driving Lights (The 5 LEDs below the Headlights )
- Headlights (connected to PWM out to control brightness)
- Taillights (connected to PWM out to control brightness)
- Steering Left (3 LEDs)
- Steering Right (3 LEDs)
- License Plate (2 LEDs, Future Option)
- Reverse Light
- Rear Fog Light
- Third Brake Light (5 LEDs, still need to order)
- Roof Lights Front   (From the kit and my added extra ones)
- Roof Light Rear  (not for me though)
- Horn (goes as RC signal to my ESS-Dual Soundsystem)
 

General Logic:
My plan is to always let the " Arduino Loop" run without any interruptions.
That means I will not use the delay() function or any hardware interrupts.
But rather constantly reading the inputs and always adjusting the outputs according to my logic.
That way I can achieve something like a parallel processing and no output logic     prevents  other output from being changed.

 

My logic:
The main logic will be controlled by the throttle.
Once pressed the state goes into ignition on.
And it stays on until the throttle has remained in neutral for a certain time (10s).
I got that idea from the ESS-Dual. The engine sound turns off after stopping for 10s.
Without "ignition" being on, no lights will work except the hazard light.

 

The second most important item will be the photosensitive sensor.
It defines if it is dark enough to turn on the headlights automatically.
Once dark, the headlights and taillights will turn on at 50%. License plate will also turn on.

The sensor has a small dial to adjust the sensitivity as desired.
 

Remote Control Channel 1:
I use it for high beam.
It means that the headlights will be on at 100%.
The front roof lights will be on.
The rear roof lights will be on if the car is reversing.
If low beam is on then the button functions as toggle on/off.
If low beam is off the button functions as lights on while pressed.

 

Remote Control Channel 2:
This is for Hazard light
Once pressed, all the indicators start blinking.
 

Remote Control Channel 3:
This is for the rear fog light.
Once pressed, the rear fog light will turn on.
I addition the headlights will turn on as if it would be dark.
 

Remote Control Channel 4:
When pressed a RC signal is sent to the ESS-Dual sounding the horn.
 

LEDs:
 Daytime Driving Lights:
They will be turned on when ignition is on.
 

 Headlights: 
50% when it is dark or fog light    on. 100% when Remote Channel 1 pressed.
Special logic when the light sensor goes to dark and the low beam headlights are turned on:
Simulate the ignition of Xenon headlights: Flash, off, slowly dim from 0% to 50%.

 

 Taillights:
50% when it is dark or fog lights on. 100% when car is braking.
The state of braking is defined like this:
Ignition must be turned on and throttle is in neutral.
An Enhancement could be to measure the speed in which the throttle goes from driving into neutral.
If it fast    enough brake lights will go on as well.

 

 Steering:
A rather complex logic.
Steering full left or right and back to neutral within 1s: Start the indicator.
Turning opposite to the indicated direction: Off
Turning into indicated direction beyond a certain value and back to neutral: off.
To control the blinking without stopping the flow of the program, the state of the LEDs need to be constantly adjusted.
On for a certain amount of time, off for a certain amount of time.
 

 Hazard Lights:
Just turn on all indicators.
 

 Reverse light:
Will be turned on once reversing and if the ignition is on.
 

 Front Roof Lights:
Will be turned on together with the headlights in high beam  mode.
 

 Rear Roof Light:
Will be turned on when the car is reversing and headlights are in high beam mode.
 

 Demo Mode:

Switch Gear, All Diff Locks on, then off again, Switch Gear within 1s.

All the LEDs will be blinking randomly  and sounding the horn.

 

So far I have defined my logic    as pseudo code in clear English.
Tonight I will start programming.

 

What I have not yet found out is how I handle trimmed RC channels.
Once trimmed the    signal values will change and impact my logic.
For example trimming the throttle could cause the "ignition" to be always on.
I guess I have to create some code for calibrating every time the car is turned on.
Unless I attach an additional memory module to the Arduino to store the trimmed values... Let's see.

 

I could also start calibration mode with the sequence applied to the RC transmitter like with the demo mode.

 

Lastly the hardware connections:
Arduino outputs are 5V with 30mA max current.
It is somewhat unsuitable for LEDs.
5V would kill LEDs without resistor and 30mA allows only a single LED to be connected.
The solution are    transistors.
Since I have multiple LEDs a prepared Darlington transistor array board with pins is the easiest solution.
 

All the LEDs from the Traxxas kit come without resistors because the kit    comes with a 3V power supply.
The outputs from the Arduino will only trigger the transistors in the array.
The transistor array is then supplied with the 3V from the power supply and then powers the LEDs.
 

My setup is in a way that no soldering is needed.
Once everything is connected I will put everything in a box and seal it watertight.
 

Some essential hardware is already on the way to start testing in the coming days
( Arduino, breakout board, push button, 1 LED, some cables )
 

 

 

 

 

 

  • Like 3
Link to comment
Share on other sites

Great plan. I just finished building a light flasher using an Arduino Pro Mini for a member here. You're right to be wary of driving the LEDs directly off the Arduino as the max drain across all pins is 200ma, fine for a few LEDs but no good for a large project. I like the transistor setup, that should work well. On my TRX-4 sport I did build a setup with an Arduino that controlled headlights/taillights (on/off), brake lights and reversing lights all driven from the board (single LED per pin) but that was about as many as I was prepared to try.

 

There is a great article on ditching Delay() on the arduino site but I guess you've probably found that - its here if you haven't https://learn.adafruit.com/multi-tasking-the-arduino-part-1/ditch-the-delay

 

Good luck, will be interested to see how your project goes.

Link to comment
Share on other sites

Thanks for the support.

I am  into learning the syntax of the programming language  now .

Let's see if I can start tonight already.

 

About the delay().

It is useful if you control    only 1 device. And that device must fulfill    a task (on/off/on/off, up/down/left/right/smile/spit/bite/jump)

But I control 12. And they need to react instantly to any input.

If there is a delay() function  then any changes in the other Inputs (throttle, steering,etc) will not be read during the delay and therefore missed.

 

I had to switch my programmers mind from a simple one time serial execution into constant looping execution.

It's not easy...

Basically if I don't catch it now I will catch next round.

The loop must never stop.

( Like the newspaper boy throwing the papers in front of every house while continue cycling instead of stopping in front of every house and wait for the door to open to deliver paper    🙂 )

 

 

For example blinking a LED (1s on, 1s off). 

I don't wait for it to blink.

I just tell the LED to turn on or off and continue the loop.

Every cycle I check  the elapsed time.

Once it    reaches an 1 second interval I tell the LED to switch and continue.

And so on.

 

Do you understand my thinking?

 

The only exception to that logic would be my demo mode or channel calibration.

It is a one time serial execution and everything else needs to be ignored.

 

 

Link to comment
Share on other sites

Totally understand your logic, I have the same issues on most of my Arduino projects. If you want to drop the delay() function and still be able to have fully timed operations, such as when you have the indicators on and blinking , the Adafruit article covers the whole gambit for pseudo multi tasking on an Arduino.

Link to comment
Share on other sites

I managed to write almost all the code last night.

Some of it is still open. Especially reading the inputs.

For that I need to wait for the hardware to arrive to write the right statements.

Any feedback welcome...

(to    those who do some Arduino programming   here 🙂 )

Maybe I can then write more without having the hardware.

  • Like 1
Link to comment
Share on other sites

Hi @Jens

 

Unfortunately, I can't read your code, I get a forbidden message. On reading the receiver inputs, its pretty straight forward, just use the interrupts on the board and you'll be well away. Here is a simple example to read a single channel:

 

Configure the interrupt in Setup as follows:

 

attachInterrupt(0, rising, RISING);

then I use the following to read the the values on rising and then on falling:

void rising() {
  attachInterrupt(0, falling, FALLING);
  ch3_prev_time = micros();
}

void falling() {
  attachInterrupt(0, rising, RISING);
  ch3_value = micros()-ch3_prev_time;
}

 

Link to comment
Share on other sites

On 24/10/2020 at 17:19, CarlC said:

Hi @Jens

 

Unfortunately, I can't read your code, I get a forbidden message. On reading the receiver inputs, its pretty straight forward, just use the interrupts on the board and you'll be well away. Here is a simple example to read a single channel:

 

It looks like   attachments to a post cannot be opened in this forum. I had a similar experience in another one.

Maybe there is a way to post my current code here in another way Maybe as a scrollable box like in some other forums...

 

I was first trying to do  everything without interrupts.

But I will keep your advice in my mind.

 

The Arduino arrived this weekend and now I need to find time to start.

My work currently doesn't seem to permit it. But let's  see.

 

 

  • Like 1
Link to comment
Share on other sites

It looks like in can post my code in a box in this post.

 

Here we go. Hopefully it works:

 

//---------------- Constants
//-- Input Pin Assignment
const int pinThrottle             = 2;
const int pinSteering             = 4;
const int pinTransmission         = 7;
const int pinDiffLockFront        = 8;
const int pinDiffLockRear         = 9;
const int pinRemoteButton1        = 10;
const int pinRemoteButton2        = 11;
const int pinRemoteButton3        = 12;
const int pinRemoteButton4        = 13;
const int pinLightSensor          = 14;
//-- Output Pin Assignment
const int pinHorn                 = 3;
const int pinHeadlight            = 5;            // with PWM
const int pinTaillight            = 6;            // with PWM
//  const int pinFogLight             = 13;       // ToDo no more Pins
const int pinIndicatorRight       = 15;
const int pinIndicatorLeft        = 16;
const int pinDaytimeLights        = 17;
const int pinLicensePlateLight    = 18;
const int pinReverseLight         = 19;
const int pinThirdBrakelight      = 20;
const int pinRooflightFront       = 21;
// const int pinRooflightRear        = 21;        // ToDo no more Pins

//-- PhotoSensor
const int numPhotoSensorDelayOn   = 5;            // Time delay for the Light Sensor to turn off
const int numPhotoSensorDelayOff  = 2;            // Time delay for the Light Sensor to turn on
//-- Throttle
const int numPWMThrottleForward   = 1550;         // ToDo: Still to be tested and defined
const int numPWMThrottleReverse   = 1450;         // ToDo: Still to be tested and defined
const int durIgnition             = 10;           // How long stays the ignition on
//-- Steering
const int numPWMSteeringLeftMin   = 1550;         // ToDo: Still to be tested and defined
const int numPWMSteeringRightMin  = 1450;         // ToDo: Still to be tested and defined
const int numPWMSteeringLeftMid   = 1700;         // ToDo: Still to be tested and defined
const int numPWMSteeringRightMid  = 1300;         // ToDo: Still to be tested and defined
const int numPWMSteeringLeftMax   = 2000;         // ToDo: Still to be tested and defined
const int numPWMSteeringRightMax  = 1000;         // ToDo: Still to be tested and defined
//-- Headlights
const int numHeadlightDim000      = 0;            // Headlights off
const int numHeadlightDim010      = 25;           // Headlights at 10%
const int numHeadlightDim020      = 50;           // Headlights at 20%
const int numHeadlightDim025      = 62;           // Headlights at 25%
const int numHeadlightDim030      = 75;           // Headlights at 30%
const int numHeadlightDim035      = 87;           // Headlights at 35%
const int numHeadlightDim040      = 100;          // Headlights at 40%
const int numHeadlightDim045      = 112;          // Headlights at 45%
const int numHeadlightDim050      = 127;          // Headlights at 50%
const int numHeadlightDim100      = 255;          // Headlights at 100%
//-- Taillights
const int numTaillightDim000      = 0;            // Taillights off
const int numTaillightDim050      = 127;          // Taillights at 50%
const int numTaillightDim100      = 255;          // Taillights at 100%

const float durIndicatorActivate  = 1;            // time to activate the indicator
const float durIndicatorOn        = 0.1;          // duration indicator LED is on
const float durIndicatorOff       = 0.1;          // duration indicator LED is off
//-- Transmission
const int numPWMGear              = 1500;         // ToDo: Still to be tested and defined
//-- Diff Locks
const int numPWMDiffLockFront     = 1500;         // ToDo: Still to be tested and defined
const int numPWMDiffLockRear      = 1500;         // ToDo: Still to be tested and defined
//-- Start Headlights
const float HeadlightStage1       = 0.5;          // Headlight Start Stage 1: 100%
const float HeadlightStage2       = 0.6;          // Headlight Start Stage 2: Off
const float HeadlightStage3       = 0.7;          // Headlight Start Stage 3: 10%
const float HeadlightStage4       = 0.8;          // Headlight Start Stage 4: 20%
const float HeadlightStage5       = 0.9;          // Headlight Start Stage 5: 25%
const float HeadlightStage6       = 1.0;          // Headlight Start Stage 6: 30%
const float HeadlightStage7       = 1.1;          // Headlight Start Stage 7: 35%
const float HeadlightStage8       = 1.2;          // Headlight Start Stage 8: 40%
const float HeadlightStage9       = 1.3;          // Headlight Start Stage 9: 45%
//-- ChristmasTree
const float durDemo               = 10;           // Duration for the Demo mode aka Christmas Tree :-)
const float durDemoActivate       = 1;            // time to activate the Demo mode
const float durDemoSwitch         = 0.5;          // time each Demo step is active

//---------------- Variables

//-- Input Variables
bool  isButton1Pressed;                   // Remote Control Button 1 Pressed
bool  isButton1Released;                  // Remote Control Button 1 Released
bool  isButton2Pressed;                   // Remote Control Button 2 Pressed
bool  isButton2Released;                  // Remote Control Button 2 Released
bool  isButton3Pressed;                   // Remote Control Button 3 Pressed
bool  isButton3Released;                  // Remote Control Button 3 Released
bool  isButton4Pressed;                   // Remote Control Button 4 Pressed
bool  isButton4Released;                  // Remote Control Button 4 Released
//-- State Variables
bool  isHighBeamFlash;                    // Flash the Highbeam when Remote1 is pressed and headlights are off
bool  isHighBeam;                         // Turn on/off Highbeam when Remote1 is pressed and headlights are on
bool  isHazardLight;                      // Turn on/off Hazard Lights when Remote2 is pressed
bool  isFogLightOn;                       // Turn on/off Rear Fog Light and Headlights when Remote3 is pressed
bool  isHornContinuous;                   // Sound Horn while Remote4 is pressed
bool  isHorn;                             // Send one time signal to sound horn when Remote4 is pressed
bool  isDark;                             // set by the photosensitive sensor if the environment is dark
bool  isReverse;                          // Car is reversing
bool  isForward;                          // Car is driving
bool  isStopping;                         // Car is Stopping
bool  isIgnition;                         // "Ignition" is turned on. Throttle has been pulled and stays on for a time defined by durIgnition.
bool  isHeadlightStart;                   // Turn on the Headlight and simulate a Xenon startup sequence
bool  isHeadlightStarted;                 // Headlight Start Sequence completed
bool  isCountdown;                        // Countdown to turn off ignition has started.
bool  isFullLeft;                         // Steering to Full Left
bool  isFullRight;                        // Steering to Full Right
bool  isIndicatorRight;                   // Indicator Right is On
bool  isIndicatorLeft;                    // Indicator Left is On
bool  TurnOffIndicator;                   // Indicator to be turned off
bool  toggleGear;                         // Gear Change
bool  isDiffLockFront;                    // Front Differentials locked
bool  toggleDiffLockFront;                // Front Differentials changed
bool  isDiffLockRear;                     // Rear Differentials locked
bool  toggleDiffLockRear;                 // Rear Differentials changed
bool  stateIndicatorRightIsOn;            // state of Right Indicator LED
bool  stateIndicatorLeftIsOn;             // state of Left Indicator LED
bool  isDemoStage1;                       // Sequence to turn on Demo: Gear Change 2 to 1
bool  isDemoStage2;                       // Sequence to turn on Demo: Front Diff Lock on
bool  isDemoStage3;                       // Sequence to turn on Demo: Rear Diff Lock on
bool  isDemoStage4;                       // Sequence to turn on Demo: Rear Diff Lock off
bool  isDemoStage5;                       // Sequence to turn on Demo: Front Diff Lock off
bool  isDemoStage6;                       // Sequence to turn on Demo: Gear Change 1 to 2
int   numCurrentGear;                     // current Gear
unsigned long   timeLastNeutral;          // time the Throttle was last in neutral
unsigned long   timeCountdown;            // countdown timer for Ignition off
unsigned long   timerHeadlightStart;      // timer to start Headlights
unsigned long   timerLeftIndBlink;        // timer to control the left indicator blinking
unsigned long   timerRightIndBlink;       // timer to control the right indicator blinking
unsigned long   timeLightSensorDelayOn;   // delay timer to turn on the headlights after it is dark
unsigned long   timeLightSensorDelayOff;  // delay timer to turn off the headlights after it is bright
unsigned long   timeDemoActivate;         // time the first step was taken to activate Demo mode
unsigned long   timeDemoStarted;          // time the Demo mode started

//---------------- Setup section

void  setup()
{
  //-- Set Variable Defaults
  isButton1Pressed        = false;
  isButton1Released       = false;
  isButton2Pressed        = false;
  isButton2Released       = false;
  isButton3Pressed        = false;
  isButton3Released       = false;
  isButton4Pressed        = false;
  isButton4Released       = false;

  isHighBeamFlash         = false;
  isHighBeam              = false;
  isHazardLight           = false;
  isFogLightOn            = false;
  isHornContinuous        = false;
  isHorn                  = false;
  isDark                  = false;
  isIgnition              = false;
  isHeadlightStart        = false;
  isHeadlightStarted      = false;
  isCountdown             = false;
  isReverse               = false;
  isForward               = false;
  isStopping              = false;
  isFullLeft              = false;
  isFullRight             = false;
  isIndicatorRight        = false;
  isIndicatorLeft         = false;
  TurnOffIndicator        = true;
  toggleGear              = false;
  isDiffLockFront         = false;
  toggleDiffLockFront     = false;
  isDiffLockRear          = false;
  toggleDiffLockRear      = false;
  stateIndicatorRightIsOn = false;
  stateIndicatorLeftIsOn  = false;
  isDemoStage1            = false;
  isDemoStage2            = false;
  isDemoStage3            = false;
  isDemoStage4            = false;
  isDemoStage5            = false;
  isDemoStage6            = false;

  numCurrentGear          = 0;
  timeLastNeutral         = millis();
  timeCountdown           = 0;
  timerLeftIndBlink       = 0;
  timerRightIndBlink      = 0;
  timeDemoStarted         = 0;
  timeDemoActivate        = 0;
  timerHeadlightStart     = 0;
  timeLightSensorDelayOn  = 0;
  timeLightSensorDelayOff = 0;

  //-- Define Input Pins
  pinMode( pinRemoteButton1,      INPUT_PULLUP );
  pinMode( pinRemoteButton2,      INPUT_PULLUP );
  pinMode( pinRemoteButton3,      INPUT_PULLUP );
  pinMode( pinRemoteButton4,      INPUT_PULLUP );
  pinMode( pinLightSensor,        INPUT_PULLUP );
  // ToDo -- pinMode( pinThrottle,
  // ToDo -- pinMode( pinSteering,
  // ToDo -- pinMode( pinTransmission,
  // ToDo -- pinMode( pinDiffLockFront,
  // ToDo -- pinMode( pinDiffLockRear,

  //-- Define Output Pins
  pinMode( pinIndicatorRight,     OUTPUT );
  pinMode( pinIndicatorLeft,      OUTPUT );
  pinMode( pinDaytimeLights,      OUTPUT );
  pinMode( pinHeadlight,          OUTPUT );
  pinMode( pinTaillight,          OUTPUT );
  pinMode( pinLicensePlateLight,  OUTPUT );
  pinMode( pinReverseLight,       OUTPUT );
  pinMode( pinThirdBrakelight,    OUTPUT );
  pinMode( pinRooflightFront,     OUTPUT );
//  pinMode( pinRooflightRear,      OUTPUT );       // ToDo
//  pinMode( pinFogLight,           OUTPUT );       // ToDo
  pinMode( pinHorn,               OUTPUT );

// ToDo
// calibrate steering/Throttle



}


//---------------- Loop Section
void  loop()
{

  //-- Read Inputs
  checkRemote1();
  checkRemote2();
  checkRemote3();
  checkRemote4();
  checkPhotoSensor();
  checkThrottle();
  checkSteering();
  checkGear();
  checkDiff1();
  checkDiff2();

  //-- Write Outputs
  setIndicatorRight();
  setIndicatorLeft();
  setDaytimeLights();
  setHeadlight();
  setTaillight();
  setLicensePlateLight();
  setReverseLight();
  setThirdBrakelight();
  setRooflightFront();
  setRooflightRear();
  setFogLight();
  setHorn();
  setHeadlightStart();
  setChristmasTree();

  //-- reset Toggles
  toggleGear          = false;
  toggleDiffLockFront = false;
  toggleDiffLockRear  = false;

}


//---------------- Function Section

void  checkRemote1()
{
  if (1 == 1) {
// ToDo if (Button1 pressed) {
    isButton1Pressed  = true;
    isButton1Released = false;
    isHighBeamFlash   = true;
  }
  if (1 == 1) {
// ToDo if (Button1 Released) {
    isButton1Released = true;
    isHighBeamFlash   = false;
  }
  if (isButton1Pressed && isButton1Released) {
    isButton1Pressed  = false;
    isButton1Released = false;
    if (isHighBeam)
      isHighBeam = false;
    else
      isHighBeam = true;
  }
}

void  checkRemote2()
{
  if (1 == 1) {
// ToDo if (Button2 pressed) {
    isButton2Pressed  = true;
    isButton2Released = false;
    }
  if (1 == 1)
// ToDo if (Button2 Released)
    isButton2Released = true;
  if (isButton2Pressed && isButton2Released) {
    isButton2Pressed  = false;
    isButton2Released = false;
    if (isHazardLight) {
      isHazardLight       = false;
      timerLeftIndBlink   = 0;
      timerRightIndBlink  = 0;
    }
    else {
      isHazardLight       = true;
      timerLeftIndBlink   = millis();
      timerRightIndBlink  = millis();
    }
    }
}

void  checkRemote3()
{
    if (1 == 1) {
// ToDo if (Button3 pressed) {
      isButton3Pressed  = true;
      isButton3Released = false;
      }
    if (1 == 1)
// ToDo if (Button3 Released)
      isButton3Released = true;
    if (isButton3Pressed && isButton3Released) {
      isButton3Pressed  = false;
      isButton3Released = false;
      if (isFogLightOn)
        isFogLightOn = false;
      else
        isFogLightOn = true;
      }
}

void  checkRemote4()
{
    if (1 == 1) {
// ToDo if (Button4 pressed) {
      isButton4Pressed  = true;
      isButton4Released = false;
      isHornContinuous  = true;
      }
    if (1 == 1) {
// ToDo if (Button4 Released) {
      isButton4Released = true;
      isHornContinuous  = false;
      }
    if (isButton4Pressed && isButton4Released) {
      isButton4Pressed  = false;
      isButton4Released = false;
      if (isHorn)
        isHorn = false;
      else
        isHorn = true;
      }
}

void  checkPhotoSensor()
{
  if (digitalRead(pinLightSensor) == LOW)
    if (timeLightSensorDelayOn == 0)
      timeLightSensorDelayOn = millis();
    if (millis() >= timeLightSensorDelayOn + ( numPhotoSensorDelayOff * 1000 )) {
      timeLightSensorDelayOn  = 0;
      isDark                  = true;
    }
  else
    if (timeLightSensorDelayOff == 0)
      timeLightSensorDelayOff = millis();
    if (millis() >= timeLightSensorDelayOff + ( numPhotoSensorDelayOn * 1000 )) {
      timeLightSensorDelayOff = 0;
      isDark                  = false;
    }
}

void  checkThrottle()
{
  isReverse  = false;
  isForward  = false;
  isStopping = false;

  if (1 == 1) {
// ToDo if (PWM > numPWMThrottleForward) {
    isIgnition = true;
    isForward  = true;
    isCountdown = false;
  }
  else
    if (1 == 1) {
// ToDo if (PWM < numPWMThrottleReverse) {
      isIgnition  = true;
      isReverse   = true;
      isCountdown = false;
    }
    else {
      isStopping = true;
      if (isIgnition)
        if (!isCountdown) {
          isCountdown = true;
          timeCountdown = millis();
      }
  }
  if (isCountdown)
    if (millis() >= timeCountdown + ( durIgnition * 1000 ))
      isIgnition = false;
}


void  checkSteering()
{

  if (1 == 1)
// ToDo if (PWM > numPWMSteeringLeftMax)
    isFullLeft = true;
  else
    if (1 == 1)
// ToDo if (PWM < numPWMSteeringRightMax)
      isFullRight = true;

  if (isIndicatorLeft)
    if (1 == 1)
// ToDo if (PWM > numPWMSteeringLeftMid)
      TurnOffIndicator = true;

  if (isIndicatorRight)
    if (1 == 1)
// ToDo if (PWM > numPWMSteeringRightMid)
      TurnOffIndicator = true;

  if (1 == 1)
// ToDo if (PWM > numPWMSteeringLeftMin)
    isIndicatorRight = false;
  else {
    if (1 == 1)
// ToDo if (PWM < numPWMSteeringRightMin)
      isIndicatorLeft = false;
    else {
      if (isFullLeft) {
        isFullLeft = false;
        if (millis() - timeLastNeutral < ( durIndicatorActivate * 1000 ))
          isIndicatorLeft   = true;
          timerLeftIndBlink = millis();
      }
      if (isFullRight) {
      isFullRight = false;
        if (millis() - timeLastNeutral < ( durIndicatorActivate * 1000 ))
          isIndicatorRight    = true;
          timerRightIndBlink  = millis();
      }
      if (TurnOffIndicator) {
        isIndicatorLeft     = false;
        isIndicatorRight    = false;
        timerLeftIndBlink   = 0;
        timerRightIndBlink  = 0;
      }
      timeLastNeutral = millis();
    }
  }
}

void  checkGear()
{
  if (1 == 1) {
// ToDo if (PWM > numPWMGear) {
    if (numCurrentGear == 1)
      toggleGear = true;
    numCurrentGear = 2;
  }
  else {
    if (numCurrentGear == 2)
      toggleGear = true;
    numCurrentGear = 1;
  }
}

void  checkDiff1()
{
  if (1 == 1) {
// ToDo if (PWM > numPWMDiffLockFront) {
    if (isDiffLockFront)
      toggleDiffLockFront = true;
    isDiffLockFront = false;
  }
  else {
    if (!isDiffLockFront)
      toggleDiffLockFront = true;
    isDiffLockFront = true;
  }
}


void  checkDiff2()
{
  if (1 == 1) {
// ToDo if (PWM > numPWMDiffLockRear) {
    if (isDiffLockRear)
      toggleDiffLockRear = true;
    isDiffLockRear = false;
  }
  else {
    if (!isDiffLockRear)
      toggleDiffLockRear = true;
    isDiffLockRear = true;
  }
}

void  setIndicatorRight()
{
  if (isIgnition)
    if (isHazardLight || isIndicatorRight) {

      if (stateIndicatorRightIsOn)
        if (millis() >= timerRightIndBlink + ( durIndicatorOn * 1000 )) {
          stateIndicatorRightIsOn = false;
          timerRightIndBlink      = millis();
        }
      else
        if (millis() >= timerRightIndBlink + ( durIndicatorOff * 1000 )) {
          stateIndicatorRightIsOn = true;
          timerRightIndBlink      = millis();
        }

      if (stateIndicatorRightIsOn)
        digitalWrite(pinIndicatorRight, HIGH );
      else
        digitalWrite(pinIndicatorRight, LOW );
    }
    else
      digitalWrite(pinIndicatorRight, LOW );
  else
    digitalWrite(pinIndicatorRight, LOW );
}

void  setIndicatorLeft()
{
  if (isIgnition)
    if (isHazardLight || isIndicatorLeft) {

      if (stateIndicatorLeftIsOn)
        if (millis() >= timerLeftIndBlink + ( durIndicatorOn * 1000 )) {
          stateIndicatorLeftIsOn  = false;
          timerLeftIndBlink       = millis();
        }
      else
        if (millis() >= timerLeftIndBlink + ( durIndicatorOff * 1000 )) {
          stateIndicatorLeftIsOn  = true;
          timerLeftIndBlink       = millis();
        }

      if (stateIndicatorLeftIsOn)
        digitalWrite(pinIndicatorLeft, HIGH );
      else
        digitalWrite(pinIndicatorLeft, LOW );
    }
    else
      digitalWrite(pinIndicatorLeft, LOW );
  else
    digitalWrite(pinIndicatorLeft, LOW );
}

void  setDaytimeLights()
{
  if (isIgnition)
    digitalWrite(pinDaytimeLights, HIGH );
  else
    digitalWrite(pinDaytimeLights, LOW );
}

void  setHeadlight()
{
  if (isIgnition)
    if (isHighBeam || isHighBeamFlash)
      analogWrite(pinHeadlight, numHeadlightDim100 );
    else
      if (isFogLightOn)
        if (isHeadlightStarted)
          analogWrite(pinHeadlight, numHeadlightDim050 );
        else
          isHeadlightStart = true;
      else
        if (isHeadlightStarted)
          analogWrite(pinHeadlight, numHeadlightDim050 );
        else
          isHeadlightStart = true;
  else
    analogWrite(pinHeadlight, numHeadlightDim000 );
}

void  setTaillight()
{
  if (isIgnition)
    if (isStopping)
      analogWrite(pinTaillight, numTaillightDim100 );
    else
      if (isFogLightOn)
        analogWrite(pinTaillight, numTaillightDim050 );
      else
        if (isDark)
          analogWrite(pinTaillight, numTaillightDim050 );
        else
          analogWrite(pinTaillight, numTaillightDim000 );
  else
    analogWrite(pinTaillight, numTaillightDim000 );
}

void  setLicensePlateLight()
{
  if (isIgnition)
    if (isFogLightOn)
      digitalWrite(pinLicensePlateLight, HIGH );
    else
      if (isDark)
        digitalWrite(pinLicensePlateLight, HIGH );
      else
        digitalWrite(pinLicensePlateLight, LOW );
  else
    digitalWrite(pinLicensePlateLight, LOW );
}

void  setReverseLight()
{
  if (isIgnition)
    if (isReverse)
      digitalWrite(pinReverseLight, HIGH );
    else
      digitalWrite(pinReverseLight, LOW );
  else
    digitalWrite(pinReverseLight, LOW );
}

void  setThirdBrakelight()
{
  if (isIgnition && isStopping)
    digitalWrite(pinThirdBrakelight, HIGH );
  else
    digitalWrite(pinThirdBrakelight, LOW );
}


void  setRooflightFront()
{
  if (isIgnition)
    if (isHighBeam || isHighBeamFlash)
      digitalWrite(pinRooflightFront, HIGH );
    else
      digitalWrite(pinRooflightFront, LOW );
  else
    digitalWrite(pinRooflightFront, LOW );
}

void  setRooflightRear()
{
  if (isIgnition)
    if (isHighBeam && isReverse)
//      digitalWrite(pinRooflightRear, HIGH );
    else
//      digitalWrite(pinRooflightRear, LOW );
  else
//    digitalWrite(pinRooflightRear, LOW );
}

void  setFogLight()
{
  if (isIgnition && isFogLightOn)
//    digitalWrite(pinFogLight, HIGH );
  else
//    digitalWrite(pinFogLight, LOW );
}

void  setHorn()
{
  analogWrite(pinHorn, 0 );
  if (isHorn)
    analogWrite(pinHorn, 255 );
  isHorn = false;
}


void  setHeadlightStart()
{

  if (isHeadlightStart)
  {
    // Start the timer
    if (timerHeadlightStart == 0)
      timerHeadlightStart = millis();

    if (millis() <= timerHeadlightStart + ( HeadlightStage1 * 1000 ))
      analogWrite(pinHeadlight, numHeadlightDim100 );
    else
      if (millis() <= timerHeadlightStart + ( HeadlightStage2 * 1000 ))
        analogWrite(pinHeadlight, numHeadlightDim000 );
      else
        if (millis() <= timerHeadlightStart + ( HeadlightStage3 * 1000 ))
          analogWrite(pinHeadlight, numHeadlightDim010 );
        else
          if (millis() <= timerHeadlightStart + ( HeadlightStage4 * 1000 ))
            analogWrite(pinHeadlight, numHeadlightDim020 );
          else
            if (millis() <= timerHeadlightStart + ( HeadlightStage5 * 1000 ))
              analogWrite(pinHeadlight, numHeadlightDim025 );
            else
              if (millis() <= timerHeadlightStart + ( HeadlightStage6 * 1000 ))
                analogWrite(pinHeadlight, numHeadlightDim030 );
              else
                if (millis() <= timerHeadlightStart + ( HeadlightStage7 * 1000 ))
                  analogWrite(pinHeadlight, numHeadlightDim035 );
                else
                  if (millis() <= timerHeadlightStart + ( HeadlightStage8 * 1000 ))
                    analogWrite(pinHeadlight, numHeadlightDim040 );
                  else
                    if (millis() <= timerHeadlightStart + ( HeadlightStage9 * 1000 ))
                      analogWrite(pinHeadlight, numHeadlightDim045 );
                    else {
                      isHeadlightStarted  = true;
                      isHeadlightStart    = false;
                    }
  }
}



// ToDo
// Change to serial execution with delay()
void  setChristmasTree()
// digitalWrite(, LOW );
// digitalWrite(, HIGH );
// toggleGear
// toggleDiffLockFront
// toggleDiffLockRear

// durDemo
// durDemoActivate
// durDemoSwitch

// timeDemoActivate
// timeDemoStarted

// isDemoStage1
// isDemoStage2
// isDemoStage3
// isDemoStage4
// isDemoStage5
// isDemoStage6
{



// To activate within 1 second
// Switch Gear
// Switch Diff Locks on
// Switch Diff Locks off
// Switch Gear


  if (toggleGear) {
    timeDemoActivate  = millis();
    isDemoStage1      = true;
  }

  if (isDemoStage1 && toggleDiffLockFront)
    isDemoStage2 = true;

  if (isDemoStage2 && toggleDiffLockRear)
    isDemoStage3 = true;

  if (isDemoStage3 && toggleDiffLockRear)
    isDemoStage4 = true;

  if (isDemoStage4 && toggleDiffLockFront)
    isDemoStage5 = true;

  if (isDemoStage5 && toggleGear)
    isDemoStage6 = true;

  if (isDemoStage6 && ( millis() <= timeDemoActivate + ( durDemoActivate * 100 ) )) {
    timeDemoStarted = millis();
    isDemoStage1    = false;
    isDemoStage2    = false;
    isDemoStage3    = false;
    isDemoStage4    = false;
    isDemoStage5    = false;
    isDemoStage6    = false;
  }

  while ( millis() <= timeDemoStarted + ( durDemo * 1000 ) && timeDemoStarted > 0  ) {










  }





}

 

Link to comment
Share on other sites

On 24/10/2020 at 17:19, CarlC said:

Hi @Jens

 

Unfortunately, I can't read your code, I get a forbidden message. On reading the receiver inputs, its pretty straight forward, just use the interrupts on the board and you'll be well away. Here is a simple example to read a single channel:

 

Configure the interrupt in Setup as follows:

 


attachInterrupt(0, rising, RISING);

then I use the following to read the the values on rising and then on falling:


void rising() {
  attachInterrupt(0, falling, FALLING);
  ch3_prev_time = micros();
}

void falling() {
  attachInterrupt(0, rising, RISING);
  ch3_value = micros()-ch3_prev_time;
}

 

Hi Carl,

 

I tried to use the pulseIn() function.

Found some code that should work, but it doesn't.

Others say that I can only use interrupts.

 

Have you tried pulseIn() and failed or did you use  interrupts straight away?

 

 

 

Link to comment
Share on other sites

13 minutes ago, Jens said:

Hi Carl,

 

I tried to use the pulseIn() function.

Found some code that should work, but it doesn't.

Others say that I can only use interrupts.

 

Have you tried pulseIn() and failed or did you use  interrupts straight away?

 

 

 

 

I went with interrupts straight away. Primarily, because I use that approach on other platforms.

Link to comment
Share on other sites

On 27/10/2020 at 16:12, CarlC said:

 

I went with interrupts straight away. Primarily, because I use that approach on other platforms.

You were right.

pulseIn() doesn't really work.

I have to use interrupts.

So I used 3 additional libraries:

  1. Servo.h: To be able to send a servo signal to the ESS-Dual additional input for a horn.
  2. ServoInput.h:  To read the PWM signal from the 5 receiver channels
  3. PinChangeInterrupt.h: To relocate the interrupts to the pins that I want to use.

The 2 servo libraries are really    good.

I only use the PWM values (1000-2000) as parameters. Everything else is handled in  the library.

eg: 

servoThrottle.getPulse() gives me values between 1000-2000.

ESSDual.writeMicroseconds(1800) to send a signal.

with   ESSDual.attach() before and  ESSDual.detach() after to avoid any unwanted interference  triggering the horn.

 

 

  • Like 1
Link to comment
Share on other sites

@Jens

 

Good find on the PinChangeInterrupt.h library, I've always used the defined pins but being able to move them is really useful. Will also look at the ServoInput lib too, I always do my PWM readings myself but if I can use a lib even better.

Link to comment
Share on other sites

Yep, those libraries are good.

I have all pins on my   Nano used.

So I have don't have much freedom.

Esp since only some pins can  handle PWM out.

Others cannot handle PWM in.

Some cannot handle digital.

etc...

So I am constantly changing pins until everything    works as expected.

Luckily I could eliminate the interrupt limitation.

 

Some help for you:

Includes in this order (Important):

#include <PinChangeInterrupt.h>
#include <ServoInput.h>
#include <Servo.h>

Complete example for ServoInput:

const int pinThrottle = 12;           
ServoInputPin<pinThrottle>      servoThrottle;
servoThrottle.getPulse()  --> gets you output in 1000-2000.

Complete example for Servo  to send a PWM signal:

const int pinHorn = 3;           // with PWM out --> must be pins 3, 5, 6, 10, 11 for Nano
Servo  ESSDual;
ESSDual.attach(pinHorn); 
ESSDual.writeMicroseconds(1800);
ESSDual.detach(); 

You should always attach and detach the servo, if you don't want to send signals. 

ESSDual.writeMicroseconds() is constantly sending the pulse and the values are somewhat fluctuating.

 

 

Link to comment
Share on other sites

  • 1 month later...

Back to my Arduino project after I finally   finished the rebuild of my formerly rusty TRX-4.

I also spent some more time to figure out details about how to accomplish all my ideas and  ordering some more parts.

 

If things go as planned it will be a  controller that is not only for my TRX-4 but it can be used in every RC car.

Nevertheless I will share my work from a TRX-4 G500 perspective.

 

I hope you are interested to follow and maybe help me when I am stuck with something.

 

I will start with a    shopping list, which I will keep updating once I progress.

 

Parts:

1 Arduino Nano (compatible) - ebay -    https://www.ebay.co.uk/itm/Arduino-Nano-V3-0-Expansion-Board-NANO-I-O-Shield-Arduino-NANO-IO-Breakaway/263100256826?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

1 Arduino  Expansion Board - ebay -  see above link

2   Darlington Transistor Arrays -   Amazon - https://smile.amazon.co.uk/gp/product/B08CHC43YC/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1&fpw=alm

1  Photosensitive Sensor - ebay - https://www.ebay.co.uk/itm/5pcs-Light-Intensity-Photosensitive-Sensor-Resistor-Module-for-Arduino/392969599869?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

1 4ch Remote - Aliexpress -   https://www.aliexpress.com/item/4000393345582.html?spm=2114.13010708.0.0.64f74c4dC9sgtF

4 Receivers - Aliexpress - see above link

1 power supply - ebay -   https://www.ebay.co.uk/itm/LM2596-Step-down-LM2596S-Power-Voltage-Converter-Module-DC-4-0-40-to-1-3-37V-LED/263168810640?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

1 set of 3:1 heat shrink tubes - ebay - https://www.ebay.co.uk/itm/320-pcs-3-1-Shrink-Tubing-Heat-Shrink-Tubing-Adhesive-7-Size-3-Color-Shrink-Wrap/274489902002?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

10 3pin Dupont jumper wires - ebay - https://www.ebay.co.uk/itm/10pcs-3pin-20cm-2-54mm-Female-to-Female-jumper-wire-Dupont-cable-for-Arduino/402479923495?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

5 Servo Y Splitter cables - ebay - https://www.ebay.co.uk/itm/5x-Y-Splitter-Servo-Wire-Compatible-with-JR-Futaba-Plug-RC-Extension-Lead/274429855026?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

1 12 pin Molex Mini connectors - ebay

       - Male: https://www.ebay.co.uk/itm/5557-4-2mm-Double-Row-Connectors-2-24-Pin-Crimps-Molex-Mini-fit-Jr-Style/233332015709?ssPageName=STRK%3AMEBIDX%3AIT&var=532865291756&_trksid=p2057872.m2749.l2649

       - Female: https://www.ebay.co.uk/itm/5559-4-2mm-Double-Row-Connectors-2-24-Pin-Crimps-Molex-Mini-fit-Jr-Style/233332499853?ssPageName=STRK%3AMEBIDX%3AIT&var=532865963917&_trksid=p2057872.m2749.l2649

2 70x100mm Copper Clad Laminate PCB Bords - Amazon - https://smile.amazon.co.uk/gp/product/B07DJV7PJN/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
1 Box of M3 Nylon Hex Spacers - Amazon - https://smile.amazon.co.uk/gp/product/B07FB6Q33X/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

 

 

Special tools  required:

  1. Soldering iron
  2. Solder wire with silver content
  3. No Clean Flux
  4. Dupont Crimping Tool

 

I think this will all be fairly easy.

So far I identified 2 rather difficult tasks. At least they were for me.

Using the crimping tool with   those small cables and soldering the pins on the transistor array.

 

 

Edited by Jens
Link to comment
Share on other sites

Step 1: Darlington Transistor Arrays.

 

Why I use them?

An Arduino is only able to supply a maximum of 40mA on each output pin. That is just enough for 1 LEDs.

If I now want to connect 2 tail lights to a single pin, I would have a problem.

On top of that the output voltage can go up to 5V, killing any LED that is without a resistor.

 

Hence I chose a transistor to power the LEDs with their own supply.

And since I will have multiple groups of LEDs (Indicators, head lights, tail lights) I choose a transistor array, which contains multiple transistors.

 

IMG-4846.jpg

The result of the most difficult task: Soldering the pins on.

And as you can see: Very unprofessional. I just hope that I don't have any failures because of that.

 

 

 

Link to comment
Share on other sites

10 hours ago, Fat Freddy said:

Sometimes I feel really thick. Next level stuff. Following this thread despite understanding one word in ten. 😆

I understand you very well and I feel the same if someone tries to explain to me things that I don't understand.

But ignore everything that was posted before yesterday. That can be quite complicated.

Yesterday I started to try to explain everything as simple as possible.

I am a hardcore programmer all life, but I really try my best to keep it simple.

But creating a light system for a realistic model using Arduino has so much potential...

Link to comment
Share on other sites

Step 3: Connections to the RC receiver Part 1.

 

I want that all the servo signals from the receiver will also go to the Arduino, so that the Arduino reads those signals and can do something with them.

The Arduino is able to read the PWM signals that a receivers sends to servos and can then do something depending on the values.

Those signals come as pulses.

Let me use the steering signal as an example:

Full left: 1000 pulses

Neutral: 1500 pulses

Full right: 2000 pulses

And the Arduino program can now read those numbers and do something according to the programming.

 

Parts needed (see above list):

5x 3pin Dupont jumper wires

5x Servo Y Splitter cables

1x 12 pin Molex Mini connectors male or female

 

The servo cable contains 3 wires as we all know.

We only need 2 of them:

The white/yellow one for the pulse signal.

The black one for the ground.

We should never use the red one as it contains the positive voltage and the higher voltage from the receiver could destroy the Arduino.

 

I also don't connect the receiver cables directly to the Arduino, but use a "Molex" plug in between.

That way I am always able to easily remove the Arduino from the car.

 

Here is how the Dupont jumper wires will look after the red cable has been clipped and the pins for the Molex plug connected.

Use the crimping tool for that.

IMG-4850.jpg

( BTW, I use a gas powered soldering iron, since I hate always having to be nearby a mains plug )

 

Now connect the Servo splitters to the receivers and for each splitter one cable goes to the servo(or ESC) and the other one to the modified jumper cable.

IMG-4854.jpg

My TRX-4 receiver has 5 channels and therefore my whole construction will be based on that.

If you have less than 5 channels, it's also Ok, but then your final Arduino program might be a bit different.

 

 

.

.

.

Next task would be to continue on the other side of the Molex plug going with the cable to the Arduino.

Or I better put all the Arduino electronics in a box first and come out with the cables from there.

 

Putting all the electronics in a box is currently unresolved for me.

I could just throw all parts in a box, keeping a chaos inside or I manage to get a custom box where all electronic parts have their proper place.

 

The only way to have such a proper box would be to have it 3D printed.

Is anybody here in this forum with a 3D printer and has the knowledge to create a 3D design on the computer?

 

Nevertheless, my next post will surely take a while to appear here.

 

 

Link to comment
Share on other sites

  • 4 weeks later...

After cracking my brain for a long time and lots of brainstorming in my daily shower I think I found a way forward.

 

Next, I want to put the IC boards together, so that I can start connecting everything.
I came up with the idea of first fixing everything on a PCB board before putting things in a box.

 

Here we go.

 

Parts needed (shopping list above updated):

  • 1x Arduino Nano
  • 1x Arduino Expansion Board
  • 2x Transistor Arrays
  • 4x Receivers from the 4ch Remote
  • 1x Power Supply / Voltage Regulator
  • 2x 70x100mm Copper Clad Laminate PCB Bords
  • 1x Box of M3 Nylon Hex Spacers

IMG-5066.jpg


My idea:
Put the Arduino with Expansion Board and the Transistor Arrays on the first PCB Board.
Put the Voltage Regulator and the 4 Receivers on the second Board.
Then use long hex spacers to stack the 2 boards on top of each other.

 

Steps:

 

Align the IC boards on the PCB and mark the screwholes with a pen.
IMG-5061.jpg

 

IMG-5062.jpg

 

IMG-5063.jpg

 

Drill 3mm holes in the PCB Bords at the marked locations.
Mark and drill 4 more holes in the corners of each board.
IMG-5065.jpg

 

Fix the IC boards with the hex spacers on the board.
I use long M2 brass hex spacers for the 4 corners.
The nylon will do as well, but I wanted some extra stability.

IMG-5069.jpg

Later, the Arduino PCB will go on top of the Regulator PCB.

 

IMG-5067.jpg


IMG-5068.jpg

 

At last glue the 4 receivers on the board with the voltage regulator.

( I used hot glue )

I just hope that the voltage regulator doesn't cause any interference...

IMG-5070.jpg

Each receiver is for one of the 4 remote channels. I just wrote down the letters so that I know how to connect them later.

 

Here is some more explanation to understand my idea:

IMG-5061-marked.jpg

A: Power In for the Arduino. It will accept up to 12V. That means 3S LiPos will be the max.

B: Mini USB to connect it to your PC. It will also power the Arduino for dry runs.

C : The In/Output pins. With the expansion board it is much easier to connect cables than directly on the Arduino board.

D : The Transistor Array.

The transistors are required if more than 1 LED needs to be powered from a single Arduino pin. Arduino pins can only supply about 40mA, which is just enough for 1 LED.

They work just like a relay.

The array is powered by the voltage regulator which will have enough power for all LEDs in the car.

 

IMG-5070-marked.jpg

A : Power in. Up to 40V. But since the Arduino only accepts 12V, this will be the max.

B :  Adjust the power output. Turn until 3.3V are displayed.

C : Displays the In or Out Voltage.

D Power Out: Precisely 3.3V to power blue/white LEDs directly. Red/Yellow/orange LEDs will need an additional 47 Ohm resistor.

E : The receivers for the additional light functions. 2 cables will be connected to the Arduino and 2 directly to power (Don't know yet where)

 

 

 

 

 

 

Edited by Jens
  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Oh man what an inspiration this is. This is  (besides different controls) the exact thing i wanted to do to my TRX4-Defender.

I've already got most if not all the hardware, but im such a noob as it comes to coding. So i managed to copy and paste some together. (will share below if possible), i managed to be able to read the PWM inputs but thats about it).

Also i've heavily modified the transmitter that came with it. (single 18650 cell for power. with night light, winch transmitter and the 4 channel transmitter built in. Can show pictures if need be.)

 

Thank you for showing me howto start all this, as this leaves great potential on the table for some nice fancy light stuff. 😄
Thanks again.

 

 

My non completed code. (Yes i did copy some found in this topic 🙂 )

 

//--------- Constants//
//------ Input Pin Assignment//
//--- Variable input//
const int InSteering        = 2;
const int InThrottle        = 4;
const int InGearbox         = 7;
//--- Binary input//
const int InRemote1         = 10; //PWM
const int InRemote2         = 11; //PWM
const int InRemote3         = 12;
const int InRemote4         = 13;
//------ Output Pin Assignment//
//--- Front//
const int OutBumper         = 3;  //PWM
const int OutHeadlights     = 5;  //PWM
const int OutBlinkersLeft   = 15;
const int OutBlinkersRight  = 16;
const int OutDaylight       = 17;
//--- Rear//
const int OutRear           = 6;  //PWM
const int OutReverse        = 19;
const int OutFog            = 18;
//--- Middle//
const int OutWheel          = 14;
const int OutLightbar       = 21;


//--- Serial monitor output names for debug
String S1 = "Throttle: ";
String S2 = " - Steering: ";
String S3 = " - Gearbox: ";



//--- Input values PWM and reset them
int long Steering     = 0;
int long Throttle     = 0;
int long Gearbox      = 0;

//--- Timeout for Pulse-in
unsigned long PulseTm  = 35000;


void setup() {
  Serial.begin(9600);


//-- Define Input Pins//
pinMode(InRemote1   ,INPUT_PULLUP);
pinMode(InRemote2   ,INPUT_PULLUP);
pinMode(InRemote3   ,INPUT_PULLUP);
pinMode(InRemote4   ,INPUT_PULLUP);
pinMode(InSteering  ,INPUT);
pinMode(InThrottle  ,INPUT);
pinMode(InGearbox   ,INPUT);

 //-- Define Output Pins//
pinMode(OutBumper         ,OUTPUT);
pinMode(OutHeadlights     ,OUTPUT);
pinMode(OutBlinkersLeft   ,OUTPUT);
pinMode(OutBlinkersRight  ,OUTPUT);
pinMode(OutDaylight       ,OUTPUT);
pinMode(OutRear           ,OUTPUT);
pinMode(OutReverse        ,OUTPUT);
pinMode(OutFog            ,OUTPUT);
pinMode(OutWheel          ,OUTPUT);
pinMode(OutLightbar       ,OUTPUT);


}

void loop() {
  Steering  = pulseIn(InSteering  , HIGH, PulseTm);
  Throttle  = pulseIn(InThrottle  , HIGH, PulseTm);
  Gearbox   = pulseIn(InGearbox   , HIGH, PulseTm);


//--- Print to serial monitor for debug
  Serial.print(S1 + Steering);
  Serial.print(S2 + Throttle);
  Serial.print(S3 + Gearbox);
  Serial.println();
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...