Pages: [1]   Go Down
Author Topic: keeping my hand near the arduino board affects my output  (Read 641 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i made one analog pin(a3) as input and one PWM pin(9) as output. i connected the PWM pin(9) with an LED. when i moved my finger across the analog pin, the led glows brightly. but i din't connect anything in the analog pin(a3). why this is happening?
here is my code:

int ledPin = 9;      // LED connected to digital pin 9
int analogPin = 3;   // potentiometer connected to analog pin 3
int val = 0;         // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);   // sets the pin as output
}

void loop()
{
  val = analogRead(analogPin);   // read the input pin
  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33961
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why this is happening
Because your input is floating.
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
Logged

Pages: [1]   Go Up
Jump to: