1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to const int ledPin = 13; int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) int threshold = 515; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: //outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: //analogWrite(analogOutPin, outputValue); if(sensorValue < threshold) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.println(""); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); } |
- without magnet, ouput reading at 522
- with magnet place in direction of the top of board, output reading range between 522- 770
- with magnet place in direction of the bottom of board, output reading range between 522-413