#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HCSR04.h>
#include "SPI.h"
#include "NRFLite.h"
const static uint8_t RADIO_ID = 0; // Our radio's id. The transmitter will send to this id.
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;
struct RadioPacket // Any packet up to 32 bytes can be sent.
{
uint8_t FromRadioId;
uint32_t OnTimeMillis;
uint32_t FailedTxCount;
};
NRFLite _radio;
RadioPacket _radioData;
LiquidCrystal_I2C lcd(0x27, 16, 2);
HCSR04 hc(5, 6);
#define buzzer 3
#define WSENSOR 0
#define FSENSOR 1
float distance,water,flame;
String message;
void setup()
{
Serial.begin(9600);
Serial.println("system initialize");
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,LOW);
lcd.init();
lcd.backlight();
welcomeDisplay();
delay(1000);
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN))
{
Serial.println("Cannot communicate with radio");
//while (1); // Wait here forever.
}
}
void loop()
{
home_display();
getdata();
while(flame>=50)
{
message="FLAME AHEAD";
digitalWrite(buzzer,HIGH);
alert_Display(message);
getdata();
}
while(distance<120 && distance>0)
{
message="OBSTRACLE AHEAD";
Alert(1);
alert_Display(message);
getdata();
}
while(water>=50)
{
message="WATER AHEAD";
digitalWrite(buzzer,HIGH);
alert_Display(message);
getdata();
}
//checkNrf();
}
void Buzzer(uint8_t num)
{
for(uint8_t j=0;j<num;j++)
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(250);
}
}
void getdata()
{
water = map(analogRead(WSENSOR),0,1023,0,100);
flame = map(analogRead(FSENSOR),0,1023,0,100);
distance = hc.dist();
Serial.print("water:");
Serial.print(water);
Serial.print("flame:");
Serial.println(flame);
Serial.print("distance:");
Serial.println(distance);
}
bool checkNrf()
{
while (_radio.hasData())
{
_radio.readData(&_radioData); // Note how '&' must be placed in front of the variable name.
String msg = "Radio ";
msg += _radioData.FromRadioId;
msg += ", ";
msg += _radioData.OnTimeMillis;
msg += " ms, ";
msg += _radioData.FailedTxCount;
msg += " Failed TX";
Serial.println(msg);
}
}
void welcomeDisplay()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PARTIENT DEMAND");
lcd.setCursor(0,1);
lcd.print(" MONITORING ");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("INITIALIZING SYS");
lcd.setCursor(0,1);
lcd.print("PLEASE WAIT ....");
}
void home_display()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" SMART BLIND ");
lcd.setCursor(0,1);
lcd.print(" SHOES ");
}
void alert_Display(String text)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(">>> !ALERT! <<<<");
if(text.length()<=16)
{
lcd.setCursor(0,1);
lcd.print(text);
}
}
void Alert(uint8_t num)
{
for(uint8_t i=0;i<num;i++)
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(250);
}
}
SMART BLIND SHOES CIRCUIT $ SIMULATION