/*
Magsensor
Magnetic proximnity sensor for bell simulator.
*/
// constants won't change. They're used here to
// set pin numbers:
const int sensorPin = 2; // the number of the proximity sensor signal pin
const int ledPin = 13; // the number of the LED pin
int sensorState = LOW;
void setup() {
Serial.begin(2400);
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
// set initial LED state
digitalWrite(ledPin, LOW);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(sensorPin);
digitalWrite(ledPin, reading);
if (reading != sensorState) {
sensorState = reading;
if (sensorState == HIGH) {
Serial.print("1");
}
}
}
Parts:
KY-024 Hall effect sensor (£3 – £4)
neodymium magnet (can be salvaged from an old hard drive)
epoxy glue to attach magnet to wheel
Arduino Uno (£20)
Male to Female Jumper Cables
USB device cable and extension cable