Last active
          February 17, 2023 00:36 
        
      - 
      
- 
        Save carlosefr/dbd5ff54f216aba5999dafe965c180c4 to your computer and use it in GitHub Desktop. 
    Simple electromagnetic field detector with an Arduino
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /* | |
| * Pin A0 -> 2MΩ resistor -> GND | |
| * Pin A0 -> antenna (a piece of wire a few centimeters long) | |
| * | |
| * Pin 11 -> LED -> 330KΩ resistor -> GND | |
| */ | |
| static const char sensorPin = 0; | |
| static const char ledPin = 11; | |
| static const char samples = 10; | |
| void setup() { | |
| pinMode(ledPin, OUTPUT); | |
| } | |
| void loop() { | |
| int sense = 0; | |
| for (int i = 0; i < samples; i++) { | |
| sense += analogRead(sensorPin); | |
| delay(2); | |
| } | |
| sense /= samples; | |
| sense = constrain(sense, 1, 100); | |
| sense = map(sense, 5, 100, 0, 255); | |
| analogWrite(ledPin, sense); | |
| delay(50); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment