Squirrel Noise Sensor and Map of Dundee Botanical Gardens

by KayOlv in Circuits > Arduino

23 Views, 0 Favorites, 0 Comments

Squirrel Noise Sensor and Map of Dundee Botanical Gardens

IMG_0004.JPEG

How to make a map of Dundee Botanical Gardens and Noise sensor squirrel that dims and brightens neopixels based on input . As well as OLED screen which connects with Ultrasonic sensors

Supplies

download.jpg
download.jpg
download.jpg
images.jpg

Main Map:

1x Wemos LOLIN D1 Mini ESP8266

1x (Arduino Uno for demostrasion)

4x Neopixels

1x Mini Breadboard

Power:

Either ; 1/2x Powerbank or Laptop port and corrosponding Wires

Or

1x Battery Clip Connectors (JSGHGDF PP3 9V Battery Clip Connector)


Noise Sensor:

1x Adafruit Noise Sensor (MAX9814)

1x Wemos LOLIN D1 Mini ESP8266

1x 1x Battery Clip Connectors (JSGHGDF PP3 9V Battery Clip Connector)


Presentation:

MDF 3mm Boards

3D printer and Wood Filament

Step Up the Noise Sensor

IMG_9995.JPEG
IMG_9994.JPEG
IMG_9997.JPEG

The sensor above has had the wires soldered to the D1 mini , noise sensor and voltage convertor due to the limited amount of space in the housing , as well as to prevent any of the wires becoming disconnected.


The components used for this set are a voltage converter which has a ground and 5v wire soldered to the noise sensor and D1 mini , using a copper 'breadboard' to reduce the overall size of the circuit.

The Adafruit MAX9814 microphone is being used as a noise sensor and records and prints the noise levels being picked up in the sounding areas , which is then transmitted to MQTT.

In order to connect the microphone to the D1 mini a wire is soldered between the OUT pin on the microphone and pin A0 on the chip.


A 9v battery is connected to the voltage converter then inserted into the 3D printed squirrel 'topher'.


The voltage converter was connected to a battery and a volt meter and the brass screw was adjusted till the reading on the voltmeter was 5v.


Code for the Noise sensor.

```
//value that sensor output will be assigned to
unsigned int noise;

//link external libraries
#include <ESP8266WiFi.h>
#include <MQTT.h>
#include "conns.h"
WiFiClient net;
MQTTClient client;

// Connecting to the local network , just copy and paste;then change the required fields
void connect() { //create function for code required to connect to the local wifi
Serial.print("checking wifi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.print("\nconnecting...");
//Change name to your own identifier (name, project etc)
while (!client.connect("noisesensor", "", "")) { // eg. noisesensor is the chosen name
Serial.print(".");
delay(1000);
}
Serial.println("\nconnected!"); //confirmation that the Wemos mini has connected to the wifi
}

void setup() {

Serial.begin(115200); //defining the baud rate of the board
WiFi.begin(ssid, pass); //set up to connect to wifi(defined in conns.h folder)
client.begin(myBroker, net); //set up to connect to the broker (defined in conns.h folder)
connect(); //runs connect function

analogReference(EXTERNAL);
pinMode(A0, INPUT); //assigns noise sensor input to pin A0
}
void loop() {

noise = analogRead(A0); //assign the anaolg output from the noise sensor to the integer 'noise'
Serial.print(noise); // serial print this integer

//noise will be a value between 0 and 1024 , most common will be between 250-550.

// calculatevoltage(); //to calculate voltage instead

client.loop(); //function stored in MQQTclient library
delay(500);

if (!client.connected()) { //linked in MQTTclient library
connect(); //links to connect function in document
}

//publish the value to MQTT broker

// client.publish("Monkeynoise", String(volts)); //if voltage
client.publish("Monkeynoise", String(noise)); //if analog output
}
```

'Topher'

IMG_9924.JPEG
IMG_9921.JPEG

'Topher' was a STL file downloaded off of thingiverse then edited in Rhino using apps anywhere in order to create a hole in the bottom to allow the components to fit.

The file was then printed using a Wood filiament , with a 0.6mm nozzle at 0.2mm quality, with lightning infill (very fast and easy to clear out).

The tree supports were removed and the model was sanded down.

Coding Development

Project development showing code

Map and Neopixels

IMG_0004.JPEG
IMG_9998.JPEG

Map is laser cut 2mm MDF with a map of the gardens engraved. With 4 circles cut out for the neopixels and a square in the bottom left corner for a OLED screen.

3 of the neopixels were coded to be consistent as a imitation of what the final product would look like and were connected to a Adruino uno . The neopixels were soldered in place and connected to pin 7 on the arduino

https://dmail-my.sharepoint.com/:u:/g/personal/2567377_dundee_ac_uk/ET7Twg-zPNpNuRXFDoitYJcBdJQ-q5Xd-MUUzqZKorMT7A?xsdata=MDV8MDJ8MjU4NDU1NUBkdW5kZWUuYWMudWt8YjEzYzA3YzMzZWQ2NDRiZmZjOGIwOGRkNmQ0ZGMyZGR8YWUzMjMxMzkwOTNhNGQyYTgxYTY1ZDMzNGJjZDkwMTl8MHwwfDYzODc4NjkwMjkyMjA0OTk2NnxVbmtub3dufFRXRnBiR1pzYjNkOGV5SkZiWEIwZVUxaGNHa2lPblJ5ZFdVc0lsWWlPaUl3TGpBdU1EQXdNQ0lzSWxBaU9pSlhhVzR6TWlJc0lrRk9Jam9pVFdGcGJDSXNJbGRVSWpveWZRPT18MHx8fA%3d%3d&sdata=QU5kOVRwcmpmKzluSFdFQmQvaEN1WmlGTkgxbXVmY3ZNZTZnS3NpLzdEZz0%3d

M

IMG_9999.JPEG
IMG_0002.JPEG
IMG_0001.JPEG

Code for neopixel and OLED screen


The D1 mini is subcribed to the topic 'Monkeynoise' on MQTT and is recieving the output of the noise sensor , which is then converted to a string , and by using if statements with ranges the neopixel connected will change depending on the recieved inputs.


The OLED screen is supposed to display the total amount of visitors in the garden that connects with Harris' code , found on https://www.instructables.com/Ultrasonic-People-Counter-MQTT/



```

//Set up for OLED screen

// OLED D1 -SLC D2 -SDA
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

//OLED Libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//defining screen size
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

//Neopixel library , and set up
#include <Adafruit_NeoPixel.h>

int PIN = D7;
int NUMPIXELS = 1;

Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


//Set up for wifi connection and mqtt broker
#include <ESP8266WiFi.h> //3 libraries to include
#include <MQTT.h>
#include <PubSubClient.h>
const char ssid[] = "**********"; // name of wifi
const char pass[] = ""; // password for wifi
const char myBroker[] = "********"; // name of broker mosquito most times
WiFiClient net;
MQTTClient client;
unsigned long lastMillis = 0;

//integers for noise sensor
int noise = 0; // don't think is needed
int myVal = 0; //the value being recieved from mqtt
int br = 0; //originally brightness : not needed


void connect() {

//connecting to mqtt broker
Serial.print("checking wifi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}

Serial.print("\nconnecting...");
// topic , name , project
while (!client.connect("", "", "")) {
Serial.print(".");
delay(1000);
}
Serial.println("\nconnected!");
client.subscribe("Monkeynoise"); //name of topic to subscribe to
}
void messageReceived(String &topic, String &payload) { // function that recives the data from MQTT and converts it to a string

int myVal = payload.toInt();
Serial.println(myVal);

int br = map(myVal, 175, 500, 0, 255);
// sets the potential ranges of input between 175-500 and the output to 0-255 which is the values used for the neopixels brightness

// strip.setPixelColor(0, strip.Color(255,255,255));
// strip.setBrightness(br);
// code for a white neopixel that changes brightness dependant on input , was changed to rgb to make a clearer demonstrasion


if (myVal < 420) { // if it is quiet

strip.setPixelColor(0, strip.Color(0, 255, 0)); // sets to green
}

else if (myVal > 420 && myVal < 440) { // if the value is in a safe range

strip.setPixelColor(0, strip.Color(255, 69, 0)); // sets it to orange
}

else if (myVal > 440) { // if the value is high

strip.setPixelColor(0, strip.Color(255, 0, 0)); // sets it to red
}
strip.show(); // runs the function that tells the neopixel what colour to be
delay(100);
}
void screen() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;)
;
}
delay(2000);
display.clearDisplay(); // runs the function
display.setTextSize(2); // sets the text size
display.setTextColor(WHITE); // sets the colour of the pixels
display.setCursor(20, 0); // sets the position for the text
display.println("VISITORS"); // text between the brackets for what is to be displayed
display.display(); // runs the function , displays the text
}
void setup() {

pinMode(D7, OUTPUT); // sets the input for the neopixels to D7 (which is also defined above the functions)
// OLED D1 -SLC D2 -SDA pins for the OLED screen
strip.begin(); // runs function strip.begin which connects the neopixels ?
strip.show(); // runs function strip.show which turns on the neopixels

Serial.begin(9600); // set the baud rate to 9600
WiFi.begin(ssid, pass);
client.begin(myBroker, net);
client.onMessage(messageReceived);
connect(); //runs function connect to connect the D1 mini to the wifi
screen(); //run function screen to start . displays visitors at the top of the screen
}

void loop() {

client.loop(); //runs the function client.loop
delay(10); // creates a small delay for the function to run

if (!client.connected()) { //if the requirements for client.connected aren't met run function connect
connect();
}
}