Toll-Free Customer Support 24/7

Atmega328 UNO BOT

/*
* Project name:
Atmega328 UNO BOT
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: ATMEGA328
Dev.Board: Arduino uno
Oscillator: 16 MHz
Software: Arduino

*/

const int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to x axis Joystick
const int analogInPin2 = A1; // Analog input pin that the potentiometer is attached to y axis Joystick
const int buttonPin_A = 2; // the number of the D0 pin
const int buttonPin_B = 3; // the number of the D1 B pin
const int buttonPin_C = 4; // the number of the D2 C pin
const int buttonPin_D = 5; // the number of the D3 D pin
const int buttonPin_E = 6; // the number of the STD pin

 

int sensorValue = 0; // value read from the pot
int D0,D1,D2,D3,STD; // variable for reading the pushbutton status

int ENA=9;
int IN1=11;
int IN2=12;
int ENB=10;
int IN3=13;
int IN4=8;

void setup()
{

// initialize the pushbutton pin as an input:
pinMode(buttonPin_A, INPUT);
pinMode(buttonPin_B, INPUT);
pinMode(buttonPin_C, INPUT);
pinMode(buttonPin_D, INPUT);
pinMode(buttonPin_E, INPUT);

//motor setup
pinMode(ENA,OUTPUT);
pinMode(ENB,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);

digitalWrite(ENA,HIGH);// Activate motor A
digitalWrite(ENB,HIGH);// Activate motor B
}
void loop()
{
// read the state of the pushbutton A,B,C,D,E value:
D0 = digitalRead(buttonPin_A);
D1 = digitalRead(buttonPin_B);
D2 = digitalRead(buttonPin_C);
D3 = digitalRead(buttonPin_D);
STD = digitalRead(buttonPin_E);

if (STD == HIGH)
{
delay(400);
if((D3==0)&&(D2==0)&&(D1==1)&&(D0==0))
{
stop();
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(100);
}
else if((D3==0)&&(D2==1)&&(D1==0)&&(D0==0))
{
stop();
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(100);
}
else if((D3==0)&&(D2==1)&&(D1==1)&&(D0==0))
{
stop();
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(100);
}
else if((D3==1)&&(D2==0)&&(D1==0)&&(D0==0))
{
stop();
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(100);
}
else
{
stop();
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
delay(100);
}
}
while(STD!=LOW)
{
STD = digitalRead(buttonPin_E);
}
}

void stop()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
delay(100);
}

Back to top