Brayden Hillryanbrad33Kayden Hanks
Published © GPL3+

MEGR 3171 IoT Project - Radiator Temperature Sensor

Particle Argon-Based Internet of Things, Using 3 Argons to Measure Coolant Temperature Through the Radiator of a Formula SAE Race Car

IntermediateFull instructions provided20 hours262
MEGR 3171 IoT Project - Radiator Temperature Sensor

Things used in this project

Hardware components

Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×2
Argon
Particle Argon
×3
LED (generic)
LED (generic)
×9
SparkFun Solder-able Breadboard
SparkFun Solder-able Breadboard
×3
Resistor 1k ohm
Resistor 1k ohm
LED Resistors
×9
Resistor 4.75k ohm
Resistor 4.75k ohm
Temp Sensor Pullup Resistor
×2
Jumper wires (generic)
Jumper wires (generic)
×1
M3 Size Socket-Cap Screws (Generic)
×24
5-pin Aviation Socket Connector, Male/Female Pair (Generic)
×3
GREDIA G3/4"" Female Thread Brass Water Flow Sensor Switch Hall Effect Liquid Flowmeter Fluidmeter Counter BSP 2-50L/Min
Fluid Flow Sensor
×1
Battery Holder, 3 x AAA
Battery Holder, 3 x AAA
×3
3D Printed Enclosure
×3
3D Printed Enclosure Lid
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Custom parts and enclosures

Enclosure Body

Enclosure Lid

Schematics

Argon Wiring Schematic

Flow Sensor Wiring Diagram

DS18B20 Temperature Sensor Wiring Diagram

Code

Sensor (Particle A) Code

C/C++
Code Used for the Temperature Sensor Only
//Include OneWire Library
#include <OneWire.h>
#include "DS18.h"

//Check Values Every 1 Second
#define TIME_INTERVAL 1000

//Make Pin D0 the Temperature Sensor Data Pin
DS18 tempSensor(D0);
//Make Pin D8 the Pin for the Wifi Connection Indicator LED
int wifiLED = D8;
//Make Pin D8 the Pin for the Low Battery Indicator LED
int battLED = D6;
//Make Pin A0 the Pin to Read Battery Voltage
int battPin = A0;


//Create "temp" Variable to Store the Temperature Value from the Sensor
int temp;
//Create "volt" Variable to Store the Battery Voltage
int volt;
//Create "rec" Variable to Store the Recording Value from the Home Base
int rec;
//Initialize the Last Time Values were Checked as 0
unsigned long lastCheck = 0;

//Create Function to Check the Temperature Reading from the Sensor
int checkTempHandler(String command) {
    checkTemp();
return 1;
}

//Create Function to Check the Voltage Reading from the Batteries
int checkVoltHandler(String command) {
    checkVolt();
return 1;
}

//Create Handler for Two Way Communication Using Subscribe Feature
void twowaycomm(const char *event, const char *data )
{
    String yes = data;
    rec = yes.toInt();
}

//Define the Function to Check Temperature
void checkTemp() {
    if (tempSensor.read()) {
        temp = (tempSensor.celsius());
        Particle.publish("TempIoT_1", String(temp), ALL_DEVICES);
    }
    else {
        
        
    }
}

//Define the Function to Check Battery Voltage
void checkVolt() {
    volt = (analogRead(battPin));
    //Particle.publish("VoltIoT_1", String(volt), ALL_DEVICES);
}


void setup() {
    //Define LED Pins as Outputs
    pinMode(wifiLED, OUTPUT);
    pinMode(battLED, OUTPUT);
    
    //Create Variables to Store Temperature and Voltage Values
    Particle.variable("TempIoT_1", temp);
    Particle.variable("VoltIoT_1", volt);
    
    //Create Functions to Collect Temperature and Voltage Values
    Particle.function("checkTempIoT_1", checkTempHandler);
    Particle.function("checkVoltIoT_1", checkVoltHandler);

    //Subscribe to Record Variable Which is Published by Home Base
    Particle.subscribe("Record", twowaycomm);
}


void loop() {
    
    //If the Particle Argon is Connected to the Wifi Network, Flash the Indicator LED
    if (Particle.connected()) {
        digitalWrite(wifiLED, HIGH);
        delay(50);
        digitalWrite(wifiLED, LOW);
        delay(50);
    }
    
     if (lastCheck + TIME_INTERVAL < millis()) {
   lastCheck = millis();
   checkVolt();
 }
 
    //If the Comand has been Sent to Record Data, Check the Temperature Values Every 1 Second
 if (rec == 1) {
   checkTemp();
 }
 if (rec == -1) {
     
 }
 
 //If the Voltage is Below 2800 mV, Turn on the Indicator LED to Notify User to Replace Batteries
 if (volt < 2800) {
     digitalWrite(battLED, HIGH);
 }
 else {
     digitalWrite(battLED, LOW);
 }

}

Sensor (Particle B) Code

C/C++
Code Used for the Temperature Sensor Only
//Include OneWire Library
#include <OneWire.h>
#include "DS18.h"

//Check Values Every 1 Second
#define TIME_INTERVAL 1000

//Make Pin D0 the Temperature Sensor Data Pin
DS18 tempSensor(D0);
//Make Pin A1 the Pin for the Flow Rate Data
int flowPin = A1;
//Make Pin D8 the Pin for the Wifi Connection Indicator LED
int wifiLED = D8;
//Make Pin D8 the Pin for the Low Battery Indicator LED
int battLED = D6;
//Make Pin A0 the Pin to Read Battery Voltage
int battPin = A0;


//Create "temp" Variable to Store the Temperature Value from the Sensor
int temp;
//Create "volt" Variable to Store the Battery Voltage
int volt;
//Create "rec" Variable to Store the Recording Value from the Home Base
int rec;
//Create "val" Variable to Store the Raw Voltage Value from the Flow Sensor
int val;
//Create "flow" Variable to Store the Calculated Flow Value from the Raw Data
int flow;
//Initialize the Last Time Values were Checked as 0
unsigned long lastCheck = 0;

//Create Function to Check the Temperature Reading from the Sensor
int checkTempHandler(String command) {
    checkTemp();
return 1;
}

//Create Function to Check the Flow Reading from the Sensor
int checkFlowHandler(String command) {
    checkFlow();
return 1;
}

//Create Function to Check the Voltage Reading from the Batteries
int checkVoltHandler(String command) {
    checkVolt();
return 1;
}

//Create Handler for Two Way Communication Using Subscribe Feature
void twowaycomm(const char *event, const char *data )
{
    String yes = data;
    rec = yes.toInt();
}

//Define the Function to Check Temperature
void checkTemp() {
    if (tempSensor.read()) {
        temp = (tempSensor.celsius());
        Particle.publish("TempIoT_2", String(temp), ALL_DEVICES);
    }
    else {
        
        
    }
}

//Define the Function to Check Flow
void checkFlow() {
    val = analogRead(flowPin);
    flow = (val + 4)/7.5;
    Particle.publish("FlowIoT_2", String(flow), ALL_DEVICES);
}

//Define the Function to Check Battery Voltage
void checkVolt() {
    volt = (analogRead(battPin));
    //Particle.publish("VoltIoT_2", String(volt), ALL_DEVICES);
}


void setup() {
    //Define LED Pins as Outputs
    pinMode(wifiLED, OUTPUT);
    pinMode(battLED, OUTPUT);
    pinMode(flowPin, INPUT);
    
    //Create Variables to Store Temperature and Voltage Values
    Particle.variable("TempIoT_2", temp);
    Particle.variable("FlowIoT_2", flow);
    Particle.variable("VoltIoT_2", volt);
    
    //Create Functions to Collect Temperature and Voltage Values
    Particle.function("checkTempIoT_2", checkTempHandler);
    Particle.function("checkVoltIoT_2", checkVoltHandler);
    Particle.function("checkFlowIoT_2", checkFlowHandler);

    //Subscribe to Record Variable Which is Published by Home Base
    Particle.subscribe("Record", twowaycomm);
}


void loop() {
    
    //If the Particle Argon is Connected to the Wifi Network, Flash the Indicator LED
    if (Particle.connected()) {
        digitalWrite(wifiLED, HIGH);
        delay(50);
        digitalWrite(wifiLED, LOW);
        delay(50);
    }
    
     if (lastCheck + TIME_INTERVAL < millis()) {
   lastCheck = millis();
   checkVolt();
 }
 
    //If the Comand has been Sent to Record Data, Check the Temperature Values Every 1 Second
 if (rec == 1) {
   checkTemp();
   //checkFlow();
 }
 if (rec == -1) {
     
 }
 
 //If the Voltage is Below 2800 mV, Turn on the Indicator LED to Notify User to Replace Batteries
 if (volt < 2800) {
     digitalWrite(battLED, HIGH);
 }
 else {
     digitalWrite(battLED, LOW);
 }

}

Home Base (Particle C) Code

C/C++
Code Used for the Home Base System with Flow Sensor
//Define Time Interval of 1 Second
#define TIME_INTERVAL 3000
//Create "temp" Variables to Store the Temperature Values from the Sensors
int temp1;
int temp2;
//Create "diff" Variable to Store the Temperature Difference
int diff;
//Create "KW" Variable to Store the Calculated Heat Dissipation Value
int KW;
//Create "rec" Variable to Store the Recording Value
int rec;
//Create "volt" Variable to Store the Battery Voltage
int volt;
//Create "val" Variable to Store the Raw Voltage Value from the Flow Sensor
int val;
//Create "flow" Variable to Store the Calculated Flow Value from the Raw Data
int flow;

//Make Pin A1 the Pin for the Flow Rate Data
int flowPin = A1;
//Make Pin D8 the Pin for the Wifi Connection Indicator LED
int wifiLED = D8;
//Make Pin D8 the Pin for the Low Battery Indicator LED
int battLED = D6;
//Make Pin A0 the Pin to Read Battery Voltage
int battPin = A0;

//Initialize the Last Time Values were Checked as 0
unsigned long lastCheck = 0;

void setup() 
{
    //Define LED Pins as Outputs
    pinMode(wifiLED, OUTPUT);
    pinMode(battLED, OUTPUT);
    pinMode(flowPin, INPUT);
    
    //Subscribe to "TempIoT_x" Variable Which Stores Temperature Recorded by Sensors and is Sent by Particle A/B
    Particle.subscribe("TempIoT_1", twowaycomm1);
    Particle.subscribe("TempIoT_2", twowaycomm2);
    
    //Subscribe to "FlowIoT_x" Variable Which Stores Flow Rate Recorded by Sensors and is Sent by Particle A/B
    //Particle.subscribe("FlowIoT_2", twowaycommflow);
    
    //Functions to Start/Stop Recording By Changing the Value of "rec"
    Particle.function("StartRecord", startRecordDataHandler);
    Particle.function("StopRecord", stopRecordDataHandler);
    
    //Variable to Store Battery Voltage
    Particle.variable("VoltIoT_HB", volt);
    //Function to Check Battery Voltage
    Particle.function("checkVoltIoT_HB", checkVoltHandler);

}

//Create Function to Check the Voltage Reading from the Batteries
int checkVoltHandler(String command) {
    checkVolt();
return 1;
}

//Create Function to Start Recording Data
int startRecordDataHandler(String command) {
    startRecordData();
return 1;
}

//Create Function to Stop Recording Data
int stopRecordDataHandler(String command) {
    stopRecordData();
return 0;
}

//Create Function to Check the Flow Reading from the Sensor
int checkFlowHandler(String command) {
    checkFlow();
return 1;
}

//Define Function to Start Recording Data
void startRecordData() {
    rec = 1;
    Particle.publish("Record", String(rec), ALL_DEVICES);
}

//Define Function to Stop Recording Data
void stopRecordData() {
    rec = -1;
    Particle.publish("Record", String(rec), ALL_DEVICES);
}


//Define the Function to Check Flow
void checkFlow() {
    val = digitalRead(flowPin);
    flow = (val + 4)/7.5;
    Particle.publish("flowRead", String(flow), ALL_DEVICES);
}

//Define the Function to Check Battery Voltage
void checkVolt() {
    volt = (analogRead(battPin));
    //Particle.publish("VoltIoT_1", String(volt), ALL_DEVICES);
}


    
//Define Function for Two Way Comms (Particle A)
void twowaycomm1(const char *event, const char *data )
{
    String pew = data;
    temp1 = pew.toInt();
}

//Define Function for Two Way Comms (Particle B)
void twowaycomm2(const char *event, const char *data )
{
    String ret = data;
    temp2 = ret.toInt();
}

//Define Function for Two Way Comms (Particle B)
//void twowaycommflow(const char *event, const char *data )
//{
    //String tim = data;
    //flow = tim.toInt();
//}

double readFlow(){
  int counter = 0;
  double sensorReading = 0;
  double priorReading = 0;
  double flow = 0;


  int starttime = millis();
  int endtime = starttime;
  while ((endtime - starttime) <=100){
    sensorReading = analogRead(flowPin);
    //count rotations per second based on voltage flips
    if ((sensorReading > 2500 && priorReading < 120) || (sensorReading < 120 && priorReading > 2500)){
      counter += 1;
    }
    priorReading = sensorReading;
    endtime = millis();
  }
  
  flow = (counter + 4) / 7.5;
  //flow = counter / 2*60*10;
  
  //Particle.publish("flowRead", String(flow), PRIVATE);
  
  return flow;
}

void calcKW() {
    diff = temp1 - temp2;
    KW = flow * 4.187 * diff;
}


void loop() {
    //flow = readFlow();
    //Particle.publish("flowRead", String(flow), PRIVATE);
    //delay(1000);
    
    //If the Particle Argon is Connected to the Wifi Network, Flash the Indicator LED
    if (Particle.connected()) {
        digitalWrite(wifiLED, HIGH);
        delay(50);
        digitalWrite(wifiLED, LOW);
        delay(50);
    }
    
    
    
    
    //If Data is Recording, Publish the Received Value Every 1 Second
    if ((lastCheck + TIME_INTERVAL < millis()) && (rec == 1)) {
   lastCheck = millis();
   Particle.publish("tempRead1", String(temp1), PRIVATE);
   Particle.publish("tempRead2", String(temp2), PRIVATE);
   flow = readFlow();
   //KW = flow * 4.187;
   Particle.publish("flowRead", String(flow), PRIVATE);
   //calcKW();
   //Particle.publish("heatDiss", String(KW), PRIVATE);
   }
   if (rec == -1) {
 }
 
  //If the Voltage is Below 2800 mV, Turn on the Indicator LED to Notify User to Replace Batteries
 if (volt < 2800) {
     digitalWrite(battLED, HIGH);
 }
 else {
     digitalWrite(battLED, LOW);
 }
 
}

Credits

Brayden Hill

Brayden Hill

1 project • 0 followers
ryanbrad33

ryanbrad33

0 projects • 0 followers
Kayden Hanks

Kayden Hanks

0 projects • 0 followers

Comments