Go Down

Topic: Led on Led send (Read 1 time) previous topic - next topic

PeterH


What use is a function that affects digital pins only, to an input-only analog pin? The pinMode() statement was correctly omitted from OP's code.


I agree it's be redundant to set the mode to INPUT since that is the default, but if you mean that the analog pins do not support digital output then I disagree.
I only provide help via the forum - please do not contact me for private consultancy.

UKHeliBob

You won't get a constant value.  The sensor is responding to you tapping it but the value will not stay at a high value because the tap will finish and the value will drop back to a fairly steady lower one as you have seen.  If you need to perform an action you need to get your program to notice the change and act on it.
Something like this
Code: [Select]
start loop
  read sensor
  if sensor value greater than threshold
    turn on the LED
  end of if
  else
    compare sensor value now with previous sensor value
    if it was it low last time and has been for some time
      turn off the LED
    end of if
    remember the current sensor value for the next check
  end of else
end of loop - go back and do it again

You will need to determine on the value of the threshold based on your experiments
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Tricky12

I tried this code today on my dryer.  The (Serial.println(val);) = 264,  with the dryer off. 
When the dryer was on and running, (Serial.println(val);) = 266.   How do I go about making the Piezo sensor,
be more sensitive to the vibrations of the dryer,  when it is on?




Code: [Select]
int sensor = 2; // Analog in
int val =0; // Current reading for analog pin

void setup() {
  Serial.begin(9600);
  pinMode(sensor, INPUT);
}

void loop() {
  val = analogRead(sensor);
  Serial.println(val);
  delay(100);
}

PeterH

You could attach it to something that resonates when the motor is running?
I only provide help via the forum - please do not contact me for private consultancy.

UKHeliBob

Try moving the sensor to a different place on the dryer.  The dryer has 3 planes in which it can move.  Left/right, forwards/backwards and up/down and all combinations of course.  Try the sensor on the top, side and front to see if you get better readings.

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up