Embedded "C " Language In Arduino

IN THIS WE ARE LEARNING HOW TO CODE EMBEDDED "C" LANGUAGE IN ARDUINNO.


In our previous post, we had learned about how to drive two DC motors back and forth using Arduino, and we have also drawn a diagram of it.If you have not seen that post yet, then read it first so that you do not have any problem in understanding further. First of all we will check our made connections properly that there is no error in them, after that we will start coding in our software. Before we start coding we should know a little about it. Like what is void loop and what do we write in void setup and how each command is put in arduino so that it can do that work automatically. Let's know about him.

1. First we will define the terminal used in motors that which motor has which terminal on which pin of arduino, so that we will not have any problem in further coding

2. Now we have defined the terminal of the motor. In their place, we can now use the predefined terminals directly.

3. Void Setup -

Now we will tell the input and output terminals in the Void setup which terminal will act as input and which will act as output, here we know that we will only give input to Arduino, so no need to define inputs. is not needed. Yes, if we give any other input from outside, we have to define it. But here we will tell only about the output pin.



4. Void Loop -

In the Void Loop we will write the code that we need to output from our motors again and again. It also has an advantage that we have to give input to arduinos by pressing the button only once. There is nothing to do after that. We can also set the time according to our wish, for how long the motors will spin forward and for how long they will spin backwards after stopping. I have written a code below for your practice. If you want, you can take help from it, at the end of the post you will also get a link to a free software for practice.








int m1 = 10;
int m2 = 9;
int t1 = 12;
int t2 = 11;  
void setup()
{
  pinMode(m1, OUTPUT); //OUTPUT PINS TO ALLOW POWER
  pinMode(m2, OUTPUT);
  pinMode(t1, OUTPUT);
  pinMode(t2, OUTPUT);
}

void loop()
{
  digitalWrite(m1, HIGH);// ALL MOTORS NOW MOVE IN 
  digitalWrite(m2, LOW) ;//FORWARD DIRCTION 
  digitalWrite(t1, HIGH);
  digitalWrite(t2, LOW);
  
  delay(5000);// Wait for 5000millisecond(s) = (5 SECONDS)
  
  digitalWrite(m1, LOW);// ALL MOTORS ARE NOW STOP
  digitalWrite(m2, LOW) ;
  digitalWrite(t1, HIGH);
  digitalWrite(t2, HIGH);
  
  delay(5000);// WAIT AGAIN FOR 5000 MILISECONDS (S) = (5  SECONDS)
  
  digitalWrite(m1, LOW);//ALL MOTOR ARE NOW MOVE BACKWARD DIRECTION
  digitalWrite(m2, HIGH);
  digitalWrite(t1, LOW);
  digitalWrite(t2,HIGH);
  
  delay(5000); //WAIT AGAIN 5000 MILLISECONDS (S) = (5 SECONDS)
  
  digitalWrite(m1, LOW);
  digitalWrite(m2,LOW);
  digitalWrite(t1,HIGH);
  digitalWrite(t2, HIGH);
  
  delay(5000); // Wait for 5000 millisecond(s)
}


👍👍👍👍👍



Post a Comment

0 Comments