1) H-Bridge Motor Shield Pin Out Diagram [Detailed Study]
My Code
FOR UPDATES FOLLOW US ON FACEBOOK[CLICK HERE]
My Code
- int speeda=10;
- int a1=8;
- int a2=9;
- void setup()
- {
- Serial.begin(9600);
- pinMode(speeda,OUTPUT);
- pinMode(a1,OUTPUT);
- pinMode(a2,OUTPUT);
- }
- void motorfull()
- {
- analogWrite(speeda,255);
- digitalWrite(a1,LOW);
- digitalWrite(a2,HIGH);
- Serial.println("Motor is running at full speed");
- }
- void motorstop()
- {
- analogWrite(speeda,0);
- digitalWrite(a1,LOW);
- digitalWrite(a2,HIGH);
- Serial.println("Motor is stopped");
- }
- void loop()
- {
- motorfull();
- delay(1000);
- motorstop();
- delay(1000)
- }
L293D + Analog Sensor Code
- int motor[]={2,3};
- int watsens=A0;
- void setup()
- {
- int i;
- for(i=0;i<2;i++)
- {
- pinMode(motor[i],OUTPUT);
- }
- Serial.begin(9600);
- pinMode(watsens,INPUT);
- // put your setup code here, to run once:
- }
- void loop()
- {
- watsens=analogRead(A0);
- Serial.println(watsens);
- if(watsens==0)
- {
- motorrun();
- Serial.println("Motor is running");
- delay(100);
- }
- else
- {
- motorstop();
- Serial.println("Motor is stopoed");
- delay(100);
- }
- // put your main code here, to run repeatedly:
- }
- void motorrun()
- {
- digitalWrite(motor[0],LOW);
- digitalWrite(motor[1],HIGH);
- }
- void motorstop()
- {
- digitalWrite(motor[0],LOW);
- digitalWrite(motor[1],LOW);
- }
FOR UPDATES FOLLOW US ON FACEBOOK[CLICK HERE]
No comments:
Post a Comment