Difference between revisions of "Project Hall Sensor"
(Created page with "<syntaxhighlight lang="c"> /* Analog input, digital output, serial output Reads an analog input pin; T000070 Hall Sensor connected to I0 reacts to the magnet direction ...") |
(No difference)
|
Latest revision as of 00:59, 24 November 2012
<syntaxhighlight lang="c">
/*
Analog input, digital output, serial output
Reads an analog input pin; T000070 Hall Sensor connected to I0 reacts to the magnet direction and uses the result to light up a T010111 LED Module connected on O0. Also prints the value of the Hall Sensor to the serial monitor.
created on 7 Dec 2010 by Davide Gomba
This example code is in the public domain.
*/
#define O0 11 #define O1 10 #define O2 9 #define O3 6 #define O4 5 #define O5 3 #define I0 A0 #define I1 A1 #define I2 A2 #define I3 A3 #define I4 A4 #define I5 A5
// These constants won't change. They're used to give names // to the pins used: const int analogInPin = I0; // Analog input pin that the Hall Sensor is attached to const int digitalOutPin= O0; // Digital output pin that the LED is attached to
int sensorValue = 0; // value read from the Linear pot
void setup() {
// initialize serial communications at 9600 bps: Serial.begin(9600); pinMode(digitalOutPin, OUTPUT);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
if (sensorValue < 505) { // notice that the normal value of the sensor is 510 digitalWrite(digitalOutPin, HIGH); } else { digitalWrite(digitalOutPin, LOW); } // print the results to the serial monitor: Serial.print("Hall Sensor Value = " ); Serial.println(sensorValue);
// wait 10 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(10);
}
<syntaxhighlight>