Go Down

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

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

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.
No PMs for help please.
Arduino with e'net at http://jimboza.gotdns.com:8085/
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

#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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy