Arduino Sound Sensor

Finally I have some time to continue with this investigation and great improvements were achieved with the circuit provided by Ant:  http://www.rev-ed.co.uk/docs/picaxe_sound.pdf

First here are the photos deleted by mistake from flickr:

Headsets microphones

Electrec thingey inside.

The circuit

This is a closeup of the circuit, I´ve added a 10uF capacitor to stabilize the output signal (it´s the green cap on the right).

The problem here is that I can´t imagine myself soldering all this components onto a pcb, I would like to have at least two of these, four would be awesome.

Click the following button to see source code for Arduino and Processing

/* ****************************************************

Arduino Code

**************************************************** */

int analogValue;
int val;

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);

}

void loop()
{
// read analog input
analogValue = analogRead(0);

// send values to processing
Serial.println(analogValue, DEC);

// pause for 10 milliseconds:
delay(10);

}

/* ****************************************************

Processing Code

**************************************************** */

// import the Processing serial library
import processing.serial.*;

// declare a font variable
PFont font48;

int linefeed = 10; // Linefeed in ASCII
Serial myPort; // The serial port

// value recieved from the serialport / arduino
int sensorValue;

// mapped value
float sensorValueMap;

// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Setup

void setup() {
myPort = new Serial(this, Serial.list()[0], 9600);

// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil(linefeed);

size (800, 600);
background (0);
//smooth();

// you need to have this font in your machine, if not go to
// Tools – Creat Font – and create your own font
font48 = loadFont(“alask_48.vlw”);

textFont(font48);

}

// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Serial Event

void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);

// if you got any bytes other than the linefeed:
if (myString != null) {

myString = trim(myString);
//println(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ‘,’));

// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
//print(“Sensor ” + sensorNum + “: ” + sensors[sensorNum] + “\n”);

// sensor
sensorValue = sensors[0];
//sensorValueSmooth = sensors[1];

}
}
}

// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Draw

void draw() {

// set the black backgrounf
background(0);

// run the displayText() function
displayText();

// map the recieved values
sensorValueMap = map(sensorValue, 0, 1024, 0, 800);

// draw a rectangle based on the variable sensorValueMap
rect (0, 100, width, sensorValueMap);
}

// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Display Text

void displayText() {

text(“Sensor Value”, 20, 80);
text(sensorValue, 450, 80);

}

// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Save image

void keyPressed(){
if(key==’s’)
saveFrame(“sound-######.png”);
}

BreadUino

This came up with the need of having the arduino permanently installed on the robots, I´m tired of having to remove the arduino from one bot to the other, and then rewire everything, and then reupload the code everytime I have a new idea, or everytime I want to show the bot to someone.

So I followed the ITP Physical Computing tutorial, and it works like a charm, now I want to try to upload code with the FTDI cable, and If I have success on this I can start making my custom Arduino boards. :D

The link below might be of interest:

Burning the bootloader without an external AVR-Writer

=================================================================

Update: 18.03.09

And here´s the trick to upload code without having to remove the chip to a normal Arduino board, and then put it back on the breadboard, I´m using an FTDI cable, Black and Red connect to GND and +V, he RX from the FTDI cable goes to the AVR’s TX (pin3) and the FTDI’s TX goes to AVR’s RX (pin2).

“I hold down the reset button, press the upload button, count to three, then release the reset button. Then the IDE seems to upload the smoothest.” Full credits to Rudolph for sharing the trick.

Another mighty trick is using a 0.01 uf cap between the RTS (green wire) and reset pin, it will make an auto reset before uploading!!! I´ve made my day!! :D    Thank you Rory  ;)

=================================================================

Testing the circuit with the L293D :-)

Control your motors with L293D

After long research and trial and error,  I´ve came up to a new walkthrough regarding this nice chip, the L293D.
Each project is one project and each one has its own unique power configurations, so you must be aware of the best battery choice and how to distribute voltage through your robot.

I strongly advice you to read the following articles:

Picking Batteries for your Robot
Once you’ve decided on batteries, how do you regulate the voltage

************************************************

L293D gives you the possibility to control two motors in both directions – datasheet

************************************************

The L293D Circuit:

Basic Implementation:

This is the most basic implementation of the chip.

As you can see, a 5V Voltage Regulator is between the battery and pins 1, 9, 16.

Pin 8 gets power before the VReg, if your motor needs for example 6V you should put 6V directly in this pin, all the other pins should not get more than 5V.

This will work with no problem at all, but if you want to do the right implementation take a look at the next example:

This is the correct Implementation (with the capacitors), and note that pin 8 is feeded by unregulated voltage. This means that if your motors need more than 5V, you should power this pin with that amount of voltage, and the rest of the circuit with 5V.


The capacitors stabilize the current.

The same circuit on a breadboard:

Soldered on a pcb and ready to go:


This is the back of the circuit, click for high resolution photo.


// Use this code to test your motor with the Arduino board:

// if you need PWM, just use the PWM outputs on the Arduino
// and instead of digitalWrite, you should use the analogWrite command

// —————————————————————————  Motors
int motor_left[] = {2, 3};
int motor_right[] = {7, 8};

// ————————————————————————— Setup
void setup() {
Serial.begin(9600);

// Setup motors
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}

}

// ————————————————————————— Loop
void loop() {

drive_forward();
delay(1000);
motor_stop();
Serial.println(”1");

drive_backward();
delay(1000);
motor_stop();
Serial.println(”2");

turn_left();
delay(1000);
motor_stop();
Serial.println(”3");

turn_right();
delay(1000);
motor_stop();
Serial.println(”4");

motor_stop();
delay(1000);
motor_stop();
Serial.println(”5?);
}

// ————————————————————————— Drive

void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}

void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void drive_backward(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}

void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void turn_right(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}

***********************************************************************************************
update 26/4/09
***********************************************************************************************

My 1st instructable  :)


Control your motors with L293D and ArduinoMore DIY How To Projects