There is a ghost in my computer. Or maybe it's a caterpillar.
Things that are happening:
- Arduino not being registered in port
- Try another Arduino? No change.
- Try another cable? No change.
- Try another dongle? No change.
- Power cycle? No change.
- Plug into Sam Heckle's computer? It registers! [Nothing else happens, just plugging in]
- Now plug back into my computer? It works.
WEIRD!
- Sound sensor all of a sudden not giving accurate readings.
- Oh! That's ok I have a new one. Doesn't work.
- Did the code change? No.
- Is my circuit ok? Yes, no change. Is it possible that both sensors are broken all of a sudden?
- Try Bianca's different sound sensor on Bianca's computer. It works with my Arduino! This is a good sign.
- Try on my computer. Same code, same sensor, same Arduino. Getting different readings.
WEIRD!
This is what I'm working with:

IT"S SO SIMPLE.
A simple Arduino code to make sure it's running:
void setup() {
// put your setup code here, to run once:
pinMode(A1, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int sound = analogRead(A1);
Serial.println(sound);
delay(100);
}
The MAX4466 code that translates the data into values that I want:
/*
MAX4466 sample code
based on by Shani Mensing and Audrey St John at MHC
rewritten by JML2023
circuit: VCC to 3.3V, OUT to A0
*/
#define MIC A1
int sampleWindow = 50;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(MIC, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
double sound = soundDiff();
//this is the actual reading you want
double soundCalc = (sound * 3.3)/1024;
Serial.print(sound);
Serial.print(",");
Serial.println(soundCalc);
delay(100);
if (soundCalc > 0.99){
Serial.println("YOU VOTED!");
}
}
double soundDiff(){
//record start time
double startMillis = millis();
//high peak, top range
int signalMax = 0;
//low peack, bottom range
int signalMin = 1024;
//sample period
int sample;
//collect data for sample length
while( (millis() - startMillis) < sampleWindow){
sample = analogRead(MIC);
if (sample < 1024){
//if sample is larger than 0
if (sample > signalMax){
//this is the new sample max
signalMax = sample;
}
else if (sample < signalMin){
signalMin = sample;
}
}
}
int peakDiff = signalMax - signalMin;
return peakDiff;
}
Code to send MAX4466 over WiFiTCP that was very reliable:
/*
MAX4466 Microphone over WiFi TCP
Modified by Julia Margaret Lu
Feb 2 2023
WiFi TCP Client
TCP Socket client for WiFiNINA and WiFi101 libraries.
Connects to the TCP socket server, reads a sensor once
every five seconds, and sends a message with the reading.
Uses the following libraries:
http://librarymanager/All#WiFiNINA.h for Nano 33 IoT, MKR1010
or
http://librarymanager/All#WiFi101.h for MKR1000
You'll need to include an arduino_secrets.h file with the following info:
#define SECRET_SSID "ssid" // your network name
#define SECRET_PASS "password" // your network password
Here's a test with netcat:
char serverAddress[] = "x.x.x.x"; // replace with your computer's IP
then on your computer, run netcat:
$ nc -l 8080 tee log.json
This will send the output to the command line and to a file called log.txt
created 30 Dec 2022
by Tom Igoe
*/
// #include <WiFi101.h> // use this for MKR1000 board
#include <WiFiNINA.h> // use this for Nano 33 IoT or MKR1010 boards
#include "arduino_secrets.h"
// Initialize the Wifi client library
WiFiClient client;
// replace with your host computer's IP address
const char server[] = "10.23.11.154";
const int portNum = 8080;
// message sending interval, in ms:
int interval = 10;
// last time a message was sent, in ms:
long lastSend = 0;
//define Mic pin
// #define MIC A0;
//data sample window in millis
int sampleWindow = 50;
void setup() {
//Initialize serial
Serial.begin(9600);
// if serial monitor's not open, wait 3 seconds:
if (!Serial) delay(3000);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
// Connect to WPA/WPA2 network.
WiFi.begin(SECRET_SSID, SECRET_PASS);
// wait 3 seconds for connection:
delay(3000);
}
//MAX4466 pin mode
pinMode(A0, INPUT);
}
void loop() {
// if the client's not connected, connect:
if (!client.connected()) {
Serial.println("connecting...");
client.connect(server, portNum);
// skip the rest of the loop:
return;
}
if (client.connected()){
Serial.println("connected!");
}
// once every interval, get a reading and send it:
// if (millis() - lastSend > interval) {
// // read sensor:
// int sensor = analogRead(A0);
// // format the message as JSON string:
// String message = "{\"sensor\": READING}";
// // replace READING with the reading:
// message.replace("READING", String(sensor));
// // send the message:
// client.println(message);
// // update the timestamp:
// lastSend = millis();
// }
double sound = soundDiff();
//this is the actual reading you want
double soundCalc = (sound * 3.3)/1024;
// Serial.println(soundCalc);
if(soundCalc > 0.99){
//format the message to match tom's example for JSON
String message = "{\"YOU VOTED YES\": 1}";
digitalWrite(13, HIGH);
//replace READING with the reading:
// message.replace("READING", String(soundCalc));
//send the message:
client.println(message);
//update the timestamp:
// lastSend = millis();
delay(3000);
String reset = "{\"waiting for action\": 0}";
client.println(reset);
} else{
digitalWrite(13, LOW);
}
// check if there is incoming data available to be received
int messageSize = client.available();
// if there's a string with length > 0:
if (messageSize > 0) {
Serial.println("Received a message:");
Serial.println(client.readString());
}
}
double soundDiff(){
//record start time
double startMillis = millis();
//high peak, top range
int signalMax = 0;
//low peack, bottom range
int signalMin = 1024;
//sample period
int sample;
//collect data for sample length
while( (millis() - startMillis) < sampleWindow){
sample = analogRead(A0);
if (sample < 1024){
//if sample is larger than 0
if (sample > signalMax){
//this is the new sample max
signalMax = sample;
}
else if (sample < signalMin){
signalMin = sample;
}
}
}
int peakDiff = signalMax - signalMin;
return peakDiff;
}
UPDATE
I swapped in a new Arduino and I'm getting proper readings again but after 10 seconds the sensors start to go haywire. Not sure what's happening here..........
UPDATE
There seemed to be some crossover or some weirdness from having two sensors connected at the same time (1 was being called on, 1 was not)
Other weirdness:
Does the sound sensor pick up conductivity from the metal bucket? It might.