robot that draws randomly

Hey guys, my project is the one in the photos, a



to the sound stimulus. They are vibration engines that react to sound, and one of them is light. But I'm having trouble programming (I think that's it) to make it work. What do you think?

void setup()
{
   // SOUND SENSOR //
   pinMode (A0, INPUT);
   pinMode (3, OUTPUT);
   pinMode (5, OUTPUT);
   digitalWrite (3, LOW);
   digitalWrite (5, LOW);

   //LIGHT
   pinMode (A1, INPUT);
   pinMode (6, OUTPUT);
   digitalWrite (6, LOW);
}

void loop()
{

   //LIGHT
   if (analogRead (A1) > 450) {
     digitalWrite (6, HIGH);

   } else {

     digitalWrite (6, LOW);
   }

   // SOUND SENSOR //
   if (analogRead (A0) > 450) {

     digitalWrite (5, HIGH);
     digitalWrite (3, HIGH);

   } else {

     digitalWrite (5, LOW);
     digitalWrite (3, LOW);
   }
   delay(200);
}

Open the serial port and put some serial prints so that you can see the program flow. Maybe your sensor outputs are not going over the thresholds.

void setup()
{
   Serial.begin(9600);
   Serial.println("running setup");
   // SOUND SENSOR //
   pinMode (A0, INPUT);
   pinMode (3, OUTPUT);
   pinMode (5, OUTPUT);
   digitalWrite (3, LOW);
   digitalWrite (5, LOW);

   //LIGHT
   pinMode (A1, INPUT);
   pinMode (6, OUTPUT);
   digitalWrite (6, LOW);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 200;
   if (millis() - timer >= interval)
   {
      timer = millis();
      //LIGHT
      int light = analogRead (A1);
      Serial.print("light reading = ");
      Serial.print(light);
      if ( light > 450)
      {
         digitalWrite (6, HIGH);
      }
      else
      {
         digitalWrite (6, LOW);
      }
      // SOUND SENSOR //
      int sound = analogRead (A0);
      Serial.print("  sound reading = ");
      Serial.println(sound);
      if (sound > 450)
      {
         digitalWrite (5, HIGH);
         digitalWrite (3, HIGH);
      }
      else
      {
         digitalWrite (5, LOW);
         digitalWrite (3, LOW);
      }
      //delay(200);
   }
}

What are the specifications of the motors?

Post a clear photo showing your wiring.

Can you make the motors run by themselves? Have you been able to control the motors outside of this program?

Thanks, I put the serial prints and they are working. Is there a specific limit they have to cross?

The engine specifications are:
Name: Vibracall 1027 Vibration Motor
Recommended Minimum Input Voltage - Maximum Recommended Input Voltage: 3V - 3V
Operating Voltage: From 2.5V to 4V;
Operating current: 90mA max;
Rotation speed: 9000 RPM;
Cable length: 3cm;
Total dimension: 40 x 10 x 3mm;

On the wires I was using some very thick ones (I couldn't take the picture but later at night I'll post it here), I'll replace it with thinner ones. And yes, I managed to get them to work on their own but I haven't tested them outside of this programming, do you have any suggestions?

Always post the code, using code tags.

What numbers are printed, and what is the result, considering this line in your code?


   // SOUND SENSOR //
   if (analogRead (A0) > 450) {

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.