Go Down

Topic: LED and Hall Effect Sensor - Inverse Reaction? (Read 553 times) previous topic - next topic

elementcollector1

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.

Chagrin

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

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

elementcollector1

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?

JimboZA


-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.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

elementcollector1

#4
Feb 24, 2014, 04:20 am Last Edit: Feb 24, 2014, 06:06 am by elementcollector1 Reason: 1
Yep, it's 1023. Couldn't remember the exact number, so I gave a very rough estimate.

Go Up