Tanner NaumannAndrew BoctorCaleb Falter1
Published

Automotive Dash Sensors

The dash sensor reads light, temperature, and acceleration, these readings will lead to a better understanding of the user's surroundings.

IntermediateFull instructions provided8 hours256
Automotive Dash Sensors

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Photo resistor
Photo resistor
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Argon
Particle Argon
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Project Flow Chart

ThingSpeak Temperature Data

ThingSpeak Humidity Data

ThingSpeak Acceleration Data

Code

Temp Sensor

C/C++
#include <Grove_Temperature_And_Humidity_Sensor.h>

//An example of DHT11 for PHOTON

#define DHTPIN 	D2     // set pin

unsigned long previousMillis=0;
const long interval = 30000;

DHT dht(DHTPIN);

void setup() {
	Serial.begin(9600);
	Serial.println("DHT11 Begin!!!");

	dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(5000);
// The sensor reads data slowly.
	unsigned long currentMillis = millis();
	
	if (currentMillis - previousMillis >= interval) {
//Read Humidity
	float h = dht.getHumidity();
// Read temperature as Celsius
	float t = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();

// Check if any reads failed
	if (isnan(h) || isnan(t) || isnan(f))
	{
		Serial.println("Failed to read from DHT11 sensor!");
		return;
	}

	Serial.print("Humid: ");
	Serial.print(h);
	Serial.println("%  ");
	Serial.print("Temp: ");
	Serial.print(t);
	Serial.println("*C ");
	Serial.print("Temp: ");
	Serial.print(f);
	Serial.println("*F ");
	Serial.println();Serial.println();
	
	String sensorVals = "{humidity:" + String(h) + ",temp:" + String(f) + "{";
	
	Particle.publish("SensorVals", sensorVals);


    }
}

Light Sensor Subscribe Code

C/C++
Code for subscribing to the photoresistor cloud publish
void setup() {
pinMode(D7, OUTPUT);
Particle.subscribe("toggle-led", toggleLed, MY_DEVICES);
}

void loop() {

}

void toggleLed(const char *event, const char *data) {
    digitalWrite(D7,HIGH);
    delay(500);
    digitalWrite(D7,LOW);
    delay(500)
}

Photoresistor Sensor/ Publishing Code

C/C++
This code detects light from the photoresistor and lights up the red led and the D7 led whenever there is an absence of light. It also publishes this data to the argon events tab and publishes it to another argon.
// First, we're going to make some variables.
// This is our "shorthand" that we'll use throughout the program:

int led1 = A5; // Instead of writing D0 over and over again, we'll write led1
// You'll need to wire an LED to this one to see it blink.

int led2 = D7; // Instead of writing D7 over and over again, we'll write led2
// This one is the little blue LED on your board. On the Photon it is next to D7, and on the Core it is next to the USB jack.

// Having declared these variables, let's move on to the setup function.
// The setup function is a standard part of any microcontroller program.
// It runs only once when the device boots up or is reset.

int photoresistor = A0;
int analogValue;



void setup() {

  // We are going to tell our device that D0 and D7 (which we named led1 and led2 respectively) are going to be output
  // (That means that we will be sending voltage to them, rather than monitoring voltage that comes from them)

  // It's important you do this here, inside the setup() function rather than outside it or in the loop function.

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(photoresistor, INPUT);

}

// Next we have the loop function, the other essential part of a microcontroller program.
// This routine gets repeated over and over, as quickly as possible and as many times as possible, after the setup function is called.
// Note: Code that blocks for too long (like more than 5 seconds), can make weird things happen (like dropping the network connection).  The built-in delay function shown below safely interleaves required background activity, so arbitrarily long delays can safely be done if you need them.

void loop() {
  
  analogValue = analogRead(photoresistor);
  
  
  if (analogValue > 1) {
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
  } else {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      Particle.publish("toggle-led", PRIVATE);
  }
}

Accelerometer Sensor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>


/*
  
 This example code is in the public domain.

*/

// these constants describe the pins. They won't change:

TCPClient client;

unsigned long ThingSpeakChannelNum = 1711039;
const char * APIWriteKey = "BJ1L94KDTDTA4JYX";


const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)

void setup()

{
    ThingSpeak.begin(client);
    
    
  // initialize the serial communications:
  Serial.begin(9600);
  
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);
}

void loop()
{
    
  // print the sensor values:
  Serial.print(analogRead(A3));
  // print a tab between values:
  Serial.print("X Acceleration:  ");
  Serial.print(analogRead(A2));
  // print a tab between values:
  Serial.print("Z Acceleration");
  Serial.print(analogRead(A1));
  Serial.println();
  // delay before next reading:
  delay(5000);
  
int accel = analogRead(A3);

int accel2 = analogRead(A2);

int accel3 = analogRead(A1);

Particle.publish("X Acceleration:", String(accel), PRIVATE);
Particle.publish("Y Acceleration:", String(accel2), PRIVATE);
Particle.publish("Z Acceleration:", String(accel3), PRIVATE);

ThingSpeak.setField(1,accel);
ThingSpeak.setField(2,accel2);
ThingSpeak.setField(3,accel3);

ThingSpeak.writeFields(ThingSpeakChannelNum, APIWriteKey);
}

Credits

Tanner Naumann

Tanner Naumann

1 project • 2 followers
Andrew Boctor

Andrew Boctor

1 project • 1 follower
Caleb Falter1

Caleb Falter1

1 project • 1 follower

Comments

Add projectSign up / Login