Pages: [1]   Go Down
Author Topic: LED and Hall Effect Sensor - Inverse Reaction?  (Read 350 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was wondering if it would be possible to write a code that takes the input from a Hall Effect sensor, and as the input increases, a LED dims proportionally.
I have this information to work with:
-The LED is set to pin 3.
-The Hall Effect Sensor is on pin A0.
-Standard reading for a HES when no magnet is nearby is ~510.
-Maximum reading for a HES, when the magnet is touching it is ~1050.
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 33
Posts: 2277
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
analogWrite(LEDPIN, map(analogRead(HALLPIN), 510, 1050, 255, 0));

See http://arduino.cc/en/reference/map
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure I fully understand. This would effectively turn a range of 510-1050 from the HES to a 'backwards range' of 255-0? That part mostly makes sense, but how does the Arduino know that '255' is the maximum for a LED?
Logged

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

-Maximum reading for a HES, when the magnet is touching it is ~1050.

Where did you get that value from?- Arduino analog inputs are never more than 1023.

how does the Arduino know that '255' is the maximum for a LED?

It's the maximum for an analogWrite- same as using a digitalWrite to set the pin high.
Logged

Retired from Arduino.
PMs are set to ignore all.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep, it's 1023. Couldn't remember the exact number, so I gave a very rough estimate.
« Last Edit: February 24, 2014, 12:06:44 am by elementcollector1 » Logged

Pages: [1]   Go Up
Jump to: