Tom ShanleyJordan Fowler
Published

Poor Road Condition Warning System

Designed to fit in your car, this warning system alerts you when bad driving conditions may be present.

IntermediateFull instructions provided65
Poor Road Condition Warning System

Things used in this project

Hardware components

Argon
Particle Argon
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
LED (generic)
LED (generic)
×1
LM35 Temperature Sensor
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Light Sensing Circuit

Temperature Circuit

Code

Light Code.txt

C/C++
Here is the code for the light sensor
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
  Serial.begin(600);
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
}

void loop() {
  int ldrStatus = analogRead(ldrPin);
    delay(2000);
  if (ldrStatus <= 400)
  {
    digitalWrite(ledPin, HIGH);
    Serial.print("Its Dark, Turn on the LED:");
    Serial.println(ldrStatus);
     Particle.publish("lightstatus","Headlights on",10,PRIVATE);
  }
  else
  {
    digitalWrite(ledPin, LOW);
    Serial.print("Its Bright, Turn off the LED:");
    Serial.println(ldrStatus);
    
    Particle.publish("lightstatus","No headlights",10,PRIVATE);
    

  }

}
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);
}
void setup() {
pinMode(D7, OUTPUT);
}

void loop() {
    digitalWrite(D7, HIGH);
    
    Particle.publish("toggle-led", PRIVATE);
    
    delay(300);
    digitalWrite(D7, LOW);

    delay(4000);
}

Temperature Sensor

C/C++
Here is the code for the temperature sensor
// This #include statement was automatically added by the Particle IDE.
#include <JsonParserGeneratorRK.h>
const String key = "0JMBYBNUVCX9NC11";

int val;
int tempPin = 1;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  val = analogRead(tempPin);
  float mv = ( val/1024.0)*3300;
  float cel = mv/10;
  float farh = (cel*9)/5 + 32;
  Serial.print("TEMPRATURE = ");
  Serial.print(cel);
  Serial.print("*C");
  Serial.println();
  delay(10000);
Particle.publish("temp", String::format("%.2f",cel), NO_ACK);

Particle.publish("thingSpeakWrite_All", +
"{ \"1\": \"" + String(cel) + "\"," +
"\"2\": \"" + String(cel) + "\"," +
"\"3\": \"" + String(cel) + "\"," +
"\"5\": \"" + String(cel) + "\"," +
"\"k\":\"" + key + "\" }", 60, PRIVATE, WITH_ACK);


}


void createEventPayload(float cel)
{
    JsonWriterStatic<256> jw;
    {
        JsonWriterAutoObject obj (&jw);
        
        jw.insertKeyValue("temp", cel);
    }
}
void setup() {
pinMode(D7, OUTPUT);
}

void loop() {
    digitalWrite(D7, HIGH);
    
    Particle.publish("toggle-led", PRIVATE);
    
    delay(300);
    digitalWrite(D7, LOW);

    delay(4000);
}
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);
}

Credits

Tom Shanley

Tom Shanley

1 project • 1 follower
Jordan Fowler

Jordan Fowler

1 project • 0 followers

Comments

Add projectSign up / Login