Problem HomeMade Arduino

Hi,

This is my first post on this forum so please be patience with me :D.
I done a project in my room which lock and unlock the door with this motor:SIL2 - Central lock actuator | 12VDC; Weight: 125g; 4A; Leads: 2 leads | TME - Electronic components (WFS) and a keyboard on the other side of the door.It work very well with an Arduino Uno but i wanted to make the microcontoller by myself and i had some problems.This is the tutorial which i followed http://www.instructables.com/id/How-to-make-your-own-Arduino-board/?ALLSTEPS.This work well with blinking or something else but when i want with an L298n motor driver to controller the motor the microcontroller keeps the motor on after switching it on and doesn't react to any other command(is not a problem in my code because it work well with arduino uno).This is the project in Fritzing :http://s000.tinyupload.com/index.php?file_id=79069424323101957411 and a picture with it:.What i do wrong and which is the difference between my board and an arduno board?

Lack of bypass caps causing noise to get into the arduino and crash it?

westfw:
Lack of bypass caps causing noise to get into the arduino and crash it?

What?Sorry i didn't understand..Do you want to say that i should insert an bypass capacitor?Electrolytic caps aren't good?

Your (fascinating) diagram shows electrolytics on the input to the 7805 and none on the output. You should have both a 10µF electrolytic on the output of the regulator and a 100 nF ceramic between Vcc and ground immediately on each side of the mega328.

It should also go without saying, that the crystal capacitors (and the crystal) must be mounted immediately adjacent to the mega328 so that the ground wire to the caps is direct to the IC. You have not mentioned whether you are presently operating this on a "solderless breadboard" or have made a PCB or what other means of construction.

Nor have you provided (as a link in the text, not an attachment) a perfectly focused photo of your rig.

Paul__B:
Your (fascinating) diagram shows electrolytics on the input to the 7805 and none on the output. You should have both a 10µF electrolytic on the output of the regulator and a 100 nF ceramic between Vcc and ground immediately on each side of the mega328.
i have a cap on the output but i forgot to put them on diagram.I will try and i will come back with the result.Thanks!

I tried to add 2 caps on every side but i get the same result.This is the schema:.
Do you have any other ideas which can be the problem?And when i tested it ,the circuit it was on the breadboard with the capacitors closed to microcontroller.But in future i want to make an custom pcb.

biabeniamin:
Do you have any other ideas which can be the problem?

Yes, plenty!

What you describe is a very common problem detailed here (or on the "general electronics" or various other fora).

In general, it has everything to do with layout, particularly layout of the power lines and ground. By and large, it is easier with a PCB as good PCB design uses "flood fill" so that all otherwise blank parts of the PCB become ground planes and one places "vias" generously to multiply interconnect parts of that ground plane.

You must arrange your ground and supply lines so that connections to the motor system run separately to the power supply than those to the Arduino controller. Better still if you use a separate power supply and only connect the ground on the L298 to that on the mega328 since that parallels the signal path between the two. If you are using the one power supply, the "star point" for the grounds should be the regulator ground where the bypass capacitors (other than those adjacent to the mega328), the power supply, the Arduino ground and the L298 ground, all connect.

And all wires must be as short as possible - again easiest once you are doing it on a PCB. Any wire longer than an inch is a potential inductor (as well as a resistor).

For the same reason, interconnecting wires must be paired; supply lines must be run in a cable together with the corresponding ground, the same with control switch lines and motor wires.

All wires are very short so this is not a problem and the caps are right near the microcontroller.And the ground and 12 v comes together.

Any others ideas?

Bypass caps for the L298? Post a picture? Post your sketch?
What test tools do you have? What debugging code have you added to your sketch to see what it is doing when it is "not responding" ?

This is the code:

#include <Wire.h>

struct keyboardPin
{
  int digitalPin;
  int pin;
};
keyboardPin pins[7];
int lockerPin1=9;
int lockerPin2=10;
int lockerPinPwm=11;
int unlockerButtonPin=15;
int lockerButtonPin=16;
bool looked=false;
int countKeyboardPin=0;
int pin[]={0,0,0,0};
int insertedPin[4];
int speakerPin=14
;
int countInsertedPin=0;
void addPin(int digitalPin,int pin)  
{
  
  pins[countKeyboardPin].digitalPin=digitalPin;
  pins[countKeyboardPin].pin=pin;
  countKeyboardPin++;
}
int  getLinie(int pin)
{
  int line=-1;
  switch(pin)
  {
    case 2:
      line=1;
      break;
    case 7:
      line=2;
      break;
    case 6:
      line=3;
      break;
    case 4:
      line=4;
      break;
  }
  return line;
}
int  getColoana(int pin)
{
  int col=-1;
  switch(pin)
  {
    case 3:
      col=1;
      break;
    case 1:
      col=2;
      break;
    case 5:
      col=3;
      break;
  }
  return col;
}
int transforLinColToNumber(int lin,int col)
{
  return ((lin-1)*3)+col;
}
int getTasta(int pin1,int pin2)
{
  int col,lin;
  col=getColoana(pin1);
  if(col==-1)
    col=getColoana(pin2);
  lin=getLinie(pin1);
  if(lin==-1)
    lin=getLinie(pin2);
  int rez=transforLinColToNumber(lin,col);
  if(rez==11)
    return 0;
  return rez;
}
void LockDoor()
{
  Serial.println("Locking");
  digitalWrite(lockerPin1,LOW);
  digitalWrite(lockerPin2,HIGH);
  digitalWrite(lockerPinPwm,HIGH);
  delay(1000);
  digitalWrite(lockerPinPwm,LOW);
  digitalWrite(lockerPin1,LOW);
  digitalWrite(lockerPin2,LOW);
}
void UnlockDoor()
{
  Serial.println("Unlocking");
  digitalWrite(lockerPin1,HIGH);
  digitalWrite(lockerPin2,LOW);
  digitalWrite(lockerPinPwm,HIGH);
  delay(1000);
  digitalWrite(lockerPinPwm,LOW);
  digitalWrite(lockerPin1,LOW);
  digitalWrite(lockerPin2,LOW);
}
void beep()
{
  tone(speakerPin,440,250);
}
void notOkBeep()
{
  tone(speakerPin,100,250);
}
void setup()
{
  Wire.begin(4);
  Wire.onReceive(i2cReceiveEvent);
  Serial.begin(9600);
  addPin(2,1);
  addPin(3,2);
  addPin(4,3);
  addPin(5,4);
  addPin(6,5);
  addPin(7,6);
  addPin(8,7);
  pinMode(unlockerButtonPin,INPUT_PULLUP);
  pinMode(lockerButtonPin,INPUT_PULLUP);
  for(int i=0;i<countKeyboardPin;++i)
  {
    if(getLinie(pins[i].pin)!=-1)
    {
      pinMode(pins[i].digitalPin,OUTPUT);
      digitalWrite(pins[i].digitalPin,HIGH);
    }
    else
      pinMode(pins[i].digitalPin,INPUT_PULLUP);
  }
  pinMode(lockerPin1,OUTPUT);
  pinMode(lockerPin2,OUTPUT);
  pinMode(lockerPinPwm,OUTPUT);
  pinMode(speakerPin,OUTPUT);
}
void checkPin()
{
  bool ok=true;
  for(int i=0;i<4;++i)
  {
    if(pin[i]!=insertedPin[i])
    {
      ok=false;
      break;
    }
  }
  if(ok)
  {
    Serial.println("ok");
    UnlockDoor();
  }
  else
  {
    Serial.println("!ok");
    notOkBeep();
  }
  countInsertedPin=0;
}
void pushedTasta(int number)
{
  insertedPin[countInsertedPin]=number;
  countInsertedPin++;
  if(countInsertedPin==4)
    checkPin();
}
void loop()
{
  if(!digitalRead(unlockerButtonPin))
  {
    UnlockDoor();
  }
  if(!digitalRead(lockerButtonPin))
  {
    LockDoor();
  }
  for(int i=0;i<countKeyboardPin;++i)
  {
    if(getLinie(pins[i].pin)==-1)
      continue;
    digitalWrite(pins[i].digitalPin,LOW);
    for(int j=0;j<countKeyboardPin;++j)
    {
      if(j!=i)
      {
        if(!digitalRead(pins[j].digitalPin))
        {
          int tasta=getTasta(pins[j].pin,pins[i].pin);
          if(tasta==12)
          {
            LockDoor();
          }
          else
          {
            beep();
            pushedTasta(tasta);
            delay(300);
            Serial.println(tasta);
          }
        }
      }
    }
    digitalWrite(pins[i].digitalPin,HIGH);
  }
}
void i2cReceiveEvent(int howMany)
{
  int x = Wire.read();
  Serial.print("Via i2c:");
  Serial.println(x);
  if(x==0)
  {
    LockDoor();
  }
  if(x==1)
  {
    UnlockDoor();
  }
}

Bypass caps for logical or for motor power for l298?
I have a multimeter,I have a buzzer which makes a sound every time a key is pressed on keyboard

I added bigger caps for microcontroller and now it works very well. Thank you very much for your help and for you time. Have a wonderful day!