Skip to content

Instantly share code, notes, and snippets.

@kaushalpartani
Created April 17, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushalpartani/529986b40858b6d5cb79a912acd46402 to your computer and use it in GitHub Desktop.
Save kaushalpartani/529986b40858b6d5cb79a912acd46402 to your computer and use it in GitHub Desktop.
#include <NewPing.h>
#include <Wire.h>
#include "rgb_lcd.h"
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.clear();
delay(1000);
}
void loop() {
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
int uS = sonar.ping_cm();
if ((uS < 10) && (uS != 0)){
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor (0, 0);
lcd.print("Threat Distance: ");
lcd.setCursor (0, 1);
lcd.print(uS);
//Serial.print(uS);
lcd.print("cm");
lcd.setCursor (8, 1);
lcd.print ("Caution!");
lcd.noAutoscroll();
}
else{
lcd.clear();
lcd.setRGB(0, 200, colorB);
lcd.setCursor(0, 0);
lcd.print ("No Threat");
lcd.setCursor (0, 1);
lcd.print ("Detected");
}
}
@kaushalpartani
Copy link
Author

Simple "threat detector" that utilizes a range sensor, arduino, and a Grove-LCD RGB Backlight display. Made 4/17/2016 at MenloHacks by Kaushal Partani, Murad Awad, and Shreyas Vaidya.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment