Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: Peizo Sensor to detect hits from a bat on: October 13, 2012, 08:27:03 am
Hi,

I've been using Peizo pick up to detect a drum hit quite successfully. I run the peizo through a small amplifier chip and then read the anaolg signal on the Arduino. I find that looking for a a value above 700 will detect any sort of hit to the drum skin.

I use an LM386 amplifier chip connected directly to the peizo (they're tiny) and then I can run the sensor wire as long as I want.

Let me know if you want further info on this and I can send you some schematics.

Dok.
2  Using Arduino / Programming Questions / Re: Checked and checked, but something's not right on: May 08, 2012, 08:19:47 am
Thanks man! Can you tell this is my first project? You got it working for me! Hazzah!
3  Using Arduino / Programming Questions / Checked and checked, but something's not right on: May 08, 2012, 07:27:57 am
HI guys,

I have some code that I'm using to read three voltages which fluctuate. I have marked them Red Blue And green as per the wire colour.

MY project is to read the voltages and determine if they are high, medium or low. To do this I first take a bunch of readings and average them out. Then I assign a 0, 1 or 2 to a value based on the voltage range. I then run it through a rolling array and check if I have had the same result 3 times in a row. If so I set the final trigger to the appropriate 0,1 or 2 value.

It's working fine for the Blue and Green threads, but I'm getting almost inverted results on the Red channel, even though they are identical in code!

I've been monitoring the out put and it's picking up all the right values, but just not displaying the right result. Please help me! It's driving me nuts and I bet you anything it's something blindingly stupid!

Here is the program:

Code:
const int numReadings = 500;

// VGA source pins
int redsignal = A0;
int greensignal = A1;
int bluesignal = A2;

//LED pins
int redled = 3;
int greenled = 5;
int blueled = 6;

//Ternary outputs
int redout = 0;
int greenout = 0;
int blueout = 0;

int redstable[3];
int greenstable[3];
int bluestable[3];

int redtrigger = 0;
int greentrigger = 0;
int bluetrigger = 0;


void setup()
{
  // initialize serial communication with computer:
  Serial.begin(9600);                  
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);
pinMode(blueled, OUTPUT);
}

void loop() {
  
long blueread = 0;                  // the running total
long redread = 0;                  // the running total
long greenread = 0;                  // the running total
  
  // Take average of red blue and green                  
for (int count = 0; count < numReadings; count++) {
  blueread += analogRead(bluesignal);
  greenread += analogRead(greensignal);
  redread += analogRead(redsignal);
}
blueread /= numReadings;
redread /= numReadings;
greenread /= numReadings;

// assign "out" to 0, 1 or 2 depe

if (blueread <= 50) blueout = 0;
if (blueread > 50 && blueread < 150) blueout = 1;
if (blueread >= 150) blueout = 2;

if (redread <= 50) redout = 0;
if (redread > 50 && redread < 150) redout = 1;
if (redread >= 150) redout = 2;

if (greenread <= 50) greenout = 0;
if (greenread > 50 && greenread < 150) greenout = 1;
if (greenread >= 150) greenout = 2;

// send readings into stability array
redstable[3] = redstable[2];
redstable[2] = redstable[1];
redstable[1] = redout;

// if 3 reading in a row are the same then set trigger to eaqual out
if (redstable[1] == redstable[2] && redstable[2] == redstable[3]) redtrigger = redout;

// repeat for other inputs
greenstable[3] = greenstable[2];
greenstable[2] = greenstable[1];
greenstable[1] = greenout;
if (greenstable[1] == greenstable[2] && greenstable[2] == greenstable[3]) greentrigger = greenout;

bluestable[3] = bluestable[2];
bluestable[2] = bluestable[1];
bluestable[1] = blueout;
if (bluestable[1] == bluestable[2] && bluestable[2] == bluestable[3]) bluetrigger = blueout;

   // send it to the computer as ASCII digits
  Serial.print(redtrigger);
     Serial.print("        ");
  Serial.print(greentrigger);
   Serial.print("        ");
  Serial.print(bluetrigger);
  
Serial.print("                    ");  

Serial.print(redread);
 Serial.print("        ");  
Serial.print(greenread);    
   Serial.print("        ");
Serial.println(blueread);
 
  //Send output to LED.
  analogWrite(redled, redread);
  analogWrite(blueled, blueread);
  analogWrite(greenled, greenread);

}

And here is the output - row 1,2 and 3 are the triggers which should read 0 if under 50, 1 between 50 and 150 and 2 for anything above 150 (but only after three of the same number in a row.
The next three columns are the voltage readings, which match correctly in the 2nd and third rows.

Code:
Red  Grn      Blue                Red       Grn     Blue
0        0        0                    197        0        0
0        0        0                    199        0        0
0        0        0                    200        0        0
0        0        0                    197        0        0
0        0        0                    40        0        156
0        0        0                    0        0        198
2        0        2                    0        0        195
2        0        2                    0        0        196
2        0        2                    0        0        199
2        0        2                    0        0        200
2        0        2                    0        0        197
2        0        2                    0        0        198
2        0        2                    0        0        197
2        0        2                    0        0        195
2        0        2                    0        0        196
2        0        2                    0        0        197
2        0        2                    0        0        195
2        0        2                    0        0        196
2        0        2                    0        0        196
2        0        2                    0        0        200
2        0        2                    0        0        195
2        0        2                    0        0        196
2        0        2                    0        0        197
2        0        2                    0        142        55
2        0        2                    0        202        0
1        0        2                    0        201        0
0        2        0                    0        199        0
0        2        0                    0        202        0
0        2        0                    0        198        0
0        2        0                    0        199        0
0        2        0                    0        197        0
0        2        0                    0        196        0
0        2        0                    0        200        0
0        2        0                    0        197        0
0        2        0                    0        200        0
0        2        0                    0        198        0
0        2        0                    0        197        0
0        2        0                    0        200        0
0        2        0                    0        196        0
0        2        0                    0        200        0
0        2        0                    0        199        0
0        2        0                    0        198        0
0        2        0                    55        199        0
0        2        0                    199        201        0
0        2        0                    199        198        0
0        2        0                    198        200        0
0        2        0                    201        201        0
0        2        0                    198        199        0
0        2        0                    201        199        0
0        2        0                    199        201        0
0        2        0                    202        202        0
0        2        0                    200        199        0
0        2        0                    199        198        0
0        2        0                    199        200        0
0        2        0                    199        198        0
0        2        0                    202        201        0
0        2        0                    199        202        0
0        2        0                    200        199        0
0        2        0                    199        202        0
0        2        0                    202        200        0
0        2        0                    200        201        0
0        2        0                    176        161        0
0        2        0                    83        0        0
0        2        0                    82        0        0
0        0        0                    82        0        0
0        0        0                    82        0        0
0        0        0                    81        0        0
0        0        0                    83        0        0
0        0        0                    82        0        0
0        0        0                    83        0        0
0        0        0                    84        0        0
0        0        0                    83        0        0
0        0        0                    82        0        0
0        0        0                    83        0        0
0        0        0                    83        0        0
0        0        0                    82        0        0
0        0        0                    84        0        0
0        0        0                    83        0        0
0        0        0                    82        0        0
0        0        0                    82        0        0
0        0        0                    83        0        0
0        0        0                    165        0        0



4  Using Arduino / Programming Questions / Re: Why am I getting negative numbers? on: May 05, 2012, 10:11:51 am
Thanks guys, Figured it out. Moved the Long initialiser into the main loop as well and am getting correct readings now!
5  Using Arduino / Programming Questions / Re: Why am I getting negative numbers? on: May 05, 2012, 10:01:23 am
Thanks for the quick response, Can you explain what you mean by Long Type?
I still find it unusual that I am getting negative numbers in the output, especially if the readings are all positive number.
6  Using Arduino / Programming Questions / Why am I getting negative numbers? on: May 05, 2012, 09:44:50 am
This is my first Arduino project and I've never programmed before so some help would be much appreciated...

I'm reading three AC voltages and trying to average them out. The code below should only return positive numbers as I have used the ABS command, but I'm still getting negative numbers in the mix. What am I doing wrong?

Code:
const int numReadings = 50;
int bluetotal = 0;                  // the running total
int redtotal = 0;                  // the running total
int greentotal = 0;                  // the running total

int red = A0;
int green = A1;
int blue = A2;
void setup()
{
  // initialize serial communication with computer:
  Serial.begin(9600);                   
 
}

void loop() {
  // Take average of red blue and green                   
for (int count = 0; count < numReadings; count++) {
  bluetotal += abs(analogRead(blue));
  greentotal += abs(analogRead(green));
  redtotal += abs(analogRead(red));
}
 
  // send it to the computer as ASCII digits
  Serial.print(bluetotal/numReadings);   
   Serial.print("        "); 
  Serial.print(redtotal/numReadings);
   Serial.print("        "); 
  Serial.println(greentotal/numReadings);
 
}
7  Using Arduino / Project Guidance / Re: VGA Colour Detector on: May 05, 2012, 08:31:26 am
So I've been playing with VGA outputs and get a definite signal difference between screens showing prime colours. Now I need some code that can take about 500 readings from three separate inputs and average them out.

The signal I'm getting is AC peaking at about 1v or so. I'm hoping the arduino can read these levels with some accuracy to take the samples.
8  Using Arduino / Project Guidance / Re: VGA Colour Detector on: May 03, 2012, 10:06:28 am
Yes, it's sort of like an ambi-light project, but I cannot connect digitally to the computer . The laptop will be about 10 meters from the projectors (two projectors) which is too far for the USB cable to run.

A colour sensor won't work either because it will need to sit at the projector, not near the projected surface.
 
I think if I run the vga out put for each of the RGB lines through a rectifier and then through filters I should get an average voltage for each line. When the image is mostly blue, for example, I should get a higher reading on the blue line.

These values are then read to produce the required colours.
9  Using Arduino / Project Guidance / VGA Colour Detector on: May 03, 2012, 09:33:13 am
Hi,

I've got an idea for a project in which I need to determine the average colour of a VGA signal being fed to a projector. Due to the setup I will not be able to run a USB cable back to the computer and so the usual approach of taking a screenshot to determine the average colour is out.

What I would like to do is take the RGB pins from the VGA output and run them through a filter and then use the signal to determine an average voltage of each pin. This should give me a reading which could be used to determine the average colour of the output.

Is this totally stupid? or does the idea have legs? I'm just not sure what type of circuitry would be able to take the VGA signals and produce a DC voltage that could be read with any sort of meaning full results. Luckily the signal being processed will be mostly one colour or the other with slow gradual changes, so it could work.

Any ideas?
Pages: [1]