// This code is based on 14 coils 5 sets (5 8j Hallpin and 5 Transpin).
// Code is developed by Subhankar Chakraborty.
// Do not copy this code, it may leads to accident.
// Code never lies..
// defines variables
long duration;
int distance1=0;
int distance2=0;
int distance3=0;
float Acceleration;
double Speed1=0;
double Speed2=0;
double Speed3=0;
int distance=0;
//Declaring the pins for Hall effect sensor:
int Zero_Value = 0;
int Hallpin1 = 2; // Hall effect sensor pin
int Hallpin2 = 23; // Hall effect sensor pin
int Hallpin3 = 27; // Hall effect sensor pin
int Hallpin4 = 6; // Hall effect sensor pin
int Hallpin5 = 7; // Hall effect sensor pin
//const int trigPin = 12; // Ultrasonic Sensor pin
//const int echoPin = 13; // Ultrasonic Sensor pin
// Declaring the pins for Mosfet(Transistor):
int Transpin1 = 22; // Mosfet pin
int Transpin2 = 24; // Mosfet pin
int Transpin3 = 26; // Mosfet pin
int Transpin4 = 11; // Mosfet pin
int Transpin5 = 12; // Mosfet pin
//Declaring the initial state for Hall effect sensor:
int Hallstate1 = 0; // Setting the initial value for Hall effect sensor
int Hallstate2 = 0; // Setting the initial value for Hall effect sensor
int Hallstate3 = 0; // Setting the initial value for Hall effect sensor
int Hallstate4 = 0; // Setting the initial value for Hall effect sensor
int Hallstate5 = 0; // Setting the initial value for Hall effect sensor
//The main setup
void setup(){
Serial.begin(9600);
pinMode(Hallpin1, INPUT); //Asking arduino to take the value of this pin as input
pinMode(Hallpin2, INPUT); //Asking arduino to take the value of this pin as input
//pinMode(Hallpin3, INPUT); //Asking arduino to take the value of this pin as input
//pinMode(Hallpin4, INPUT); //Asking arduino to take the value of this pin as input
//pinMode(Hallpin5, INPUT); //Asking arduino to take the value of this pin as input
pinMode(Transpin1, OUTPUT); //Asking arduino to give the output of the respective pin
pinMode(Transpin2, OUTPUT); //Asking arduino to give the output of the respective pin
//pinMode(Transpin3, OUTPUT); //Asking arduino to give the output of the respective pin
//pinMode(Transpin4, OUTPUT); //Asking arduino to give the output of the respective pin
//pinMode(Transpin5, OUTPUT); //Asking arduino to give the output of the respective pin
}
/*float ultrasonicRead ()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(100);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
//calculating distance
distance= duration*0.034/2;
Serial.print("Acceleration in cm/s2 : ");
Serial.println(Acceleration);
return distance;
}
*/
//Looping the main setup
void loop(){
Hallstate1 = digitalRead(Hallpin1); //Reading the initial state and if there any change in state
Hallstate2 = digitalRead(Hallpin2); //Reading the initial state and if there any change in state
//Hallstate3 = digitalRead(Hallpin3); //Reading the initial state and if there any change in state
//Hallstate4 = digitalRead(Hallpin4); //Reading the initial state and if there any change in state
//Hallstate5 = digitalRead(Hallpin5); //Reading the initial state and if there any change in state
//Serial.print(Hallstate1);
//Serial.println();
/*//calculating Speed
distance1 = ultrasonicRead(); //calls ultrasoninicRead() function below
delay(100);//giving a time gap of 0.1 sec
distance2 = ultrasonicRead(); //calls ultrasoninicRead() function below
delay(100);
distance3 = ultrasonicRead();
Serial.print("Distance1 in cm :");
Serial.println(distance1);
Serial.print("Distance2 in cm :");
Serial.println(distance2);
Serial.print("Distance3 in cm :");
Serial.println(distance3);
//formula change in distance divided by change in time
Speed1 = (distance2 - distance1)/0.1; //as the time gap is 1 sec we divide it by 1.
Speed2 = (distance3-distance2)/0.1;
Speed3 = (distance3-distance1)/duration;
//acceleration
Acceleration = ( Speed2-Speed1)/2;
//Displaying Speed
Serial.print("Speed in cm/s :");
Serial.println(Speed1);*/
if (Hallstate1 == LOW){
digitalWrite(Transpin1, HIGH);
Serial.print("Detected1");
//delay(100);
Serial.println();
}
/*else if (Hallstate2 == LOW){
digitalWrite(Transpin2, HIGH);
Serial.print("Detected2");
delay(5000);
Serial.print("done");
Serial.println();
}
/*else if (Hallstate3 == LOW){
digitalWrite(Transpin3, HIGH);
Serial.print("Detected3");
Serial.println();
}*/
/*else if (Hallstate4 == LOW){
digitalWrite(Transpin4, HIGH);
Serial.print("Detected4");
Serial.println();
}
else if (Hallstate5 == LOW){
digitalWrite(Transpin5, HIGH);
Serial.print("Detected5");
Serial.println();
}*/
else{
digitalWrite(Transpin1, LOW);
digitalWrite(Transpin2, LOW);
//digitalWrite(Transpin3, LOW);
//digitalWrite(Transpin4, LOW);
//digitalWrite(Transpin5, LOW);``
}
}
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.