EMI sketch details in Environmental Monitoring with Arduino

I built the EMI gadget and it makes the same noise all the time. I'd like to know more about the sketch.
Where could I get some info about what this code does and how? I'd like to understand it and not just type into Arduino.
1 person has
this question
+1
Reply
  • Brian Jepson (Editor, Maker Media, Inc.) May 12, 2013 21:30
    Hi Attila,

    I'll ask the authors to get some information together on this to share with you.

    Regards,

    Brian
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated happy, confident, thankful, excited

  • It's really pretty simple!

    The long wire is an antenna. As we say in the book: "Arduino’s analog input normally takes a reading of the electrical energy coming into the analog port. But because we have connected an antenna to that port, the antenna is absorbing electrical voltage from the radio signals given off by electronic equipment, and directing it into the analog port.

    Arduino analog’s port can take voltage from zero to a maximum of 5 volts, and it measures this voltage in 1024 discrete slices (making each slice worth 0.0048828 volts). For example, when Arduino tells us that the reading from the analog port is, say, 250, it is telling us that the antenna wire is picking up 1.2207 volts of EMI energy (250 × 0.0048828)."

    The arduino map() function then takes that input from the analog port and maps it over a wider span of values, from 0 to 2048.

    Arduino then takes the newly-mapped input value, from 0 to 2048, and sends it to the tone() function. Tone() takes the mapped analog port value and plays that value as an audio frequency: if the mapped analog value was 1053, for example, arduino would play a tone of 1053 hertz.

    So you can see, as more and more EMF energy flows into the antenna, the pitch of the tone should get higher and higher.

    If your EMF detector is making only one tone, there are several things to check:
    1) Are you using the proper resistor with the antenna? Try changing the resistor and see if you get different sounds.

    2) The EMF detector works best when it is powered by a separate power supply -- NOT by the USB cable. Try that, if you haven't.

    3) Make sure the map() function is written correctly.

    4) Did you test the speaker connection with the little melody program shown in the beginning of the chapter? Make sure that works.

    Good luck!!!!!!!!!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Thank you Patrick and Brian,

    It make sense. Everything works, but I was using the USB.
    The info about the map() function was helpful also.

    there is something else I can't figure out.
    #include
    #define SerialIn 2
    #define SerialOut 7
    ...
    SoftwareSerial mySerialPort(SerialIn, SerialOut);
    ...
    pinMode(SerialOut, OUTPUT);
    pinMode(SerialIn, INPUT);

    Why are these pin "definitions" in the program if we don't connect anything to pin 2 and 7 ?
    Or I just missed something important while I was reading? If the question would be too trivial, my excuse is that I just bought my first Arduino a weak ago.

    Thank you again.

    Attila.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated happy, confident, thankful, excited