Arduino act strange as I pull the cable out

Hi everyone, I was recently finished with my project which is an egg´s reader, the purpose of this project is to analize the eggs and tell if the egg is fertile and the chicken is alive - the egg was fertile but the chicken is dead - the egg was not fertile, the egg is empty.
the methode I have used is with light and LDR, a 3W led is inside a suction cup that bright on top of the egg (the suction cup prevent direct light on the LDR) and the LDR that are all around the egg will determine what is going on in the eggs.
I´ll copy-paste part of the sketch and upload some pictures of the projekt at the end of the text so that is more understandable.

I tested the machine with a single head and it worked.

The problem comes when the arduino is not connected to the computer, it act weird and random, I would try in this order: I monitor one egg with the serial monitor, the egg is unfertile so not sign of moviment on the serial monitor, I check the arduino nano (I set the led_builtin to turn on as soon as the feedback(ALIVE) turn on so that I can check in advance what is going on) and the led_builtin is off as expected, I pull the cable off and I try again, after few seconds the arduino nano would send a feedback to arduino mesa with no reasons, so I check again with the cable and the program seems working good and I tried 10 times in a row like this with the same result.

the program consist that the arduino nano reads the value all the times and eventually gives a feedback once the threshold is achieved, everything would reset as soon as I push the button that start the program on arduino mega ( it will count up to 20 sec and then read all the feedback) but no problem with arduino mega, everything works as it should.

I power up the led with a separate power supply and power up the arduino with a battery as showned in picture (I hade bad experiance with arduino going crazy as soon as I was testing it with the cable in, that´s why I used a pure power supply for testing)

My first get is that somewhere the is no proper grounding but I checked so many time the wiring with no success.








I forgot the scketch:

                          //SINGLE SENSORS

long SensorValue1;
long Lowpeak1 = 0;
long SensorValue2;
long Lowpeak2 = 0;
long SensorValue3;
long Lowpeak3 = 0;
long SensorValue4;
long Lowpeak4 = 0;
//SENSORS GROUPS
long SensorG1;
long Lowpeak5 = 0;
long SensorG2;
long Lowpeak6 = 0;
long SensorG3;
long Lowpeak7 = 0;
long SensorG4;
long Lowpeak8 = 0;

int Moviment1 ;
int Moviment2 ;
int Moviment3 ;
int Moviment4 ;
int Moviment5 ;
int Moviment6 ;
int Moviment7 ;
int Moviment8 ;

int Reset = 2; //START/RESET signal from arduino mega
int feedback = 3; //DEAD / LIVE chicken signal from arduino nano
int startcyclus;

int led1 = LED_BUILTIN;

unsigned long CurrentTime;

unsigned long PreviusTime1;
unsigned long PreviusTime2;
unsigned long PreviusTime3;
unsigned long PreviusTime4;
unsigned long PreviusTime5;
unsigned long PreviusTime6;
unsigned long PreviusTime7;
unsigned long PreviusTime8;
unsigned long PreviusTime9;

const unsigned long calculation = 20000 ; //intervallo usato per la durata del controllo delle uova
const unsigned long maxtime = 2000 ; //tempo massimo tra ogni rilevamento di movimento

void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(A6, INPUT);
pinMode(A7, INPUT);

pinMode(led1, OUTPUT);

pinMode(Reset, INPUT);
pinMode(feedback, OUTPUT);
digitalWrite(Reset, LOW);
digitalWrite(feedback, LOW);
digitalWrite(led1, LOW);
}

void loop() {
CurrentTime = millis();
SensorValue1 = analogRead(A0);
SensorValue2 = analogRead(A1);
SensorValue3 = analogRead(A2);
SensorValue4 = analogRead(A3);
SensorG1 = analogRead(A4);
SensorG2 = analogRead(A5);
SensorG3 = analogRead(A6);
SensorG4 = analogRead(A7);

digitalWrite(startcyclus, LOW);

if (digitalRead(Reset) == HIGH) { // se schiaccio start
Lowpeak1 = SensorValue1;
Lowpeak2 = SensorValue2;
Lowpeak3 = SensorValue3;
Lowpeak4 = SensorValue4;
Lowpeak5 = SensorG1;
Lowpeak6 = SensorG2;
Lowpeak7 = SensorG3;
Lowpeak8 = SensorG4; // il treshold cambia riportando tutti i lowpeak ad i valori attuali dei sensori

Moviment1 = 0;
Moviment2 = 0;
Moviment3 = 0;
Moviment4 = 0;
Moviment5 = 0;
Moviment6 = 0;
Moviment7 = 0;
Moviment8 = 0;

// digitalWrite(led, LOW);
digitalWrite(feedback, LOW);
Serial.print("reset");
Serial.println(Reset);

delay(10);
digitalWrite(Reset, LOW);
digitalWrite(led1, LOW);
digitalWrite(feedback, LOW);
delay(10);
digitalWrite(feedback, LOW);

PreviusTime1 = CurrentTime ;
PreviusTime2 = CurrentTime ;
PreviusTime3 = CurrentTime ;
PreviusTime4 = CurrentTime ;
PreviusTime5 = CurrentTime ;
PreviusTime6 = CurrentTime ;
PreviusTime7 = CurrentTime ;
PreviusTime8 = CurrentTime ;
PreviusTime9 = CurrentTime ;

}

                                                                                                                   //SENSOR 1

if (Lowpeak1 < 10) { //se il lowpeak é minore di 10
Lowpeak1 = SensorValue1; //il lowpeak diventa il valore del sensore
}

if (SensorValue1 < Lowpeak1) { //faccio un update del lowpeak in caso il valore del sensore sia sceso
Lowpeak1 = SensorValue1;
PreviusTime1 = CurrentTime;
}

if ((SensorValue1 - Lowpeak1) >= 3 ){

  Moviment1 = Moviment1 + 1;
  Lowpeak1 = SensorValue1;                    //riporto il lowpeak al valore attuale del sensore
  PreviusTime1 = CurrentTime;
  delay(30);

}

if ((CurrentTime - PreviusTime1 >= maxtime) && (Lowpeak1 != SensorValue1)){ //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
//riporto il lowpeak al valore attuale del sensore
Lowpeak1 = SensorValue1; //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
PreviusTime1 = CurrentTime; //I reset previus time to the value of millis
Serial.println("TOO LONG1");
}

if (Moviment1 >= 5){
digitalWrite(feedback, HIGH);
digitalWrite(led1, HIGH);
// Serial.print("chicken alive");
//Serial.print(digitalRead(feedback));

}

SensorValue1 = analogRead(A0); //I read the value of the sensor
Serial.print("S1:");
Serial.print(SensorValue1);
Serial.print("-L1:");
Serial.print(Lowpeak1);
Serial.print("-M1:");
Serial.print(Moviment1);
Serial.print(" /*/ ");

//Serial.print(" - FEEDBACK :");
//Serial.print(digitalRead (feedback));
//Serial.print(" - start :");
//Serial.println(digitalRead (Reset));

Hello
did you check that all power supplies and used hardware components are connected to a common ground ?
Does your power supply is able to support you system with enought energy?

Just checke the grounding and it looks good.

Well it´s 2A for 10 arduino, the only ouput is led, 18 led which only 9 turn on at the same time, I would say it´s more than enough.

9 leds of 3 watts consume 5.4 A on 5V.

I might have explained wrong, I have 9 (3W) led which are separately power supplied.
the led that are supplied with arduino are just common diode , in the picture you can see them in a white case with round hole.

Your OP was quite long, maybe I did not look carefully enough.

I've seen many false claims on power supplies, did you test its capabilities?

The lines between the Mega and Nano are serial ?

Then you need pull_up_ resistors to 5V, not pull_down_s. Serial wires idle HIGH.

from mega to nano are just 2 digital signal for basic istruction.
could you explain that bette? do I need a resistor from 5v to ground? how big resistor and why?

what´s the best method you recommend to check the supply?

make some measurements ?

Hi, @tocco
Welcome to the forum.

To add code please click this link;

Do you have a DMM to measure the 5V on each of the Nanos.
If you just have one egg unit powered up, does the fault still occur.

A thanks for the informative pics and description of your project. :+1:

A more informative schematic would help with pin numbers and hardware labels.
Just draw a couple of LDRs and label the other inputs to the Nano that they are from the other LDRs in your project.

What communication system are you using between the Mega and the Nanos.
If RS232 the Mega only has 4 UARTs, are you using software serial library as well?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:


long SensorValue1;
long Lowpeak1 = 0;
long SensorValue2;
long Lowpeak2 = 0;
long SensorValue3;
long Lowpeak3 = 0;
long SensorValue4;
long Lowpeak4 = 0;
//SENSORS GROUPS
long SensorG1;
long Lowpeak5 = 0;
long SensorG2;
long Lowpeak6 = 0;
long SensorG3;
long Lowpeak7 = 0;
long SensorG4;
long Lowpeak8 = 0;

int Moviment1 ;
int Moviment2 ;
int Moviment3 ;
int Moviment4 ;
int Moviment5 ;
int Moviment6 ;
int Moviment7 ;
int Moviment8 ;

int Reset = 2;                  //START/RESET signal from arduino mega
int feedback = 3;                 //DEAD / LIVE chicken signal from arduino nano
int startcyclus;

int led1 = LED_BUILTIN;


unsigned long CurrentTime;

unsigned long PreviusTime1;
unsigned long PreviusTime2;
unsigned long PreviusTime3;
unsigned long PreviusTime4;
unsigned long PreviusTime5;
unsigned long PreviusTime6;
unsigned long PreviusTime7;
unsigned long PreviusTime8;
unsigned long PreviusTime9;

const unsigned long calculation = 20000 ;                   //intervallo usato per la durata del controllo delle uova
const unsigned long maxtime = 2000 ;                   //tempo massimo tra ogni rilevamento di movimento

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
  pinMode(A6, INPUT);
  pinMode(A7, INPUT);

  pinMode(led1, OUTPUT);

  pinMode(Reset, INPUT);
  pinMode(feedback, OUTPUT);
  digitalWrite(Reset, LOW);
  digitalWrite(feedback, LOW);
  digitalWrite(led1, LOW);
}

void loop() {
  CurrentTime = millis();
  SensorValue1 = analogRead(A0);
  SensorValue2 = analogRead(A1);
  SensorValue3 = analogRead(A2);
  SensorValue4 = analogRead(A3);
  SensorG1 = analogRead(A4);
  SensorG2 = analogRead(A5);
  SensorG3 = analogRead(A6);
  SensorG4 = analogRead(A7);

  digitalWrite(startcyclus, LOW);

  if (digitalRead(Reset) == HIGH) {              // se schiaccio start
    Lowpeak1 = SensorValue1;
    Lowpeak2 = SensorValue2;
    Lowpeak3 = SensorValue3;
    Lowpeak4 = SensorValue4;
    Lowpeak5 = SensorG1;
    Lowpeak6 = SensorG2;
    Lowpeak7 = SensorG3;
    Lowpeak8 = SensorG4;                    // il treshold cambia riportando tutti i lowpeak ad i valori attuali dei sensori

    Moviment1 = 0;
    Moviment2 = 0;
    Moviment3 = 0;
    Moviment4 = 0;
    Moviment5 = 0;
    Moviment6 = 0;
    Moviment7 = 0;
    Moviment8 = 0;
    //  digitalWrite(led, LOW);
    digitalWrite(feedback, LOW);
    Serial.print("reset");
    Serial.println(Reset);

    delay(10);
    digitalWrite(Reset, LOW);
    digitalWrite(led1, LOW);
    digitalWrite(feedback, LOW);
    delay(10);
    digitalWrite(feedback, LOW);

    PreviusTime1 = CurrentTime ;
    PreviusTime2 = CurrentTime ;
    PreviusTime3 = CurrentTime ;
    PreviusTime4 = CurrentTime ;
    PreviusTime5 = CurrentTime ;
    PreviusTime6 = CurrentTime ;
    PreviusTime7 = CurrentTime ;
    PreviusTime8 = CurrentTime ;
    PreviusTime9 = CurrentTime ;


  }







  //SENSOR 1


  if (Lowpeak1 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak1 = SensorValue1;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorValue1 < Lowpeak1) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak1 = SensorValue1;
    PreviusTime1 = CurrentTime;
  }




  if ((SensorValue1 - Lowpeak1) >= 3 ) {


    Moviment1 = Moviment1 + 1;
    Lowpeak1 = SensorValue1;                    //riporto il lowpeak al valore attuale del sensore
    PreviusTime1 = CurrentTime;
    delay(30);

  }



  if ((CurrentTime - PreviusTime1 >= maxtime) && (Lowpeak1 != SensorValue1)) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak1 = SensorValue1;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime1 = CurrentTime;                  //I reset previus time to the value of millis
    Serial.println("TOO LONG1");
  }



  if (Moviment1 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorValue1 = analogRead(A0);                          //I read the value of the sensor
  Serial.print("S1:");
  Serial.print(SensorValue1);
  Serial.print("-L1:");
  Serial.print(Lowpeak1);
  Serial.print("-M1:");
  Serial.print(Moviment1);
  Serial.print("  /*/  ");

  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));




  //SENSOR 2



  if (Lowpeak2 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak2 = SensorValue2;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorValue2 < Lowpeak2) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak2 = SensorValue2;
    PreviusTime2 = CurrentTime;
  }




  if ((SensorValue2 - Lowpeak2) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment2 = Moviment2 + 1;
    Lowpeak2 = SensorValue2;
    PreviusTime2 = CurrentTime;                              //riporto il lowpeak al valore attuale del sensore

    delay(30);
  }

  if (CurrentTime - PreviusTime2 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak2 = SensorValue2;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime2 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG2");
  }

  if (Moviment2 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorValue2 = analogRead(A1);                          //leggo il valore del sensore in questo istante

  Serial.print("S2:");
  Serial.print(SensorValue2);
  Serial.print("-L2:");
  Serial.print(Lowpeak2);
  Serial.print("-M2:");
  Serial.print(Moviment2);
  Serial.print("  /*/  ");


  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));






  //SENSOR 3



  if (Lowpeak3 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak3 = SensorValue3;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorValue3 < Lowpeak3) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak3 = SensorValue3;
    PreviusTime3 = CurrentTime;
  }




  if ((SensorValue3 - Lowpeak3) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment3 = Moviment3 + 1;
    Lowpeak3 = SensorValue3;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime3 = CurrentTime;
    delay(30);
  }

  if (CurrentTime - PreviusTime3 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak3 = SensorValue3;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime3 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG3");
  }



  if (Moviment2 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorValue3 = analogRead(A2);                          //leggo il valore del sensore in questo istante
  Serial.print("S3:");
  Serial.print(SensorValue3);
  Serial.print("-L3:");
  Serial.print(Lowpeak3);
  Serial.print("-M3:");
  Serial.print(Moviment3);
  Serial.print("  /*/  ");


  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));


  //SENSOR 4



  if (Lowpeak4 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak4 = SensorValue4;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorValue4 < Lowpeak4) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak4 = SensorValue4;
    PreviusTime4 = CurrentTime;
  }




  if ((SensorValue4 - Lowpeak4) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment4 = Moviment4 + 1;
    Lowpeak4 = SensorValue4;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime4 = CurrentTime;

    delay(30);
  }


  if (CurrentTime - PreviusTime4 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak4 = SensorValue4;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime4 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG4");
  }



  if (Moviment4 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorValue4 = analogRead(A3);                          //leggo il valore del sensore in questo istante
  Serial.print("S4:");
  Serial.print(SensorValue4);
  Serial.print("-L4:");
  Serial.print(Lowpeak4);
  Serial.print("-M4:");
  Serial.print(Moviment4);
  Serial.print("  /*/  ");


  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));






  //SENSOR GROUP 1

  if (Lowpeak5 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak5 = SensorG1;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorG1 < Lowpeak5) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak5 = SensorG1;
    PreviusTime5 = CurrentTime;
  }




  if ((SensorG1 - Lowpeak5) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment5 = Moviment5 + 1;
    Lowpeak5 = SensorG1;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime5 = CurrentTime;

    delay(30);
  }

  if (CurrentTime - PreviusTime5 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak5 = SensorG1;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime5 = CurrentTime;                  //riporto il previus time al valore del millis
    //  Serial.println("TOO LONG5");
  }


  if (Moviment5 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorG1 = analogRead(A4);                          //leggo il valore del sensore in questo istante
  Serial.print("SG1:");
  Serial.print(SensorG1);
  Serial.print("-L5:");
  Serial.print(Lowpeak5);
  Serial.print("-M5:");
  Serial.print(Moviment5);
  Serial.print("  /*/  ");


  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));







  //SENSOR GROUP 2

  if (Lowpeak6 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak6 = SensorG2;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorG2 < Lowpeak6) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak6 = SensorG2;
    PreviusTime6 = CurrentTime;
  }




  if ((SensorG2 - Lowpeak6) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment6 = Moviment6 + 1;
    Lowpeak6 = SensorG2;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime6 = CurrentTime;
    delay(30);
  }

  if (CurrentTime - PreviusTime6 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak6 = SensorG2;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime6 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG6");
  }

  if (Moviment6 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorG2 = analogRead(A5);                          //leggo il valore del sensore in questo istante
  Serial.print("SG2:");
  Serial.print(SensorG2);
  Serial.print("-L6:");
  Serial.print(Lowpeak6);
  Serial.print("-M6:");
  Serial.print(Moviment6);
  Serial.print("  /*/  ");



  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));








  //SENSOR GROUP 3

  if (Lowpeak7 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak7 = SensorG3;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorG3 < Lowpeak7) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak7 = SensorG3;
    PreviusTime7 = CurrentTime;
  }




  if ((SensorG3 - Lowpeak7) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment7 = Moviment7 + 1;
    Lowpeak7 = SensorG3;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime7 = CurrentTime;

    delay(30);
  }


  if ((CurrentTime - PreviusTime7) >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak7 = SensorG3;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime7 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG7");
  }


  if (Moviment7 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorG3 = analogRead(A6);                          //leggo il valore del sensore in questo istante
  Serial.print("SG3:");
  Serial.print(SensorG3);
  Serial.print("-L7:");
  Serial.print(Lowpeak7);
  Serial.print("-M7:");
  Serial.print(Moviment7);
  Serial.print("  /*/  ");



  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));







  //SENSOR GROUP 4

  if (Lowpeak8 < 10) {                     //se il lowpeak é minore di 10
    Lowpeak8 = SensorG4;                    //il lowpeak diventa il valore del sensore
  }




  if (SensorG4 < Lowpeak8) {                              //faccio un update del lowpeak in caso il valore del sensore sia sceso
    Lowpeak8 = SensorG4;
    PreviusTime8 = CurrentTime;
  }




  if ((SensorG4 - Lowpeak8) >= 3) {                       //se il valore del sensore diventa di 2 piú grande del lowpeak

    Moviment8 = Moviment8 + 1;
    Lowpeak8 = SensorG4;                                  //riporto il lowpeak al valore attuale del sensore
    PreviusTime8 = CurrentTime;

    delay(30);
  }


  if (CurrentTime - PreviusTime8 >= maxtime) {        //se entro il tempo settato come maxtime non succede nulla, ovvero nessun movimento é stato rilevato,
    //riporto il lowpeak al valore attuale del sensore
    Lowpeak8 = SensorG4;                    //cosí che ogni eventuale piccolo innalzamento dei valori non implichi sul risultato di un uovo non ferile
    PreviusTime8 = CurrentTime;                  //riporto il previus time al valore del millis
    // Serial.println("TOO LONG8");
  }


  if (Moviment8 >= 5) {
    digitalWrite(feedback, HIGH);
    digitalWrite(led1, HIGH);
    // Serial.print("chicken alive");
    //Serial.print(digitalRead(feedback));


  }
  SensorG4 = analogRead(A7);                          //leggo il valore del sensore in questo istante
  Serial.print("SG4:");
  Serial.print(SensorG4);
  Serial.print("-L8:");
  Serial.print(Lowpeak8);
  Serial.print("-M8:");
  Serial.print(Moviment8);
  Serial.println("  /*/  ");



  //Serial.print(" - FEEDBACK :");
  //Serial.print(digitalRead (feedback));
  //Serial.print(" - start :");
  //Serial.println(digitalRead (Reset));






  //CHECK

  //if (SensorValue1 >= 70 && SensorValue2 >= 70 && SensorValue3 >= 70 && SensorValue4 >= 70) {
  //Serial.println(" ubefrugt");
  //}



  /*
    Serial.print(SensorValue1);
    Serial.print(" - ");
    Serial.print(SensorValue2);
    Serial.print(" - ");
    Serial.print(SensorValue3);
    Serial.print(" - ");
    Serial.print(SensorValue4);
    Serial.print(" - ");
    Serial.print(SensorG1);
    Serial.print(" - ");
    Serial.print(SensorG2);
    Serial.print(" - ");
    Serial.print(SensorG3);
    Serial.print(" - ");
    Serial.println(SensorG4);
  */


}

thank you very much for the info!!

I´m 110% that there is 5v on every arduino, not all the code can be in the message but the rest of it is just copy past for every sensor.

I updated the drawing a little bit, I unfortunately have no licence to any electrical drawing program.

arduino nano: USB-SERIAL CH340
atmega328p (old bootloader)

between mega and nano I´m just using basics digital input and output for basic commands such as reset and a feedback which I read on the MEGA as ALIVE or DEAD.

You don’t need one, but if you insist then Inkscape is a general purpose drawing package, I use a general purpose drawing package for all my schematics.

However you need to do better on the schematics you draw. A circle with the label Mega and unlabelled wires coming of it is insufficient to tell what you have.

Yes it does sound like a ground problem, but are you sure everything is powered when your PC cable is removed?

Some times strange things happen when one of the supplies is taken off, may be something like happens there. But it is some times difficult to notice here what is wrong there. Small things can have large or strange effects.

Sometimes it helps if you start with a small system or program. Like one channel and when that works, add the next channel.

Thank you man, I´m downloading inkscape right now and will try a better drawign with that.
Yeah I´m pretty sure everything is well powered up at all times.

When you have a big design with lots of repetition like yours, you could use what is known as the hierarchical technique. At the top level you have a basic block diagram and if it is a repeated number of the same block then only one block needs to be shown.
In this example the actual circuit of the sensor is shown only once and labelled and surrounded by a dotted rectangle. Then repeats of this circuit are shown by just the label "sensor n".
Other things to note is that + is at the top and ground at the bottom, and what is called page buses are used. That is everywhere there is a line with a +5V above it is joined to the same point and the same for the ground, a line with three diagonals underneath it.

Also note how the pin numbers on the chips are not shown in the physical position of the pins, but in an order chosen to simplify the wiring connections between the chips and minimise the number of crossing wires. For a crossing wire I prefer the convention of showing a gap where one wire goes under an other one.

Also note all wires to be horizontal or vertical and chip pin numbers inside the chip's rectangle and pin names outside the chip's rectangle, with all components having a value next to them.

Have fun.

I finally made a schematic drawing, that´s also my first so be nice if I don´t do everything with perfection :slight_smile:

3 Likes