Hi, I just compiled my code and everything was working fine but when I connected the power source to the reles (12V), the code is stuck on the void setup and never goes to the void loop, when the power source isn't conected, the reles and everything works fine... any ideas?
thank you very much for your help in advance!
CODE JUST IN CASE IT HELPS:
#include <AFMotor.h>
AF_DCMotor motorA(1);
const int solenoide = 51;
const int led_inicial = 49;
float metal_SI;
int reading_SI;
int metalPin_SI = 8;
const int BT0 = 31;
int reading_BT0;
const int BT1 = 33;
int reading_BT1;
const int BT2 = 35;
int reading_BT2;
const int BT3 = 37;
int reading_BT3;
int posicio_emmagatzemable =0;
void setup()
{
//Motor speed
motorA.setSpeed(250);
//Led inicial
pinMode(led_inicial, OUTPUT);
digitalWrite(led_inicial, HIGH);
delay(500);
digitalWrite(led_inicial, LOW);
delay(500);
//Declarem solenoide com un output
pinMode(solenoide, OUTPUT);
//High solenoide = apagada
Serial.begin(9600);
delay(1000);
//Declarem butons com a INPUTS
pinMode(BT0, INPUT);
pinMode(BT1, INPUT);
pinMode(BT2, INPUT);
pinMode(BT3, INPUT);
Serial.print("Ojo que estem dins del inicialitzador ");
Serial.print("\n");
Serial.print("\n");
}
void loop()
{
int selected_button = 0;
int NO_button =0;
int i=0;
int comptador=0;
motorA.run(RELEASE);
reading_BT0 = digitalRead(BT0);
reading_BT1 = digitalRead(BT1);
reading_BT2 = digitalRead(BT2);
reading_BT3 = digitalRead(BT3);
if (reading_BT0 == LOW or reading_BT1 == LOW or reading_BT2 == LOW or reading_BT3 == LOW) {NO_button = 1;}
if (reading_BT0 == LOW) {selected_button = 0;}
if (reading_BT1 == LOW) {selected_button = 1;}
if (reading_BT2 == LOW) {selected_button = 2;}
if (reading_BT3 == LOW) {selected_button = 3;}
if (NO_button == 1){comptador = selected_button - posicio_emmagatzemable;
if(comptador == -1){comptador = 3;}
if(comptador == -2){comptador = 2;}
if(comptador == -3){comptador = 1;}
Serial.print(" Estava a la posicio ");
Serial.print(posicio_emmagatzemable);
Serial.print("\n");
Serial.print(" Volem anar a la posicio = : ");
Serial.print(selected_button);
Serial.print("\n");
Serial.print(" Haurem de moure = : ");
Serial.print(comptador);
Serial.print("\n");
posicio_emmagatzemable = selected_button;
}
//Serial.print(" ");
//Serial.print("Cops detectat= : ");
//Serial.print(i);
if (i != comptador){
digitalWrite(solenoide, LOW);
delay(1000);
motorA.run(FORWARD);
delay(1500);}
while (i != comptador) {
delay(750);
reading_SI = analogRead(metalPin_SI);
metal_SI = (float)reading_SI*100/1024.0;
if(reading_SI<100){
i++;
digitalWrite(led_inicial, HIGH);
delay(100);
digitalWrite(led_inicial, LOW);
//Serial.print("Ojo que estem dins del comptador ");
}
}
//Serial.print("RES ");
motorA.run(RELEASE);
delay(1000);
digitalWrite(solenoide, HIGH);
}