Proximity sensor to run another code

I am pretty new to Arduino and still learning, my question is, can you use a proximity sensor to activate a code already saved. I am into model trains and found a simulated welding code but would like to mount a proximity sensor in the engine house so when I back my train into the engine house the proximity sensor would "see" the train and start the simulated welding code. Then when the train leaves it would stop running the code. The coding is hard for me to understand and I dont think I could write one until I learn more. Please forgive me if this a dumb question.

Doing what was described is quite possible using a Arduino thingy.

So rather than just pointing out that this is in general, quite trivial to implement, you need to now cite - with Web links - what proximity sensor you propose to use, what code it is you have for the simulation, what Arduino you have and what other components you propose to use?

Also to the point - just what have you done so far with all this?

Right now I just have the Arduino Nano inside the Train building connected to a 5v source and it just goes all the time once I turn on the power. It just gets repetitive so that's why I wanted just to come on when sensed. I did not get the Idea till now.

int ledPin = 13; // LED connected to digital pin 13

void setup()
{
 pinMode(ledPin, OUTPUT);
}

void loop()
{
 int i,count;
 count=random(10,60);
 for (i=0;i<count;i++)
 {
  digitalWrite(ledPin, HIGH); // set the LED on
  delay(random(60));
  digitalWrite(ledPin, LOW); // set the LED off
  delay(random(200));
 }
 delay(random(800,2000)); // wait a random bit of time
}

Quick and dirty:

When you ground the prox pin, it should activate.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.