Pages: 1 [2]   Go Down
Author Topic: Led on Led send  (Read 1385 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4335
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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




Code:
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);
}
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could attach it to something that resonates when the motor is running?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4335
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

Pages: 1 [2]   Go Up
Jump to: