Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LED
- int fail;
- int pass;
- int recording;
- int p=500;
- //declration for mapping the delau potentiometer
- float s1;
- float s2;
- float s3;
- float s4;
- float s5;
- float s6;
- float s7;
- // declaration of "reading of delay"
- float Reading_Headup ;
- float Reading_Headdown ;
- float Reading_Holder ;
- float Reading_Rej ;
- float Reading_vblowon ;
- float Reading_vblowoff ;
- float Reading_ps;
- //declare the values
- float max_rej;
- float max_accept;
- float normal_value;
- //states of gb and rb declaration
- int state_prox;
- int state_GB;
- int state_RB;
- int state_test_button;
- //detect bottle
- //Scan for button
- //Take pressure readings
- //Pass fail test
- //flow, or kickout.
- // Record button Decleration
- int GB=7;
- int RB=9;
- int test_button=6;
- //pressure sensor Declearation
- int Ps = A7;
- //Delays Declatartion
- float DELAY_Headup =A4;
- float DELAY_Headdown =A1;
- float DELAY_Holder =A2;
- float DELAY_Rej =A3;
- float DELAY_vblowon =A5;
- float DELAY_vblowoff =A6;
- // valves Declearation
- int V_Rej = 22;
- int V_Head = 26;
- int V_Holder =28;
- int V_Blow =30;
- //status LED Declearation
- int Fail_LED=32;
- int Pass_LED=34;
- int Rec_LED=35;
- // proximity declaration
- int prox = 36 ;
- // Belt conveyor break
- int Belt_break = 38 ;
- void setup() {
- pinMode( Ps ,INPUT);
- pinMode( DELAY_Headdown ,INPUT); //potentiometer 1
- pinMode( DELAY_Headup ,INPUT); //potentiometer 2
- pinMode( DELAY_Holder ,INPUT);//potentiometer 3
- pinMode( DELAY_Rej ,INPUT);//potentiometer 4
- pinMode( prox ,INPUT);
- pinMode( DELAY_vblowon ,INPUT);//potentiometer 5
- pinMode( DELAY_vblowoff ,INPUT);//potentiometer 6
- pinMode( GB ,INPUT);
- pinMode( RB ,INPUT);
- pinMode (test_button,INPUT);
- pinMode ( Belt_break,OUTPUT);
- pinMode (Fail_LED,OUTPUT);
- pinMode (Pass_LED,OUTPUT);
- pinMode (Rec_LED,OUTPUT);
- }
- // Clear the currently stored maximum
- void clearReading(){
- prevReading = 0;
- }
- // Check for the current maximum and store it
- void updateReading(int curReading){
- if(prevReading < curReading)
- prevReading = curReading;
- }
- // Display the currently stored maximum
- void displayReading(){
- Serial.println(prevReading)
- }
- void loop() {
- Serial.begin(9600);
- state_GB = digitalRead(GB);
- state_RB = digitalRead(RB);
- state_prox=digitalRead (prox);
- state_test_button=digitalRead (test_button);
- state_prox==digitalRead (prox);
- clearReading();
- s1= map (Reading_Headup, 0 ,1023 ,0 , 10000); // max delay 10sec
- s2=map (Reading_Headdown, 0 ,1023 ,0 , 10000); // max delay 10sec
- s3= map (Reading_Holder, 0 ,1023 ,0 , 10000); // max delay 10sec
- s4=map (Reading_Rej, 0 ,1023, 0 , 10000); // max delay 10sec
- s5= map (Reading_vblowon, 0 ,1023, 0 , 10000);// max delay 10sec
- s6 = map(Reading_vblowoff ,0 ,1023 ,0,10000);// max delay 10sec
- s7=map (Reading_ps, 0 , 0.025 , 0,10);
- Reading_Headup = analogRead(DELAY_Headup) ;
- Reading_Headdown= analogRead(DELAY_Headdown) ;
- Reading_Holder= analogRead(DELAY_Holder) ;
- Reading_Rej= analogRead(DELAY_Rej) ;
- Reading_vblowon= analogRead(DELAY_vblowon) ;
- Reading_vblowoff= analogRead(DELAY_vblowoff) ;
- Reading_ps=analogRead(Ps);
- updateReading(Reading_ps);
- Serial.println("HEAD UP DELAY" ) ;
- Serial.println (s1);
- delay(10);
- //Serial.println("pressurereading=" ) ;
- //Serial.println ( s7);
- /*
- if(state_GB==HIGH)
- {
- Serial.println("GB ON");
- delay(p);
- }
- else {Serial.println("GB off");
- delay(p);
- }
- if(state_prox==HIGH)
- {
- Serial.println("prox ON");
- delay(p);
- }
- else {Serial.println("prox off");
- delay(p);
- }
- if(state_RB==HIGH)
- {Serial.println("RB ON");
- delay(p);
- }
- else {Serial.println("RB off");
- delay(p);
- }
- if(state_test_button==HIGH)
- {Serial.println("testing button on ");
- delay(p);
- }
- else {Serial.println("testing button off");
- delay(p);
- }
- */
- //MODE "1" RECORDING GOOD BOTTLE
- if (state_GB==HIGH && state_prox==HIGH )
- {
- Serial.println("REC_GOOD_MODE");
- digitalWrite (Pass_LED,HIGH);
- digitalWrite (Rec_LED,HIGH);
- delay(Reading_Headdown);
- digitalWrite(Belt_break,HIGH);
- digitalWrite( V_Head , HIGH);
- delay(Reading_Headup);
- delay( Reading_vblowon);
- digitalWrite( V_Blow , HIGH);
- delay(Reading_vblowoff);
- digitalWrite( V_Blow , LOW);
- delay(p);
- //max function has been added lately new adjustment date 27.4.2022
- max_accept=max(Reading_ps);
- if (reading_ps > oldReading){
- oldReading = Reading_ps;
- }
- if (digitalRead(A1)){
- Serial.println(oldReading);
- oldReading = 0;
- }
- digitalWrite( V_Head , LOW);
- digitalWrite(Belt_break,LOW);
- }
- //MODE2 RECORDING REJ BOTTLE
- if (state_RB==HIGH && state_prox==HIGH )
- {
- Serial.print("REC_REJ_MODE");
- digitalWrite(Fail_LED,HIGH);
- digitalWrite (Rec_LED,HIGH);
- delay(Reading_Headdown);
- digitalWrite(Belt_break,HIGH);
- digitalWrite( V_Head , HIGH);
- delay(Reading_Headup);
- delay( Reading_vblowon);
- digitalWrite( V_Blow , HIGH);
- delay(Reading_vblowoff);
- digitalWrite( V_Blow , LOW);
- //max function has been added lately new adjustment date 27.4.2022
- max_rej=max(Reading_ps);
- displayReading()
- delay( Reading_vblowoff);
- digitalWrite( V_Head , LOW);
- digitalWrite(Belt_break,LOW);
- delay( Reading_Rej);
- digitalWrite( V_Rej , HIGH);
- delay(100);
- digitalWrite( V_Rej ,LOW);
- }
- //MODE3 TESTING
- if ( state_test_button ==HIGH && state_prox ==HIGH)
- {
- Serial.println("testing");
- delay(Reading_Headdown);
- digitalWrite(Belt_break,HIGH);
- digitalWrite( V_Head , HIGH);
- delay(Reading_Headup);
- delay( Reading_vblowon);
- digitalWrite( V_Blow , HIGH);
- //max function has been added lately new adjustment date 27.4.2022 hoping i doen't get the 3 values the same
- normal_value==Reading_ps;
- delay(Reading_vblowoff);
- digitalWrite( V_Blow , LOW);
- if( normal_value>=max_accept || max_rej<normal_value <= max_accept )
- {
- digitalWrite (Pass_LED,HIGH);
- digitalWrite( V_Head , LOW);
- digitalWrite(Belt_break,LOW);
- }
- else if(normal_value<=max_rej )
- {
- digitalWrite(Fail_LED,HIGH);
- digitalWrite( V_Head , LOW);
- digitalWrite(Belt_break,LOW);
- delay( Reading_Rej);
- digitalWrite( V_Rej , HIGH);
- delay(100);
- digitalWrite( V_Rej ,LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement