ARDUINO DATA COLLECTING DEVICE
this device can measure environmental data like temperature light intensity smoke.and also can be used as a measuring tape because it has ultrasonic sensors to find the distance from it to the object in front of it .and it is password protected just like a cellphone. but if you want to change the password you hove to change it in the code.
after you entered a right password it will ask you to choose the mode of operation thanafter you select the mode you can see the data on screen
temperature mode
light mode
distance mode
here is the codes used in this project if you want to build this thing
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <math.h>
#define Password_Length 8
float lux = 0.00,av=0.0048828125,lv;
char Data[Password_Length];
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
char key_pressed=0;
double Temp;
int sensorPin = A1; // select the input pin for the potentiometer
const byte ROWS = 4;
const byte COLS = 4;
const int trigpin = 2;
const int echopin = 3;
const int light = A0;
long duration;
int distance;
char Mode = '0';
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x3f, 16, 2);
void setup(){
lcd.init();
lcd.backlight();
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
Serial.begin(9600);
}
void loop(){
if(Mode == '0')
{pass();}
else if (Mode == 'A')
{mode();}
else if (Mode == '1')
{temp();}
else if (Mode == '2')
{Light();}
else if (Mode == '3')
{sonic();}
}
void pass()
{
lcd.setCursor(0,0);
lcd.print("Enter Password:");
customKey = customKeypad.getKey();
if (customKey){
Data[data_count] = customKey;
lcd.setCursor(data_count,1);
lcd.print(Data[data_count]);
data_count++;
}
if(data_count == Password_Length-1){
lcd.clear();
if(!strcmp(Data, Master)){
lcd.print("Correct");
delay(1000);
lcd.clear();
Mode = 'A';
Serial.println("correct password found");
}
else{
lcd.print("Incorrect");
delay(1000);
}
lcd.clear();
clearData();
}
}
void sonic()
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(100);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin,HIGH);
distance = duration*0.034/2;
Serial.print("Distance ");
Serial.println(distance);
// initialize the lcd
lcd.backlight();
lcd.setCursor(0,0);
if(distance < 1000)
{lcd.clear();
lcd.print("Distance:-");
lcd.print(distance);
lcd.print("cm");
delay(1000);}
if(key_pressed=='#')
{ Mode = 'A';
lcd.clear();
delay(10);
}
if(key_pressed=='2')
{ Mode = '2';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
void mode()
{
lcd.setCursor(0,0);
lcd.print("Enter Mode:");
lcd.setCursor(1,0);
if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
delay(10);
}
else if(key_pressed=='2')
{ Mode = '2';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(10);
}
else if(key_pressed=='3')
{ Mode = '4';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(10);
}
else if(key_pressed=='*')
{ Mode = '0';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(100);
}
key_pressed=='0';
}
void Light(){
lv = analogRead(light);
lux = (250.000/(av*lv))-50.000;
int l = (int)lux;
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
lcd.print("light intenstty:-");
lcd.setCursor(0,1);
lcd.print(l);
lcd.print(" lux");
delay(500);
if(key_pressed=='#')
{ Mode = 'A';
key_pressed ='0';
lcd.clear();
delay(10);
}
else if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='3')
{ Mode = '3';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
void clearData(){
while(data_count !=0){
Data[data_count--] = 0;
}
return;
}
void clearData1(){
while(data_count1 !=0){
Data1[data_count1--] = 0;
}
return;
}
void temp(){
key_pressed = customKeypad.getKey();
int readVal=analogRead(sensorPin);
Temp = Thermistor(readVal);
lcd.clear();
lcd.print("Temperature:-");
lcd.setCursor(0,1);
lcd.print(Temp);
lcd.print(" 'celcius");
delay(1000);
if(key_pressed=='#')
{ Mode = 'A';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='2')
{ Mode = '2';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='3')
{ Mode = '3';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
double Thermistor(int RawADC) {
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
//Temp = (Temp * 9.0)/ 5.0 + 32.0 ; // Convert Celcius to Fahrenheit
return Temp;
}
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <math.h>
#define Password_Length 8
float lux = 0.00,av=0.0048828125,lv;
char Data[Password_Length];
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
char key_pressed=0;
double Temp;
int sensorPin = A1; // select the input pin for the potentiometer
const byte ROWS = 4;
const byte COLS = 4;
const int trigpin = 2;
const int echopin = 3;
const int light = A0;
long duration;
int distance;
char Mode = '0';
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x3f, 16, 2);
void setup(){
lcd.init();
lcd.backlight();
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
Serial.begin(9600);
}
void loop(){
if(Mode == '0')
{pass();}
else if (Mode == 'A')
{mode();}
else if (Mode == '1')
{temp();}
else if (Mode == '2')
{Light();}
else if (Mode == '3')
{sonic();}
}
void pass()
{
lcd.setCursor(0,0);
lcd.print("Enter Password:");
customKey = customKeypad.getKey();
if (customKey){
Data[data_count] = customKey;
lcd.setCursor(data_count,1);
lcd.print(Data[data_count]);
data_count++;
}
if(data_count == Password_Length-1){
lcd.clear();
if(!strcmp(Data, Master)){
lcd.print("Correct");
delay(1000);
lcd.clear();
Mode = 'A';
Serial.println("correct password found");
}
else{
lcd.print("Incorrect");
delay(1000);
}
lcd.clear();
clearData();
}
}
void sonic()
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(100);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin,HIGH);
distance = duration*0.034/2;
Serial.print("Distance ");
Serial.println(distance);
// initialize the lcd
lcd.backlight();
lcd.setCursor(0,0);
if(distance < 1000)
{lcd.clear();
lcd.print("Distance:-");
lcd.print(distance);
lcd.print("cm");
delay(1000);}
if(key_pressed=='#')
{ Mode = 'A';
lcd.clear();
delay(10);
}
if(key_pressed=='2')
{ Mode = '2';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
void mode()
{
lcd.setCursor(0,0);
lcd.print("Enter Mode:");
lcd.setCursor(1,0);
if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
delay(10);
}
else if(key_pressed=='2')
{ Mode = '2';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(10);
}
else if(key_pressed=='3')
{ Mode = '4';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(10);
}
else if(key_pressed=='*')
{ Mode = '0';
lcd.print(Mode);
delay(1500);
lcd.clear();
delay(100);
}
key_pressed=='0';
}
void Light(){
lv = analogRead(light);
lux = (250.000/(av*lv))-50.000;
int l = (int)lux;
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
lcd.print("light intenstty:-");
lcd.setCursor(0,1);
lcd.print(l);
lcd.print(" lux");
delay(500);
if(key_pressed=='#')
{ Mode = 'A';
key_pressed ='0';
lcd.clear();
delay(10);
}
else if(key_pressed=='1')
{ Mode = '1';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='3')
{ Mode = '3';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
void clearData(){
while(data_count !=0){
Data[data_count--] = 0;
}
return;
}
void clearData1(){
while(data_count1 !=0){
Data1[data_count1--] = 0;
}
return;
}
void temp(){
key_pressed = customKeypad.getKey();
int readVal=analogRead(sensorPin);
Temp = Thermistor(readVal);
lcd.clear();
lcd.print("Temperature:-");
lcd.setCursor(0,1);
lcd.print(Temp);
lcd.print(" 'celcius");
delay(1000);
if(key_pressed=='#')
{ Mode = 'A';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='2')
{ Mode = '2';
lcd.clear();
key_pressed ='0';
delay(10);
}
if(key_pressed=='3')
{ Mode = '3';
lcd.clear();
key_pressed ='0';
delay(10);
}
}
double Thermistor(int RawADC) {
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
//Temp = (Temp * 9.0)/ 5.0 + 32.0 ; // Convert Celcius to Fahrenheit
return Temp;
}