Challenge of the week
This week our tech challenge was to use a motor in conjunction with a sensor of our choice. Unfortunately for me I could not find any examples that furnished code for a project like this that used the same components that came with my starter kit. I tried working with sensors alone & was able to successfully make them work using the information furnished with the kit. When I would combine the sensor code with the motor code something got scrambled, and nothing would work.
To at least have a project to turn in, I opted to do the motor without the sensor. This sounds relatively simple, but it was more involved than I expected. Attaching the motor directly to the Arduino causes a threat of damaging the Arduino board. For this reason a power supply module must be placed on the breadboard. Although the instructions said I could provide power from the Arduino directly to the power supply board I was unable to do it. Evidently it requires a cable that I did not receive in my kit, so I ended up providing power to it with the furnished 9 Volt battery and its provided cable. The power supply module has a convenient, built in on/off switch. The power feeds through the L293D IC (integrated circuit). There is a long drawn out description of how this IC works, but I will not bore you with all the technical mumbo jumbo. It simply helps make the circuit work properly.
| Power Supply Module |
| L293D Pin Configuration |
| Motor Project Schematic |
| Motor Wiring Diagram |
![]() |
| Top View of Motor Assembly |
![]() |
| Motor Video |
/************************
Exercise the motor using
the L293D chip
************************/
#define ENABLE 5
#define DIRA 3
#define DIRB 4
int i;
void setup() {
//---set pin
direction
pinMode(ENABLE,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
Serial.begin(9600);
}
void loop() {
//---back and forth
example
Serial.println("One way, then reverse");
digitalWrite(ENABLE,HIGH); // enable on
for
(i=0;i<5;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(500);
digitalWrite(DIRA,LOW); //reverse
digitalWrite(DIRB,HIGH);
delay(500);
}
digitalWrite(ENABLE,LOW); // disable
delay(2000);
Serial.println("fast Slow example");
//---fast/slow stop
example
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(3000);
digitalWrite(ENABLE,LOW);
//slow stop
delay(1000);
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,LOW); //one way
digitalWrite(DIRB,HIGH);
delay(3000);
digitalWrite(DIRA,LOW); //fast stop
delay(2000);
Serial.println("PWM full then slow");
//---PWM example, full speed then slow
analogWrite(ENABLE,255); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,50); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,255); //half speed
delay(2000);
digitalWrite(ENABLE,LOW); //all done
delay(10000);
}


No comments:
Post a Comment