Skip to content

Week 5

Circuit

This week, I rebuilt my circuit with generous assistance. I removed Programmable Air in favor of using the air pump components directly.

I started by transferring the circuit to a larger breadboard, since it now has 4 sections with 5 attachments (USB power, power supply, 2 air pumps, air valve):

  1. Arduino 33 Nano IoT, hooked up to USB power
  2. Air valve: solenoid screwed into a screw terminal on the billboard, with a diode to TIP102
  3. Sparkfun motor driver with capacitors, connected to Arduino and the 2 air pumps
  4. Power input: 9V power supply hooked up to a L7805 voltage regulator and heat sink

The motor architecture is more complicated than I expected, but every component serves a clear purpose. Each air pump can only go one direction, and since I want to both blow and suck in this project (as the air quality worsens then improves), I need two pumps. The motor driver lets me programmatically turn each one on successively. The two pumps are connected by silicone tubing, and the solenoid air valve switches which one’s airflow is output to the pillow.

Electrically, the project runs at a total of ~12V, split into two circuits. The Arduino pulls its 3.3V over USB. Separately, a 9V variable power supply powers the 5V air valve plus the 4.5V air pump (only one at a time). The voltage regulator that regulates the power input generates a ton of heat even at 9V, so a heat sink improves safety. (Without a heatsink, any nearby cables produce a noticeable scent from the heat radiating off the voltage regulator.)

I soldered my own motor driver to header pins, which was the first time I soldered header pins. Unfortunately, even after successfully checking continuity with a multimeter, the component failed. I also soldered the two leads on each of the two air pumps, but the first time I put them in my backpack, 3/4 cable connections snapped. That was my first time desoldering, which took at least an hour longer than I expected, but with some help from the shop staff, I removed the old cable ends and solder and soldered fresh cables, this time with heat shrink on all the connections, and verified the electrical connections again.

Arduino

I started over on the Arduino software without Programmable-Air in the mix. I set up the motor driver pins, plus the air valve, as digital ouputs of the Arduino, and made a test program that would turn on the first motor for two seconds then the second pump for four seconds to validate everything was working.

Arduino testing code
const int motor1Pin = 4; // Motor driver 1 leg 1 (pin 4, AO1)
const int motor2Pin = 5; // Motor driver 1 leg 2 (pin 5, AO2)
const int motor3Pin = 7; // Motor driver 2 leg 1 (pin 7, BO1)
const int motor4Pin = 8; // Motor driver 2 leg 2 (pin 8, BO2)
const int valvePin = 12;
void setup() {
Serial.begin(9600);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(pwm1Pin, OUTPUT);
pinMode(pwm2Pin, OUTPUT);
pinMode(valvePin, OUTPUT);
}
void loop() {
// Inflate:
// Turn on valve, turn on motor 1, turn on motor 2
digitalWrite(valvePin, HIGH);
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, LOW);
delay(2000);
// Deflate:
// Turn off valve, turn off motor 1, turn on motor 2
digitalWrite(valvePin, LOW);
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, LOW);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, HIGH);
delay(4000);
}

Next, I re-integrated Adafruit IO to conttrol the stages over Wi-Fi:

Arduino code with Adafruit IO over Wi-Fi
#define IO_USERNAME ""
#define IO_KEY ""
#define WIFI_SSID "sandbox370"
#define WIFI_PASS "+s0a+s03!2gether?"
#define ARDUINO_SAMD_MKR1010
#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
AdafruitIO_Feed *relay = io.feed("airquality");
const int motor1Pin = 4; // Motor driver 1 leg 1 (pin 4, AIN1)
const int motor2Pin = 5; // Motor driver 1 leg 2 (pin 5, AIN2)
const int motor3Pin = 7; // Motor driver 2 leg 1 (pin 7, AIN1)
const int motor4Pin = 8; // Motor driver 2 leg 2 (pin 8, AIN2)
const int valvePin = 12;
int stage = 0;
void setup() {
Serial.begin(9600);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(valvePin, OUTPUT);
Serial.print("Connecting to Adafruit IO");
// connect to io.adafruit.com
io.connect();
relay->onMessage(handleMessage);
// wait for a connection
while (io.status() < AIO_CONNECTED) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
delay(500); // wait a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
relay->get();
}
void handleMessage(AdafruitIO_Data *data) {
Serial.print("feed received new data <- ");
Serial.println(data->toChar());
stage = data->toInt();
}
void loop() {
Serial.println(stage);
io.run();
if (stage == 1) {
Serial.println("Stage 1 running");
// Inflate:
// Turn on valve, turn on motor 1, turn on motor 2
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, LOW);
digitalWrite(valvePin, HIGH);
// digitalWrite(pwm1Pin, LOW);
// digitalWrite(pwm2Pin, HIGH);
delay(2000); // 10 seconds
}
if (stage == 2) {
Serial.println("Stage 2 running");
// Deflate:
// Turn off valve, turn off motor 1, turn on motor 2
digitalWrite(valvePin, LOW);
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, LOW);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, HIGH);
delay(4000);
}
}

Technical issues

After I soldered new wires onto the motors, I verified they both worked when plugged into power, and I heat shrank the connections so they don’t fail again. I plugged them both into the motor driver, and had the same Arduino code running, and the motors alternately turned on, just as I wanted.

I kept working on the software, including integrating Adafruit IO, and the hardware stopped working; even when I flashed the exact same program that worked prior, the motors will not turn on. I’m not an expert with the multimeter but I’m seemingly getting current out of the H bridge, I’ve got 9V coming in as expected, and it’s not an electrical issue with the motors (they turn on when powered directly). I’ve run through every debugging technique I can think of, but I’m going to try getting another H bridge next.

In the meantime, I’m sadly manually controlling the motors for playtesting. It’s a huge let-down after so many hours of work making the circuit work.

Schematic

I came into this class knowing next to nothing about schematics. I am still far from an expert, but my eyes don’t merely glaze over now. This week, I made a schematic for my project. I first tried Fritzing since I know it’s popular, but it had next to none of the components I wanted to use. Diode similarly didn’t support the Nano 33 IoT. I landed on Flux, a web-based editor with an extensive community collection of components. I did not find anything workable for the air valve there, so it’s still missing from this schematic, and I likely messed up modeling the power flow, but most of the components are there.

Website

I fleshed out the website this week, doing a lot of research, writing, art direction, and chart-making. I continued the visual direction I set with last year’s project Flareup, since this is a similar storyline in a European city with similar display needs. My primary sources for writing were:

One particular challenge was the map of London power stations, which I could not find an existing aggregated source for. I started with Wikipedia’s List of power stations in England, which I downloaded as a CSV using this handy tool, then filtered the data in Numbers to London-area plants. Several of the facilities were lacking geo coordinates, so I used Google Maps to manually geocode them and convert the coordinates to separate columns, before plotting them all on Mapbox.

Next week

  • Lay flat the wires on the breadboard
  • Try analogWrite 0-255 to PWM pins to get slower speed
  • Improve website storytelling