Hello All,
I am working on a custom project that involves a DC-powered circuit.
The circuit is parallel: each components is wired in parallel.
The circuit involves two switches for component control. The first switch turns an LED on/off and an Arduino with I2C LDC on/off. There is a power indicator LED before the first switch. The Arduino an ItsyBitsy by Adafruit.
The idea is to get the Arduino to power a pin once a power-detector pin has power. The detector pin is powered by turning ON the second switch.
I am having trouble with the Arduino in that it is ignoring the power-status of the second switch. The second switch is OFF, meaning the detector pin has no power, but the Arduino is still acting as if it was powered. I can pull the detector pin out of the breadboard and it is still acting as if the detector wasn't there.
The IDEA is that once the second switch is ON:
- pin11 reads HIGH which causes pin7 to write HIGH.
- pinA8 now reads what its detecting and the Arduino does some calculations.
- IF: pinA8 is >= 263, THEN: pinA5 is HIGH.
- IF pinA8 is < 263, THEN: pinA5 is LOW, AND pinA1 is HIGH (pinA1 is a function ALARM).
But what's going on here is that pin7 is disregarding the control status of pin11 - pin7 is always on an cycling.
I need pin11 and pin7 to behave properly, otherwise the red and green LEDs are always on when they're supposed to be controlled by switch 2 and pinA8 respectively.
Any help would be great. It's a 5V circuit.
What's really going on here is that the code runs fine when plugged into the USB, but when the USB is unplugged then he red and green LEDs blink when the pin11 is off. The whole thing works fine otherwise (i.e., when the switch is on).
I have posted the script and some pictures for assistance below:
/*
Sketch CGP Joey 2.5 - Itsy Bitsy microcontroller by Adafruit Industries L.L.C.
Author Jordache Boudreau, Innovative Potential Inc., and Innovative Potential L.L.C.,
Version 2.1.5 Board.Version.Edits
Date 1-05-2024
Brief This sketch is used to obtain running information about a CGP.
A blinking LED from pin13 will indicate if the program is on and running.
The sketch will power an I2C LCD, returning a timer, values of voltage and amperes, as milliamps, and a calculated active drug concentration.
There is a circuitbreaker loop for functionality and safety, as well.
For full calculations see Excel file "Innovative Potential - Engeineering - CGP Calculations - 27-06-2023.xls"
Reference Pan, Ethan. (2016). Ultimate Starter Kit. Freenove (http://www.freenove.com)
https://github.com/adafruit/Adafruit-ItsyBitsy-32u4-PCB/blob/master/Itsy%20Bitsy%2032u4%205V%20Pinout.pdf
Copyright Copyright 2023-2024 © Jordache Boudreau and Innovative Potential Inc., and L.L.C.
Website https://www.TheInnnovativePotential.com
License Unlimited: Jordache Boudreau; Inonvative Potential Inc., and Innovative Potential L.L.C.
To work: Upload the script AND THEN press the ItsyBitsy reset button. The blinking light will stop flashing, and remain in the OFF position. Then, the program indicator LED (red) will cycle ON/OFF.
Also: Try chaning the COM channel a bunch of times, it seems to like COM12.
*/
#include <LiquidCrystal_I2C.h>
#include <FlexiTimer2.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int voltPin = 0;
int hour, minute, second;
int adcValue;
float volts;
float amps;
float moles_e; //moles of electrons
float moles_AD; //Active Drug
float SSO; //Steady State Output concentratin of active drug
float MTV; //Maximum Tumor Volume
void setup() {
if (!i2CAddrTest(0x27)) {
lcd = LiquidCrystal_I2C(0x3F, 16, 2);
}
lcd.init();
lcd.backlight();
startingAnimation();
FlexiTimer2::set(1000, timerInt);
FlexiTimer2::start();
Serial.begin(9600);
Serial.println("Initializing...");
Serial.println("Input hour, minute, and second to set time.");
pinMode(A1, OUTPUT); //initialize digital pin 19 (A1) as an OUTPUT for BUZZER.
pinMode(A5, OUTPUT); //initialize digital pin 23 (A5) as an OUTPUT for Green LED.
pinMode(13, OUTPUT); //initialize digital pin 13 as an OUTPUT for board-based Red LED.
pinMode(7, OUTPUT); //initialize digital pin 9 as an OUTPUT for the electrochemical cell.
pinMode(A11, OUTPUT);
pinMode(11, INPUT); //initialize digital pin 12 as an INPUT for relaying power to the electrochemical cell.
pinMode(A8, INPUT); //initialize digital pin 8 (A8) as an INPUT for reading the aDcValue from the electrochemical cell.
}
void loop() {
adcValue = analogRead(A8);
volts = adcValue * (5.0 / 1023);
amps = (volts / 250) * 1000;
moles_e = ((amps * 21000) / 96400); //21000 = 21 s residency time; and 96400 is Faraday's constant
moles_AD = (moles_e * 0.5 * 1); //0.5 = 1 mole of prodrug converted to active drug (AD) for every 2 moles of electrons; Arduino hated that "moles_AD * (1/2)" syntax
SSO = (moles_AD / 0.00135) / 1000; //0.00135 is volume of ECell of CGP, 1x10^6 is conversion to millimolars.
MTV = ((SSO / 3) / 0.000414); // there is a 3-fold dilution factor when putting a concentration into a spherical tumor.
digitalWrite(13, HIGH); //turn the LED on (HIGH is the voltage level)
delay(1500); //wait for 1.5 seconds (1500 miliseconds)
digitalWrite(13, LOW); //turn the LED off (LOW is the voltage level)
delay(1500); //wait for 1.5 seconds (1500 miliseconds)
//digitalWrite(A11, HIGH); //Remove the // for debugging on PC.
if (digitalRead(11) == 0) {
digitalWrite(7, LOW);
digitalWrite(A8, LOW);
digitalWrite(A5, LOW);
digitalWrite(A1, LOW);
}
else if (digitalRead(11) == 1) {
digitalWrite(7, HIGH);
digitalWrite(A8, LOW);
digitalWrite(A5, LOW);
digitalWrite(A1, LOW);
}
if (analogRead(A8) >= 263) {
digitalWrite(A5, HIGH);
digitalWrite(A1, LOW);
}
else if (analogRead(A8) < 263) {
digitalWrite(A5, LOW);
}
if ((digitalRead(11) == 1) && (digitalRead(7) == 1) && (analogRead(A8) < 263)) {
digitalWrite(A1, HIGH);
delay(500);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(500);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(500);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(500);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(100);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(100);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(100);
digitalWrite(A1, LOW);
delay(100);
digitalWrite(A1, HIGH);
delay(100);
digitalWrite(A1, LOW);
delay(100);
}
Serial.print("PIN 11 Digital Value: ");
Serial.println(digitalRead(11));
Serial.print("PIN 7 Digital Value: ");
Serial.println(digitalRead(7));
Serial.print("PIN A8 Analog Value: ");
Serial.println(analogRead(A8));
Serial.print("PIN A8 Signal Value (Anode Value): ");
Serial.println(adcValue);
Serial.print("Volts (V): ");
Serial.println(volts);
Serial.print("Amps (mA): ");
Serial.println(amps);
Serial.print("Moles of Electrons (umol): ");
Serial.println(moles_e);
Serial.print("Moles of Active Drug (umol): ");
Serial.println(moles_AD);
Serial.print("Intravanous Flow Rate (mL/h): ");
Serial.println(230);
Serial.print("Anode Compartment Volume (mL): ");
Serial.println(13.5);
Serial.print("Residency Time (s): ");
Serial.println(21.00);
Serial.print("Steady State Output of Active Drug (mM): ");
Serial.println(SSO);
Serial.print("Mimimum Treatable Tumor Volume (mL): ");
Serial.println(MTV);
Serial.print("------------");
Serial.println();
lcdDisplay();
delay(1000);
if (second >= 60) {
second = 0;
minute++;
if (minute >= 60) {
minute = 0;
hour++;
if (hour >= 24) {
hour = 0;
}
}
}
}
void startingAnimation() { //Displays words on I2C LCD startup animation.
for (int i = 0; i < 16; i++) {
lcd.scrollDisplayRight(); //moves words in from the right direction.
}
lcd.print(" Doin' Stuff..."); //words to display "_____".
for (int i = 0; i < 16; i++) {
lcd.scrollDisplayLeft();
delay(500); //displays word on the screen for 500 miliseconds.
lcd.setCursor(0, 1); //print on LCD second line.
lcd.print(""); //words to display "______".
}
lcd.clear();
}
void timerInt() {
second++;
}
void serialEvent() {
int inInt[3];
while (Serial.available()) {
for (int i = 0; i < 3; i++) {
inInt[i] = Serial.parseInt();
}
Serial.print("Your input is: ");
Serial.print(inInt[0]);
Serial.print(", ");
Serial.print(inInt[1]);
Serial.print(", ");
Serial.println(inInt[2]);
hour = inInt[0];
minute = inInt[1];
second = inInt[2];
Serial.print("Time now is: ");
Serial.print(hour / 10);
Serial.print(hour % 10);
Serial.print(':');
Serial.print(minute / 10);
Serial.print(minute % 10);
Serial.print(':');
Serial.print(second / 10);
Serial.println(second % 10);
}
}
void lcdDisplay() {
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(hour / 10 );
lcd.print(hour % 10);
lcd.print(':');
lcd.print(minute / 10);
lcd.print(minute % 10);
lcd.print(':');
lcd.print(second / 10);
lcd.print(second % 10);
lcd.setCursor(0, 1);
lcd.print("mA:");
lcd.print(amps);
lcd.setCursor(8, 1);
lcd.print("D:");
lcd.print(SSO);
lcd.print("mM");
}
float getAmps() {
int adcVal = analogRead(A8);
float volts = adcVal * (5.0 / 1024);
float amps = volts * 10000;
return amps;
}
float getmoles_e() {
int adcVal = analogRead(A8);
float volts = adcVal * (5.0 / 1024);
float amps = volts * 10000;
float moles_e = ((amps * 21000) / 96400);
return moles_e;
}
float getmoles_AD() { //Returns the value of Active Drug based on prodrug concentration.
int adcVal = analogRead(A8);
float volts = adcVal * (5.0 / 1024);
float amps = volts * 10000;
float moles_e = ((amps * 21000) / 96400); //The rate limiter is the moles of electrons, therefore the starting moles of prodrug is irrelevant, this is massive oversimplification.
float moles_AD = (moles_e * 0.5 * 1); //moles electron to moles prodrug is 1:2; moles of prodrug to active drug ratio is 1:1, dependent on prodrug
return moles_AD;
}
float getSSO() {
int adcVal = analogRead(A8);
float volts = adcVal * (5.0 / 1024);
float amps = volts * 10000;
float moles_e = ((amps * 21000) / 96400);
float moles_AD = (moles_e * 0.5);
float SSO = (moles_AD / 0.00135) / 1000 ; //This is a concentration estimate of active drug output
return SSO;
}
float getMTV() {
int adcVal = analogRead(A8);
float volts = adcVal * (5.0 / 1024);
float amps = volts * 10000;
float moles_e = ((amps * 21000) / 96400);
float moles_AD = (moles_e * 0.5);
float MTV = ((SSO / 3) / 0.000414); //spatial volume of tumor is a 3x dilution factor; 414 uM is BQ LC99; USE EACH MOLECULE LC99 HERE.
return MTV;
}
bool i2CAddrTest(uint8_t addr) {
Wire.begin();
Wire.beginTransmission(addr);
if (Wire.endTransmission() == 0) {
return true;
}
return false;
}