I was tasked by a friend to make a lighting system for atv drag races.
i have eventually decided that i needed an arduino to be able to do what im looking for and have never done any coding at all.
i have watched a few basic toutorials to get some bacics and believe thisd may get me somewhere.
i do not yet have an arduino to try the code out on and figured i could throw it on here and get some sudgestions.
function--
i want there to be one operator with one on off switch.
when the switch in the off position all lights will be off except the yellow staging light.
once the switch is turned on the yellow goes out and the green start light is on
if the left or right lane triggers a photoelectric switch at the start line before the light is green it lights a corresponding red light for the lane.
the first lane to the finish lights a corresponding orange light to show who crossed the finish line first using a photoelectric sensor giving voltage as they pass it
once the race is over the switch is turned off and all lights are turned off except the yellow staging light.
any and all input is appriciated. like i said i might have watches 2 hours of youtube videos so this may be pretty bad. just had a feeling i may be close.
In the Arduino IDE, use CtrlT or CMDT to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
int trigger = 1;
int yellow = 2;
int green = 3;
int redL = 4;
int redR = 5; // pin numbers are random at this point
int orangeL = 6;
int orangeR = 7;
int SL1 = 8; // all outputs will be connected to relays to control lights
int SL2 = 9;
int SR1 = 10;
int SR2 = 11;
void setup() {
pinMode(trigger, INPUT); // on/off switch
pinMode(SL1, INPUT); // first photoelectric sensir left lane
pinMode(SL2, INPUT); // second photoelectric sensir left lane
pinMode(SR1, INPUT); // first photoelectric sensir right lane
pinMode(SR2, INPUT); // second photoelectric sensir right lane
pinMode(yellow, OUTPUT); // yellow staging light
pinMode(green, OUTPUT); // green start light
pinMode(redL, OUTPUT); // left lane advanced start
pinMode(redR, OUTPUT); // right lane advanced start
pinMode(orangeL, OUTPUT); // left lane finished first
pinMode(orangeR, OUTPUT); // right lane finished first
}
void loop()
{
if (digitalRead(trigger) == LOW) {
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(redL, LOW); // switch off - all lights except staging light off
digitalWrite(redR, LOW);
digitalWrite(orangeL, LOW);
digitalWrite(orangeR, LOW);
}
{
if (digitalRead(trigger) == HIGH) {
digitalWrite(yellow, LOW); // switch on - staging light off and green start light on
digitalWrite(green, HIGH);
}
}
{
if (digitalRead(SL1) == HIGH && yellow == HIGH) {
digitalWrite(redL, HIGH); // activation for left lane early start
delay(10000);
}
else {
digitalWrite(redL, LOW);
}
{
if (digitalRead(SR1) == HIGH && yellow == HIGH) {
digitalWrite(redR, HIGH); // activation for left lane early start
delay(10000);
}
else {
digitalWrite(redR, LOW);
}
{
if (digitalRead(SL2) == HIGH && (green == HIGH) && (orangeR == LOW) {
digitalWrite(orangeL, HIGH); // win light for left lane
delay(8000);
}
else {
digitalWrite(orangeL, LOW);
}
{
if (digitalRead(SR2) == HIGH && (green == HIGH) && (orangeL == LOW) {
digitalWrite(orangeR, HIGH); // win light for right lane
delay(8000);
}
else {
digitalWrite(orangeR, LOW);
}
}
These 'if' statements won't work because you are comparing constants (2, 3, 6, and 7) to the constant 'HIGH" (1) and none of them will ever match. You can, in most cases, read the state of an output pin with digitalRead(pin) so you can change yellow == HIGH to digitalRead(yellow) == HIGH. Another solution is to keep a variable with the last state you wrote:
the wiring diagram that i drew up was done before i realized that you could buy specific relay modules and i have one ordered.
also i am trying to decide what style of beam sensor would work best.
reflector style means all wiring will be able to be placed between racing lanes but may be less accurate and harder to align (this is intended to be a mobile set up)
however if i need to use the transmitter and receiver style i will need to power the two transmitters on the outside of the left lane and right lane independently of the main system.