0% found this document useful (0 votes)
86 views10 pages

Firebase Integration for Helmet Code

The document contains code for configuring an Arduino to measure vibration from a helmet sensor and transmit the data to a NodeMCU. The Arduino code measures vibration using a pulse sensor and transmits the value over serial. The NodeMCU code connects to WiFi and retrieves the vibration values from the Arduino over serial. It then uploads the values to a Firebase database. The code also controls motors on the helmet to move it forward and back based on commands received from the NodeMCU over serial.

Uploaded by

ICRDET 2019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views10 pages

Firebase Integration for Helmet Code

The document contains code for configuring an Arduino to measure vibration from a helmet sensor and transmit the data to a NodeMCU. The Arduino code measures vibration using a pulse sensor and transmits the value over serial. The NodeMCU code connects to WiFi and retrieves the vibration values from the Arduino over serial. It then uploads the values to a Firebase database. The code also controls motors on the helmet to move it forward and back based on commands received from the NodeMCU over serial.

Uploaded by

ICRDET 2019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CHAPTER 6

CODING

6.1 HELMET_ARDUNIO_CONIGURATION CODE

void loop(){

long measurement =vibration();

Serial.println(measurement);

long vibration(){

long measurement=pulseIn (vs, HIGH); //wait for the pin to get HIGH and
returns measurement

return measurement;

*/

int ByteReceived;

int button = 2;

void setup() /****** SETUP: RUNS ONCE *****/

Serial.begin(9600);

pinMode(button,INPUT);

digitalWrite(button,HIGH);

//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/

/* if (Serial.available() > 0)

ByteReceived = Serial.read();

Serial.print("you pressed");

Serial.print(ByteReceived);

Serial.println(char(ByteReceived));

delay(1000);

}*/

if(digitalRead(button)==HIGH)

Serial.write("0");

else

Serial.write("1");

delay(2000);

/*if(bs==HIGH)

Serial.write("1");

else

Serial.write("0");*/

}
6.2 HELMET CODE

nt pos=7;

int neg=8;

char state;

void setup()

pinMode(pos,OUTPUT);

pinMode(neg,OUTPUT);

Serial.begin(9600);

Serial.print("began");

void loop()

if(Serial.available()>0){

Serial.print("iam in");

state=Serial.read();

Serial.print(state);

if(state=='1'){

Serial.println("start movement");
digitalWrite(pos,HIGH);

digitalWrite(neg,LOW);

delay(700);

else if(state=='0'){

/*Serial.println("reverse");

digitalWrite(neg,HIGH);

digitalWrite(pos,LOW);

delay(1000);*/

Serial.println("stop");

digitalWrite(pos,LOW);

digitalWrite(neg,LOW);

delay(1000);

6.3 NODEMCU_HELMET CODE

#include <ESP8266WiFi.h>

#include<FirebaseArduino.h>

#define FIREBASE_HOST "sample-8f1fd.firebaseio.com" //


database URL
#define FIREBASE_AUTH
"mVeoMTLE2XbGrHhpiS2N9UfzRJSDBZExcEPKXzRl" // secret key

#define WIFI_SSID "pi"

#define WIFI_PASSWORD "abcdefgh"

#define vib A0

int val=0;

void setup() {

pinMode(vib,INPUT);

Serial.begin(9600);

Serial.println("Serial communication started\n\n");

WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to


connect with wifi

Serial.print("Connecting to ");

Serial.print(WIFI_SSID);

while (WiFi.status() != WL_CONNECTED) {

Serial.print(".");

delay(500);

Serial.println();

Serial.print("Connected to ");

Serial.println(WIFI_SSID);

Serial.print("IP Address is : ");


Serial.println(WiFi.localIP()); //print local IP address

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase

delay(1000);

void loop() {

val=analogRead(vib);

// Firebase Error Handling


************************************************

if (Firebase.failed())

{ delay(500);

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

Serial.println(Firebase.error());

Serial.println("Connection to fiebase failed. Reconnecting...");

delay(500);

else {

Serial.println("Everything is ready!");

delay(300); Serial.println("Everything is ready!");

delay(300); Serial.println("Everything is ready! \n \n \n");


delay(300);

Firebase.setInt("/vibration1",val);

Serial.println(val);

delay(300); Serial.println("uploaded vibration val to firebase \n \n \n");

}
Screenshots

CHAPTER 8
SCREENSHOTS AND OUTPUTS

You might also like