Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Alvaro Chang-GarciaSaul Farias Fortunato
Published

Temperature and Sound Sensor for Cars

Measuring both temperature and sound levels in automobiles using sensors to improve the driving experience.

IntermediateFull instructions provided7 hours124
Temperature and Sound Sensor for Cars

Things used in this project

Hardware components

SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
×1
Breadboard (generic)
Breadboard (generic)
×2
Temperature Digital sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×2
Argon
Particle Argon
×2
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Adafruit

Story

Read more

Schematics

Schematics

Temperature

Schematics

Sound

Code

Sound Sensor Code

C/C++
Using the Particle Argon's Web IDE
int sensorPin = A0;
int buttonpin = D0;
int sound_level = 0;
int val = 0;

int temperature_f;

void setup() {
  pinMode(buttonpin, INPUT_PULLUP);
  pinMode(D7, OUTPUT); // configure D7 pin as output
  Serial.begin(9600);
  Particle.subscribe("hook-response/Sound", myHandler, MY_DEVICES);
  Particle.subscribe("temp1", temperatureHandler, ALL_DEVICES);
}

void loop() {
  val = digitalRead(buttonpin);
  if (val == HIGH) {
    Particle.publish("button_status", "pressed", PRIVATE);
  }
  else {
    Particle.publish("button_status", "released", PRIVATE);
  }
  sound_level = analogRead(sensorPin);
  Serial.println(String(sound_level) );
  String data = String(sound_level);
  Particle.publish("Sound", data, PRIVATE);
  delay(4000);
}

void myHandler(const char *event, const char *data) {
  // Handles integration response
}

void temperatureHandler(const char *event, const char *data1) {
  String pew = data1;
  temperature_f = pew.toInt();
  
  if (temperature_f > 75) {
    digitalWrite(D7, HIGH); // turns on D7 LED
  } else {
    digitalWrite(D7, LOW); // turns off D7 LED
  }
}

Temperature Sensor Code

C/C++
Using the Particle Argon's Web IDE
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

int Trigger;
int analogvalue = 0;
int temp_f;
// Sets D7 as pin to control LED
int led2 = D7;
int Sound;
int Light_Position;

// Initializes temperature
int temperature_f;
TCPClient client;
unsigned long myChannelNumber = 2095165;
const char *myWriteAPIkey = "5NE938WQRGC8RTG5";

void setup() {
  Serial.begin(9600);
  ThingSpeak.begin(client);
  Particle.variable("analogvalue", analogvalue);
  Particle.variable("temp_f", temp_f);
  pinMode(led2, OUTPUT);
  Particle.subscribe("Sound", soundHandler, ALL_DEVICES);
  pinMode(A0, INPUT);
}

void loop() {
  delay(1500);
  analogvalue = analogRead(A0);
  temp_f = (analogvalue * -0.08099688473520249 + 135.99688473520249);
  // Convert the temperature to a string and publish to the "Temperature" event
  Particle.publish("Temperature", String(temp_f), PRIVATE);
  // Wait 8 seconds
  delay(4000);

  
  if (Sound >70) {
    digitalWrite(led2, HIGH);
    Light_Position = 1;
  } else {
    digitalWrite(led2, LOW);
    Light_Position = 0;
  }
  Particle.publish("Light", String(Light_Position), PUBLIC);
  delay(2000);
  Particle.publish("temp1", String(temp_f), ALL_DEVICES);
  ThingSpeak.setField(3, temp_f);
  Serial.print(temp_f);
  Serial.println("temp_f");
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIkey);
  delay(2000);
}

void soundHandler(const char *event, const char *data) {
  Sound = atoi(data);
}

Credits

Alvaro Chang-Garcia
1 project • 0 followers
Saul Farias Fortunato
1 project • 0 followers

Comments