Before we started creating our circuit, we made a truth table and wrote some equations which our circuit could follow. If no symptoms are present, the light becomes green. If one is present, the light becomes yellow, and if two are present, the light becomes red and the patient's symptoms are transmitted to the healthcare provider. In the worst case scenario that all three symptoms are present, an alarm sounds and emergency services are contacted.
In our first design, we followed our truth table and used "and" and "or" statements to turn on one of three lights. We did not add the alarm wiring yet due to its complexity. In future designs, we could decide to add resistors, capacitors, regulators, and flip-flops. We should also properly ground our design.
Our second design changed the wiring to prevent a short circuit from happening. Still, the logic behind this circuit is the same as the first, since we use "and" statements to determine which risk factors are happening and "or" statements to determine which light should turn on. This design includes the alarm system, flip flops, and a timer for the flip flops.
We struggled to figure out why our second design was not working when we realized that we forgot a clock to match the time intervals from the timer. We added this and our design worked!
Final Design link: https://www.circuitlab.com/circuit/w92suadns9d7/week-3-circuit-version-2/
In our first TinkerCAD design, we tried to make the RGB light and speaker work, and we did not really worry about the prompt. We coded the lights to swap from green to yellow to red, then played Yankee Doodle on the speaker. This was simply to learn how to program and connect different components.
Even though we don't have access to two of the sensors, we still coded for them in our final code.
int red_light_pin = 11;
int yellow_light_pin = 10;
int green_light_pin = 9;
int speaker_pin = 12;
int temp_pin = 0;
const int oxy_pin = 1;
int mic_pin = 2;
int symCounter = 0;
const float VRefer = 5.0;
float oxyConcentration;
float temp;
float sound;
float db = 0;
void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(yellow_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(speaker_pin, OUTPUT);
pinMode(mic_pin, INPUT);
pinMode(temp_pin, INPUT);
pinMode(oxy_pin, INPUT);
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop() {
int reading = analogRead(temp_pin);
float milliVolts = reading * (5000/1024);
temp = (milliVolts - 500) / 10; // analog input to temperature
oxyConcentration = readConcentration();
sound = analogRead(mic_pin);
db = (sound+83.2073) / 11.003; // analog input to decibels
symCounter = 0;
checkSymptoms();
Serial.print(symCounter);
if (symCounter == 0){
greenOn();
}
else if (symCounter == 1){
yellowOn();
}
else if (symCounter == 2){
redOn();
}
else if (symCounter == 3){
soundAlarm();
}
}
float readO2Vout()
{
long sum = 0;
for(int i=0; i<32; i++)
{
sum += analogRead(oxy_pin);
}
sum >>= 5;
float MeasuredVout = sum * (VRefer / 1023.0);
return MeasuredVout;
}
float readConcentration()
{
float MeasuredVout = readO2Vout();
float Concentration = MeasuredVout * 0.21 / 2.0;
return Concentration;
}
void soundAlarm(){
tone(speaker_pin, 1000);
}
void redOn(){
digitalWrite(green_light_pin, LOW);
digitalWrite(yellow_light_pin, LOW);
digitalWrite(red_light_pin, HIGH);
}
void yellowOn(){
digitalWrite(green_light_pin, LOW);
digitalWrite(yellow_light_pin, HIGH);
digitalWrite(red_light_pin, LOW);
}
void greenOn(){
digitalWrite(green_light_pin, HIGH);
digitalWrite(yellow_light_pin, LOW);
digitalWrite(red_light_pin, LOW);
}
void checkSymptoms(){
if (temp >= 22){
symCounter++;
}
if(oxyConcentration <= 0.9){
symCounter++;
}
if(db >= 80){
symCounter++;
}
}
Our second design made use of the temperature sensor and updated the LEDs to match each scenario. If there were three symptoms at the same time, the buzzer would sound as an alarm. However, we did not use an oxygen sensor or sound sensor since TinkerCad did not have it. We manually controlled these two risk factors by changing the conditions in the "if" statements.
int red_light_pin = 11;
int yellow_light_pin = 10;
int green_light_pin = 9;
int speaker_pin = 12;
int temp_pin = 0;
int symCounter = 0;
bool highTemp = false;
float temp;
bool dryCough = false;
bool lowOxygen = false;
void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(yellow_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(speaker_pin, OUTPUT);
}
void loop() {
int reading = analogRead(temp_pin);
float milliVolts = reading * (5000/1024);
temp = (milliVolts - 500) / 10;
symCounter = 0;
checkSymptoms();
if (symCounter == 0){
greenOn();
}
else if (symCounter == 1){
yellowOn();
}
else if (symCounter == 2){
redOn();
}
else if (symCounter == 3){
soundAlarm();
}
}
void soundAlarm(){
tone(speaker_pin, 1000);
}
void redOn(){
digitalWrite(green_light_pin, LOW);
digitalWrite(yellow_light_pin, LOW);
digitalWrite(red_light_pin, HIGH);
}
void yellowOn(){
digitalWrite(green_light_pin, LOW);
digitalWrite(yellow_light_pin, HIGH);
digitalWrite(red_light_pin, LOW);
}
void greenOn(){
digitalWrite(green_light_pin, HIGH);
digitalWrite(yellow_light_pin, LOW);
digitalWrite(red_light_pin, LOW);
}
void checkSymptoms(){
if (temp > 38){
highTemp = true;
}
else {
highTemp = false;
}
if(1==0){
dryCough = true;
}
else {
dryCough = false;
}
if(1==0){
lowOxygen = true;
}
else{
lowOxygen = false;
}
}