A field of crickets using Arduino and motors dc.

Here is the mini-project that we had to do using motors for the physical computing course.

Ben and I decided to something like a field of crickets after showing this video and after listened the noises that the motors do:

Arduino Controlling Motors from Jesse Chorng on Vimeo.

We thought that could be cool to imitate the noises that the crickets do when it is dark in the spring and summer seasons, and we decided to do it using motors dc, leds and photocell sensors.

Here you can see some pictures about what we wanted to do:

The most difficult thing was making the motor sing like a cricket. At the begining we had five motors that changed it speed depending on the light received by the photocell sensor. So when it was dark, the motors ran fast and the leds blinked, and when there were light, the motors stoped and the leds get dark. It worked fine. But the sound could be better.

Then we tryed to put a little tremolo to the motor using millis() function, changing the values for the motor very fast, switching a low and a high value repeatedly. This tremolo made the sound of the motor better and also adden some kind of movement that was cute.

Video:

Field of crickets with Arduino and motors from berio on Vimeo.

Circuit:

For doing the circuit we used the tutorial called High Current Loads, from Tom Igoe at ITP:
http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

We used a 9v battery for each one of the motors, but maybe it wasn»t the best solution. We didn»t know how to power our 3 motor at once, and finally we decided to use 3 batteries instead of one, but it could be nice if we could do it only with one battery.

And here is the code:

 
// Motors pins
int motorsPin[] = {11, 10, 9, 6, 5};

// Light sensore pins
int sensorsPin[] = {1, 2, 3, 4, 5};
int sensorsVal[] = {0, 0, 0, 0, 0};

// Leds pins
int ledsPin[] = {2, 3, 4, 7, 8};

int numMotors = 5;

// time variables
long sensorPreviousMillis[] = {0, 0, 0, 0, 0};
long sensorInterval[] = {1000, 900, 1100, 800, 700};
long previousMillis[] = {0, 0, 0, 0, 0};
long interval[] = {60, 50, 70, 80, 40};

// Speed presets for the motors
int motorLow = 0;
int motorHigh = 150;

// Motor switcher
boolean activateMotor[] = {false, false, false, false, false};

void setup() {
for(int i=0; i pinMode(motorsPin[i], OUTPUT);
pinMode(ledsPin[i], OUTPUT);
}
Serial.begin(9600);
}

void loop() {
// read the values from the sensors
for(int i=0; i sensorsVal[i] = analogRead(sensorsPin[i])*10;
sensorInterval[i] = sensorsVal[i];
}

// turn on and off the motor, using periods of time that change depending of
// the value coming from the photocell sensor
for(int j=0; j if(millis() - sensorPreviousMillis[j] < sensorInterval[j]){
activateMotor[j] = true;
}else if((millis() - sensorPreviousMillis[j] >= sensorInterval[j]) && (millis() - sensorPreviousMillis[j] < sensorInterval[j]*2)){
activateMotor[j] = false;
}else{
sensorPreviousMillis[j] = millis();
}

// this makes the vibrato thing
if(millis() - previousMillis[j] < interval[j]){
if(activateMotor[j]){
analogWrite(motorsPin[j], motorHigh);
digitalWrite(ledsPin[j], HIGH);
}
}else if((millis() - previousMillis[j] >= interval[j]) && (millis() - previousMillis[j] < interval[j]*2)){
if(activateMotor[j]){
analogWrite(motorsPin[j], motorLow);
digitalWrite(ledsPin[j], LOW);
}
}else{
previousMillis[j] = millis();
}
}
}

Download: