Hello all,
I’m a hardware person at heart, and have recently been getting back into software to develop a piece of scientific apparatus. The field is in perceptual psychology/ olfaction and I’m developing a new type of device called a pulse olfactometer.
Essentially, a pump fills two chambers with smell, and then a valve array distributes the air to right and left nostrils. Where I work as a research assistant, we’re hoping to use the device to discover new things about how our sense of smell works (for instance, suppose that I pump a strawberry odour into your left nostril, and lemon to your right - would you notice if I briefly reversed the polarity?) Here’s what the UI looks like:
Introductions aside, I’m having some difficulty programming even the basic functions because my knowledge is pretty poor. The basic operation is like this (I’ll paste what code I have later, but for now just in “arduinenglish”)
if (begin button pressed) // button widget
turn on (pump)
delay(fill duration) // value from numerical input widget
turn off (pump)
delay (release delay) // value from numerical input widget
turn on (some selection of valves) // based on which valves selected in app
delay (duration) // how long the selection of valves left open, from app numerical input
turn off (all valves)
if(reset button pressed)
abort sequence and wait for begin button again
Hardware model: ESP8266/ NodeMCU12E +wifi
Android Oreo with Blynk app
• Blynk server
• Blynk Library downloaded a few days ago
I know that this is a relatively simple project, but I don’t know how to use the value from the numerical input as the fill duration, and then how to set that as the delay between turning the pump on and off again.
Here is my code so far (sadly not much, I know), I’ve taken out the bits I know to be wrong (not sure if that’s helpful):
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloudcom", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
const int pump = 7;
const int valve1 = 17;
const int valve2 = 18;
const int valve3 = 20;
const int valve4 = 4;
long fillduration;
int releasedelay;
int duration;
pinMode(pump, OUTPUT); // Sets the pump as an output
pinMode(valve1, OUTPUT); // Sets valve1 as an output
pinMode(valve2, OUTPUT); // Sets valve2 as an output
pinMode(valve3, OUTPUT); // Sets valve3 as an output
pinMode(valve4, OUTPUT); // Sets valve4 as an output
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V3) { // pump fill duration input in app
fillTime = param.asInt();
BLYNK_WRITE(V4) { // delay between pmp stopping and valves opening
releasedelay = param.asInt();
BLYNK_WRITE(V5) { // valve 1 selection switch
fillTime = param.asInt();
// and so on
}
Thanks so much and of course I would be happy to give anyone that helps a mention in any academic papers which this device is used to collect data for (if they so wish!)
Many thanks
Harry