Piezo Hall

A sketch that beeps the Piezo based on the strenght of the magnetic field at the hall sensor (thin gieger counter for magnetic fields)

Hardware used:
  • Switch
  • Hall Sensor
  • Piezo
  • LED
Code Used:
  • analogRead
  • digitalWrite
  • analogWrite

#include <Servo.h> 

/* Rotary encoder read example */
#define ENCODER_A 14
#define ENCODER_B 15
#define SWITCH 13
#define BUTTON 12
#define RGB_RED 11
#define RGB_GREEN 10
#define RGB_BLUE 9
#define LED 6
#define SERVO 5
#define PIEZO 3
#define RELAY 2
#define POT 2
#define HALL 3
#define THERMISTOR 4
#define PHOTOCELL 5

void setup()
  pinMode(SWITCH, INPUT);  
  pinMode(PIEZO, OUTPUT);
  pinMode(LED, OUTPUT);
void loop()
  if (digitalRead(SWITCH) == HIGH) {
    analogWrite(PIEZO, 128);
    digitalWrite(PIEZO, LOW);
  } else {
    digitalWrite(LED, HIGH);
    digitalWrite(LED, LOW);


Leave a Reply

Your email is never published nor shared.

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>