Show Posts
Pages: [1] 2
1  Using Arduino / Sensors / Re: Troubleshooting the knock sensor, sensitivity problem on: September 08, 2013, 05:49:43 am
Those round piezo elements are very sensitive.
Which one are you using ? Could you attach a photo of it ?
Are you sure you have 2M resistors ? Perhaps the resistor is only 2k ?
I'm sure it's 2M resistor, I checked it. You can see the element from the attachment.


Can you give us the URL with specs?
Did you test it with a volt meter?

Sounds like you have a sketch running. Can you format it and show it in the program tags (# button on the forum editor)?

So you are saying, it is basicly working, but not up to your expectations?

The code is from here http://www.arduino.cc/en/Tutorial/KnockSensor
I'm not quite sure what you would like to see with the volt meter. I got 0 - 150 mV when metering from the resistors legs, and tapping directly the element. All connections should be good.

And yes, basically it's working but not as I have seen it working, like in the youtube video below.
They are tapping the surface where it is attached. I have to tap directly to the element to get any reasonable readings.

Code: (I had to but it like this so you can go straight to the part where it is shown how it should work. Obviously there is more sophisticated code involved in there but the principle is the same)
www.youtube.com/watch?v=8kRTpmswgFk&t=4m25s

Code:
// these constants won't change:
const int ledPin = 7;      // led connected to digital pin 13
const int knockSensor = 0; // the piezo is connected to analog pin 0
const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not


// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int ledState = LOW;         // variable used to store the last LED status, to toggle the light

void setup() {
 pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
 Serial.begin(9600);       // use the serial port
}

void loop() {
 

  sensorReading = analogRead(knockSensor);  // read the sensor and store it in the variable sensorReading:
 
Serial.println(sensorReading); 
 
  // if the sensor reading is greater than the threshold:
  if (sensorReading >= threshold) { // toggle the status of the ledPin:
 
    ledState = !ledState;    // update the LED pin itself:   
   
    digitalWrite(ledPin, ledState);   // send the string "Knock!" back to the computer, followed by newline
   
    Serial.println("Knock!");         
  }
  delay(100);  // delay to avoid overloading the serial port buffer
}

2  Using Arduino / Sensors / Troubleshooting the knock sensor, sensitivity problem on: September 07, 2013, 03:25:10 am
I'm trying to get the knock sensor example to work but I can't. My connections are like in the example but I have 2 Mohm resistor since I read that it would increase the sensitivity. It didn't help.

Is there a certain way to attach the element to a surface? I tried to tape it on the surface and I would say it's quite firmly attached. I tried to tape over it. I also tried to tape from the biger discs side so it wouldn't press both discs together. I think the both ways gave same results.

When I slide my finger over the element it gives high readings, even over 1000. But when I knock hard the surface right next to it where it's attached, it gets readings very occasionally and they are below 20. If I slap the surface it might get 70.

How can I make it more sensitive or is it broken?
3  Using Arduino / General Electronics / Re: LED on when relay off? on: August 18, 2012, 10:35:14 am
Thanks! I'm not sure if I did it how you described but got it working. The switch has C, NO (normally open) and NC (normally closed) marks on the contacts and I suppose they are the same IN, OUT and GND, that made me confused. I feel stupid  smiley-red

Here's how it's now
4  Using Arduino / General Electronics / LED on when relay off? //solved on: August 18, 2012, 04:26:34 am
Hi!

Is it possible to get LED on when relay is off with NPN transistor and how would you do it? I'm thinking way too simplified right now and can't figure it out..

This is for a switch which has a built in LED that I want to be light when the switch is off..
5  Using Arduino / Programming Questions / Re: Merging two codes, reading from ultrasonic sensor to display on: March 01, 2011, 09:39:19 am
Hi,

I have now  tested the code and it works, but it needs some tweaks. When the distance increases the displays starts to flicker. I believe it's because it takes longer time to get the distance by the sensor. How can I make the display code to be primary code and the measurement code to be secondary so it is not done with same frequency?


Code:
#include "URMSerial.h"
#define DISTANCE 1

int ledPin = 13;
URMSerial urm;

// Arduino pins connected to the 4511
const int LedA = 4;
const int LedB = 5;
const int LedC = 6;
const int LedD = 7;

// Arduino pins connected to the segment driver transistors
const int D1 = 8;
const int D2 = 9;
const int D3 = 10;

void setup() {

  Serial.begin(9600); // Sets the baud rate to 9600
  urm.begin(2,3,9600); // RX Pin, TX Pin, Baud Rate pinMode(ledPin, OUTPUT);

  // Let the Arduino know which pins go where
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedC, OUTPUT);
  pinMode(LedD, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  digitalWrite(D1, LOW);
  digitalWrite(D2, LOW);
  digitalWrite(D3, LOW);
}

void loop()
{
  // Request a distance reading from the URM37
  urm.requestMeasurement(DISTANCE);

  // Avoid fetching the distance until we're sure the reading is ready
  if(urm.hasReading())
  {
    int value; // This value will be populated
    switch(urm.getMeasurement(value)) // Find out the type of request
    {
    case DISTANCE: // Double check the reading we recieve is of DISTANCE type
      Serial.println(value);


      // Display the first digit
      Display(value / 100);       // Send first digit to the 4511
      value = value % 100;      // Calculate next digit
      digitalWrite(D1, HIGH);    // Illuminate first segment
      delay(2);                  // Wait
      digitalWrite(D1, LOW);     // Extinguish first segment

      // Display the second digit
      Display(value / 10);
      value = value % 10;
      digitalWrite(D2, HIGH);
      delay(2);
      digitalWrite(D2, LOW);

      // Display the third digit

      Display(value);
      digitalWrite(D3, HIGH);
      delay(2);
      digitalWrite(D3, LOW);

      break;
    }
  }
}

void Display(int n)
{
  if ( n > 9 )
  {
    n = 9;
  }

  if ( n < 0 )
  {
    n = 0;
  }

  if ( n / 8 == 1 )
  {
    digitalWrite(LedD, HIGH);
  }
  else
  {
    digitalWrite(LedD, LOW);
  }

  n = n % 8;

  if ( n / 4 == 1 )
  {
    digitalWrite(LedC, HIGH);
  }
  else
  {
    digitalWrite(LedC, LOW);
  }
  n = n % 4;

  if ( n / 2 == 1 )
  {
    digitalWrite(LedB, HIGH);
  }
  else
  {
    digitalWrite(LedB, LOW);
  }
  n = n % 2;

  if ( n == 1 )
  {
    digitalWrite(LedA, HIGH);
  }
  else
  {
    digitalWrite(LedA, LOW);
  }
}
6  Using Arduino / Programming Questions / Re: Merging two codes, reading from ultrasonic sensor to display on: February 16, 2011, 02:40:18 am
But thats what I'm missing right now?
7  Using Arduino / Programming Questions / Re: Merging to codes, reading from ultrasonic sensor to display on: February 15, 2011, 02:51:11 pm
Thanks for the clarification.

This:
Code:
// Function to display the digit 'n'
void Display(int n)
is just perverse!

Do you mean the code after it is useless or some how wrong? Because that's the only thing I can think of what I should add to the code.
8  Using Arduino / Programming Questions / Re: Merging two codes, reading from ultrasonic sensor to display on: February 15, 2011, 04:02:03 am
If that's what it means, yes. As I'm new to coding, I need some basic help.

I don't even understand how these two lines works and is it the left or right first digit.
Code:
Display(value / 100);       // Send first digit to the 4511
output = value % 100;      // Calculate next digit
9  Using Arduino / Programming Questions / Re: Merging two codes, reading from ultrasonic sensor to display on: February 14, 2011, 05:18:17 pm
I am sorry but I can't figure out how to do that.  smiley-red

Here's what I manage to cobble together.
Code:
#include "URMSerial.h"
#define DISTANCE 1

int ledPin = 13;
URMSerial urm;
int output = 0;

// Arduino pins connected to the 4511
const int LedA = 5;
const int LedB = 8;
const int LedC = 7;
const int LedD = 6;

// Arduino pins connected to the segment driver transistors
const int Led1 = 4;
const int Led2 = 3;
const int Led3 = 2;

void setup() {

  Serial.begin(9600); // Sets the baud rate to 9600
  urm.begin(9,10,9600); // RX Pin, TX Pin, Baud Rate pinMode(ledPin, OUTPUT);

  // Let the Arduino know which pins go where
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedC, OUTPUT);
  pinMode(LedD, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  digitalWrite(Led1, HIGH);
  digitalWrite(Led2, HIGH);
  digitalWrite(Led3, HIGH);
}

void loop()
{
  // Request a distance reading from the URM37
  urm.requestMeasurement(DISTANCE); // You may call this as many times as you like. It will only send once

  // Avoid fetching the distance until we're sure the reading is ready
  if(urm.hasReading())
  {
    int value; // This value will be populated
    switch(urm.getMeasurement(value)) // Find out the type of request
    {
    case DISTANCE: // Double check the reading we recieve is of DISTANCE type



      // Display the first digit
      Display(value / 100);       // Send first digit to the 4511
      output = value % 100;      // Calculate next digit
      digitalWrite(Led1, LOW);    // Illuminate first segment
      delay(2);                   // Wait
      digitalWrite(Led1, HIGH);   // Extinguish first segment

      // Display the second digit
      Display(value /10);
      output = value % 10;
      digitalWrite(Led2, LOW);
      delay(2);
      digitalWrite(Led2, HIGH);

      // Display the third digit
      Display(value);
      output = value;
      digitalWrite(Led3, LOW);
      delay(2);
      digitalWrite(Led3, HIGH);

      delay(200);
      break;
    }
  }
}


10  Using Arduino / Programming Questions / Re: Merging two codes, reading from ultrasonic sensor to display on: February 14, 2011, 04:21:10 pm
I do realise that and think it should be taken into the account some how in the code.

Dose this look anything like you thought?  smiley-mr-green

Code: (merged)
#include "URMSerial.h"

#define DISTANCE 1
#define TEMPERATURE 2
#define ERROR 3
#define NOTREADY 4

int ledPin = 13;
URMSerial urm;
int output = 0;

// Arduino pins connected to the 4511
const int LedA = 5;
const int LedB = 8;
const int LedC = 7;
const int LedD = 6;

// Arduino pins connected to the segment driver transistors
const int Led1 = 4;
const int Led2 = 3;
const int Led3 = 2;

void setup() {

  Serial.begin(9600); // Sets the baud rate to 9600
  urm.begin(9,10,9600); // RX Pin, TX Pin, Baud Rate pinMode(ledPin, OUTPUT);

  // Let the Arduino know which pins go where
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedC, OUTPUT);
  pinMode(LedD, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  digitalWrite(Led1, HIGH);
  digitalWrite(Led2, HIGH);
  digitalWrite(Led3, HIGH);
}

void loop()
{
  // Request a distance reading from the URM37
  urm.requestMeasurement(DISTANCE); // You may call this as many times as you like. It will only send once

  // Avoid fetching the distance until we're sure the reading is ready
  if(urm.hasReading())
  {
    int value; // This value will be populated
    switch(urm.getMeasurement(value)) // Find out the type of request
    {
    case DISTANCE: // Double check the reading we recieve is of DISTANCE type



      digitalWrite(Led1, LOW); // Illuminate first segment
      delay(2); // Wait
      digitalWrite(Led1, HIGH); // Extinguish first segment

      // Display the second digit
      Display(output / 10);
      output = output % 10;
      digitalWrite(Led2, LOW);
      delay(2);
      digitalWrite(Led2, HIGH);

      // Display the third digit
      Display(output);
      digitalWrite(Led3, LOW);
      delay(2);
      digitalWrite(Led3, HIGH);

      delay(200);
      break;
    }
  }
}
11  Using Arduino / Programming Questions / Merging two codes, reading from ultrasonic sensor to display on: February 14, 2011, 03:27:46 pm
Hi,

I have been working on ultrasonic distance meter with display and got the distance out of the sensor with this code
Code: (http://www.botbuilder.co.uk/codeandprojects/bbsonar/index.html)
#include "URMSerial.h"

#define DISTANCE 1
#define TEMPERATURE 2
#define ERROR 3
#define NOTREADY 4

int ledPin = 13;
URMSerial urm;

void setup() {

  Serial.begin(9600); // Sets the baud rate to 9600
  urm.begin(2,3,9600); // RX Pin, TX Pin, Baud Rate pinMode(ledPin, OUTPUT);
}

void loop()
{
  // Request a distance reading from the URM37
  urm.requestMeasurement(DISTANCE); // You may call this as many times as you like. It will only send once

  // Avoid fetching the distance until we're sure the reading is ready
  if(urm.hasReading())
  {
    int value; // This value will be populated
    switch(urm.getMeasurement(value)) // Find out the type of request
    {
    case DISTANCE: // Double check the reading we recieve is of DISTANCE type
      Serial.println(value, DEC); // Fetch the distance in centimeters from the URM37

      delay(200);
      break;
    }
  }
}


I would like to merge it to this, but since I am not compleatly sure what parts of the code are nessessary it's quite dificult. If you show me what parts are nessasary I would like to try merge them myself.

Code: (http://nzlamb.wordpress.com/2010/04/19/multiplexing-7-segment-led-displays-with-arduino/)
// Arduino pins connected to the 4511
const int LedA = 5;
const int LedB = 8;
const int LedC = 7;
const int LedD = 6;

// Arduino pins connected to the segment driver transistors
const int Led1 = 4;
const int Led2 = 3;
const int Led3 = 2;

long count = 0;
int output = 0;
int remain = 0;

void setup()
{
  // Let the Arduino know which pins go where
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedC, OUTPUT);
  pinMode(LedD, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  digitalWrite(Led1, HIGH);
  digitalWrite(Led2, HIGH);
  digitalWrite(Led3, HIGH);
}

void loop()
{
  // The counter runs from 0-9999 so divide this by 10 as
  // we only have three display segments
  output = count / 10;

  // Display the first digit
  // The order of these steps is important to prevent
  // visible 'bleeding' on the display
  Display(output / 100); // Send first digit to the 4511
  output = output % 100; // Calculate next digit
  digitalWrite(Led1, LOW); // Illuminate first segment
  delay(2); // Wait
  digitalWrite(Led1, HIGH); // Extinguish first segment

  // Display the second digit
  Display(output / 10);
  output = output % 10;
  digitalWrite(Led2, LOW);
  delay(2);
  digitalWrite(Led2, HIGH);

  // Display the third digit
  Display(output);
  digitalWrite(Led3, LOW);
  delay(2);
  digitalWrite(Led3, HIGH);

  // Count to 9999 then reset
  count = count + 1;
  if (count > 9999)
  {
    count = 0;
  }
}

// Function to display the digit 'n'
void Display(int n)
{
  if ( n > 9 )
  {
    n = 9;
  }

  if ( n < 0 )
  {
    n = 0;
  }

  if ( n / 8 == 1 )
  {
    digitalWrite(LedD, HIGH);
  }
  else
  {
    digitalWrite(LedD, LOW);
  }

  n = n % 8;

  if ( n / 4 == 1 )
  {
    digitalWrite(LedC, HIGH);
  }
  else
  {
    digitalWrite(LedC, LOW);
  }
  n = n % 4;

  if ( n / 2 == 1 )
  {
    digitalWrite(LedB, HIGH);
  }
  else
  {
    digitalWrite(LedB, LOW);
  }
  n = n % 2;

  if ( n == 1 )
  {
    digitalWrite(LedA, HIGH);
  }
  else
  {
    digitalWrite(LedA, LOW);
  }

}

12  Using Arduino / Project Guidance / Re: Ultrasonic distance meter with display on: February 14, 2011, 02:59:06 pm
I have now followed two pages for this project, this to get the untrasonic work and this for controlling the 3 digit 7 segment display. I have manage to get the distance out of the sensor. The displays havn't arrived yet so I havn't been able to figure out how to get them show the value from the sensor.

But meanwhile waiting for the displays to arrive I have designed a custom shield. All the components should fit between the Arduino and the shield. It needs some tweaking but I think I have done quite well since this is my first design. I tried to design it so it would be easy so solder at home. If you now how it could be improved, please tell  smiley

And for the guidance, I would appreciate help with the code. I tought it would be good to make a topic under the code section, it's here
13  Using Arduino / Project Guidance / Re: Ultrasonic distance meter with display on: January 26, 2011, 03:28:03 pm
I just got to the "LEDs and Multiplexing" page and you had already replayd smiley And yes, 3 digits.
14  Using Arduino / Project Guidance / Re: Ultrasonic distance meter with display on: January 26, 2011, 03:14:33 pm
To understand why I demand something from this device I shall tell you where it's going to be used. I'm doing this for my parents, their carage is partially quite tight. The meter is not necassary but I tought it would be fun to make one so here I am  smiley

Onions, I would like to use an LCD display but the numbers should be quite big and bright and I couldn't find any. Or I didn't know where to search. Now they are planned to be 3" (7,62 cm) high.
And now the number of seven segment displays is increased to 3 because of my fathers request. Now I'm wondering how I'm going to connect those to the Arduino, I will check the forum and the tutorials pages if there's anything for me.

pmodernme, thats a good idea, thanks! The reason why, is that the carage door is opened by an electrical motor, and when it's used a lamp is turned on and stays on for a while. I tought that my device could be powered at the same time as the lamp is.

Thanks for your input, I'm getting excited  smiley-lol
15  Using Arduino / Project Guidance / Re: Ultrasonic distance meter with display on: January 26, 2011, 10:08:01 am
Thanks, Uno seems to be a good choise.

How about powering the device. It should be powered at the same time as an another device which I think has 230 V. Is it possible to connect my device to that or do I need another powersupply?
Pages: [1] 2