Hello,
I'm trying to make vehicles that can be recognize for a layout, I have 3 halls and want to lichtup seven LEDs so BYTE control basically, but it will not work with me, can somebody help me on the right track.
If the car runs over de halls the wrong ID coms treu, because of the problem that not all halls will respons or be active by the car, example,
Car 7,
First read out is Car 1
than 2 times car 7 (THATS RIGHT But it must by once) But i can live with this.
Thanx in advance
4 read out gives car 5
the first and last car is randomize not always the same, he does it 3 to 4 times good and then he gives a different readout But there is not car 7. :~
Programming.
/*
Hall sensor schakeling EMV test modelbaan
Schakelt (IR-)LED's aan en uit m.b.v. hall sensoren
Schema: Willy van As
Principe
* LED van pin via weerstand 220 aan aarde
* Hall sensor aan pin met pull up weerstand van 10k
*/
// set pin numbers:
const int HS1Pin = 5; // the number of the Hall 1 sensor pin Sleepcontact
const int HS2Pin = 2; // the number of the Hall 2 sensor pin Voertuigen herkenning
const int HS3Pin = 3; // the number of the Hall 3 sensor pin Voertuigen herkenning
const int HS4Pin = 4; // the number of the Hall 4 sensor pin Voertuigen herkenning
const int IR1Pin = 6; // the number of the LED 1 pin Sleepcontact (Groen)
const int IR2Pin = 7; // the number of the LED 2 pin Voertuig 1 (Groen)
const int IR3Pin = 8; // the number of the LED 3 pin Voertuig 2 (Groen)
const int IR4Pin = 9; // the number of the LED 4 pin Voertuig 3 (Groen)
const int IR5Pin = 10; // the number of the LED 5 pin Voertuig 4 (Geel)
const int IR6Pin = 11; // the number of the LED 6 pin Voertuig 5 (Geel)
const int IR7Pin = 12; // the number of the LED 7 pin Voertuig 6 (Geel)
const int IR8Pin = 13; // the number of the LED 8 pin Voertuig 7 (Geel)
// variables will change:
int HS1State = 0; // variable for reading the Hall 1 status
int HS2State = 0; // variable for reading the Hall 2 status
int HS3State = 0; // variable for reading the Hall 3 status
int HS4State = 0; // variable for reading the Hall 4 status
long time = 0;
long debounce = 1;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(IR1Pin, OUTPUT); // Sleepcontact
pinMode(IR2Pin, OUTPUT); // Voertuig 1 001 HS2
pinMode(IR3Pin, OUTPUT); // Voertuig 2 010 HS3
pinMode(IR4Pin, OUTPUT); // Voertuig 3 100 HS4
pinMode(IR5Pin, OUTPUT); // Voertuig 4 011 HS2 en HS3
pinMode(IR6Pin, OUTPUT); // Voertuig 5 101 HS2 en HS4
pinMode(IR7Pin, OUTPUT); // Voertuig 6 110 HS3 en HS4
pinMode(IR8Pin, OUTPUT); // Voertuig 7 111 HS2 en HS3 en HS4
// initialize the Hall sensor pin as an input:
pinMode(HS1Pin, INPUT_PULLUP);
pinMode(HS2Pin, INPUT_PULLUP);
pinMode(HS3Pin, INPUT_PULLUP);
pinMode(HS4Pin, INPUT_PULLUP);
}
void loop(){
// Read HS 1 Sleepcontact herkenning
HS1State = digitalRead(HS1Pin);
if (HS1State == LOW) {
// turn IR1 on:
digitalWrite(IR1Pin, HIGH); //Voertuig sleeper herkend
Serial.println("-----------------------------");
Serial.println("Sleper gezien van voertuig");
}
else {
// turn LED off:
digitalWrite(IR1Pin, LOW); // Sleeper weg
}
// Voertuigen herkennings tabel.
HS2State = digitalRead(HS2Pin);
HS3State = digitalRead(HS3Pin);
HS4State = digitalRead(HS4Pin);
// Read HS2
delay(4);
if (HS2State == LOW && HS3State == HIGH && HS4State == HIGH && millis() - time > debounce) { //Voertuig 1 Bit 100
// turn IR2 on:
digitalWrite(IR2Pin, HIGH);
Serial.println("Voertuig type 1 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR2Pin, LOW);
}
// Read HS3
delay(4);
if (HS2State == HIGH && HS3State == LOW && HS4State == HIGH && millis() - time > debounce) { //Voertuig 2 Bit 010
// turn IR3 on:
digitalWrite(IR3Pin, HIGH);
Serial.println("Voertuig type 2 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR3Pin, LOW);
}
// Read HS4
delay(4);
if (HS2State == HIGH && HS3State == HIGH && HS4State == LOW && millis() - time > debounce) { //Voeruig 3 Bit 001
// turn IR4 on:
digitalWrite(IR4Pin, HIGH);
Serial.println("Voertuig type 3 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR4Pin, LOW);
}
// Read Halss HS2 and HS3 110
delay(4);
if (HS2State == LOW && HS3State == LOW && HS4State ==HIGH && millis() - time > debounce) { //Voertuig 4 Bit 110
// turn IR5 on:
digitalWrite(IR5Pin, HIGH);
Serial.println("Voertuig type 4 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR5Pin, LOW);
}
HS1State = digitalRead(HS1Pin);
if (HS1State == LOW) {
// turn IR1 on:
digitalWrite(IR1Pin, HIGH); //Voertuig sleeper herkend
Serial.println("-----------------------------");
Serial.println("Sleper gezien van voertuig");
}
else {
// turn LED off:
digitalWrite(IR1Pin, LOW); // Sleeper weg
}
// Read halls HS2 and HS4 101
delay(4);
if (HS2State == LOW && HS3State == HIGH && HS4State == LOW && millis() - time > debounce) { //Voeruig 5 Bit 101
// turn IR6 on:
digitalWrite(IR6Pin, HIGH);
Serial.println("Voertuig type 5 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR6Pin, LOW);
}
// Read the halls HS3 and HS4 011
delay(4);
if (HS2State == HIGH && HS3State == LOW && HS4State == LOW && millis() - time > debounce) { //Voeruig 6 Bit 011
// turn IR7 on:
digitalWrite(IR7Pin, HIGH);
Serial.println("Voertuig type 6 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR7Pin, LOW);
}
//Read the halls HS2 and HS3 and HS4 111
delay(4);
if (HS2State == LOW && HS3State == LOW && HS4State == LOW && millis() - time > debounce) { //Voeruig 7 Bit 111
// turn IR8 on:
digitalWrite(IR8Pin, HIGH);
Serial.println("Voertuig type 7 gepasseerd");
}
else {
// turn LED off:
digitalWrite(IR8Pin, LOW);
}
// Serial.println(" ");
// delay(27);
// delay(4);
}