0

I have made a project using Arduino, 3 LDRs and a L293D motor driver shield. My project was that when I block light from the first LDR, the motor will spin. When I block light from the second LDR, the motor will spin in opposite direction, and when I will block light from the third one, it will stop. The code had no errors and I expected it to work... But no luck. When I blocked light from the first or second LDR, the motor only made a faint "zing-zing" type of sound. Why is this happening? Is this a power problem? But I have connected 2 9v batteries to the shield and the Arduino. Please help! Here is the code I used-

#include (AFMotor.h)

const int LDR1 = A0;
const int LDR2 = A1;
const int LDR3 = A2;
const int LightIntensity = 150; 
int SensorReading1 = 0;
int SensorReading2 = 0;
int SensorReading3 = 0;
AF_DCMotor motor(1);

void setup(void)
{
  pinMode(LDR1, INPUT);
  pinMode(LDR2, INPUT);
  pinMode(LDR3, INPUT);
  motor.setSpeed(255);
}

void loop()
{
  SensorReading1 = analogRead(LDR1);
  SensorReading2 = analogRead(LDR2);
  SensorReading3 = analogRead(LDR3);

  if (SensorReading1 < LightIntensity)
  {
    motor.run(FORWARD);
  }

  if (SensorReading2 < LightIntensity)
  {
    motor.run(BACKWARD);
  }

   if (SensorReading3 < LightIntensity)
  {
    motor.run(RELEASE);
  }
}
  • Please Specify What Motors You Are Using. I Would Recommend Using A 12v Battery Or A Wall Adapter That Gives More Current. Also I Would Recommend Using Servos As They Are Much Less Trouble and Work Off Relatively Low Current. You Can Make Them Run When Something Is Sensed. This Will Make Your Circuit Use Less Power. You Can Get Small Servos For Like 5 Bucks That Will Do The Job. There Would Be No Need For A Shield. But if You Insist On Using Your Current Motors, Use Something Like A 12 Volt 7.5 Ah Battery (Thats What I Use). It Will Last Longer and Provide More Current. Also I Would Recommend – Tim7345 Nov 6 '17 at 8:41
1

You have not said what you motor is and that normally has a big bearing on the answer, but I think your problem is you need more power.

A 9V battery doesn't actually give you much current, you would be better off with a 'wall wart' aka a mobile phone charger. The higher the amps the better normally, particularly with motors. Try and find one that can put out 5Volts at 1Amp (assuming you have a 5V motor).

Also make more use of Serial.println() to show you what your program is doing. If you had debug statements in the LDR if statements then you would know the switches are working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.