-
1Step 1
First thing you are going to want to do is switch the Atlas Scientifica EZO circuits to i2c mode so they will be compatible with the Tentacle mini.
PH circuit
- Use a jumper wire to short PGND to TX and run 3.3 volts to VCC and GND. The circuit should go from blue to green. After it's turned to green remove ground then power and you'll be in i2c mode. Check out the data sheet for more info.
Conductivity circuit
- Use a jumper wire to short PRB to TX and run 3.3 volts to VCC and ground. The circuit should go from green to blue. After its turned to green remove ground then power and you'll be in i2c mode. Check out the data sheet for more info.
-
2Step 2
Tentacle Mini for Arduino Setup
- Copy the contents of this address and save it in a new Arduino project called TentacleSetup.
- Plug EZO circuits into the Tentacle shield and then plug the tentacle shield into the Arduino Uno. ***Make sure the pins are aligned properly ***
- Connect the Arduino uno to your computer using a A-B USB cable. Make sure the EZO circuits come on blue.
- Upload the TentacleSetup sketch you saved earlier.
- Open the Serial Monitor and scan for i2c devices attached to the tentacle mini by opening the serial monitor and typing 'scani2c' in the text box and pressing 'send'.
scani2c
The default addresses for the PH and Conductivity are 100 and 99.
To get a reading from the PH sensor type:
100
Followed by
r
-
3Step 3
Connect NodeMCU to Arduino UNO
- D2 (NodeMCU) to pin 10 (Uno)
- D3 (NodeMCU) to pin 11 (Uno)
- D6 (NodeMCU) to pin 12 (Uno)
- D7 (NodeMCU) to pin 13 (Uno)
- GND (NodeMCU) to GND (UNO)
Connect i2c LCD to Arduino Uno
- SCL => SCL
- SDA => SDA
Power it all:
- VIN (nodeMCU) => 5v from power supply
- GND (nodeMCU) => 5v GND from power supply
- VCC (i2c LCD Module) => 5v from power supply
- GND (i2c LCD Module) => 5v GND power supply
- VIN (Arduino Uno) => 12V from power supply
- GND (Arduino Uno) => 12V GND power supply
-
4Step 4
Arduino Uno
- You'll need the LiquidCrystal_I2C library installed. The other libraries (Wire and SoftwareSerial) were installed when you downloaded Arduino.
- include libraries and define the i2c address you got when you ran the "scani2c" command.
Writing Code: Full code is on Github.
#include #include #include #define coAddress 100 #define phAddress 99
Now we need to set/initiate some variables and use some class constructors to tell Arduino how to handle our software serial ports and LCD screen.
byte code=0; char data[20]; byte in_char=0; byte i=0; int time_=2000; float RTD_float; LiquidCrystal_I2C lcd(0x27,20,4); SoftwareSerial port1(11,10); //RX,TX SoftwareSerial port2(13,12);
First thing we want to happen in the loop is to connect to our sensor and get the value when it is available. The information will come as a byte array so you'll need to parse the information to get a full reading.
void loop() { //for conductivity Wire.beginTransmission(coAddress); Wire.write('r'); Wire.endTransmission(); delay(time_); Wire.requestFrom(coAddress, 20, 1); code = Wire.read(); while(Wire.available()){ in_char = Wire.read(); data[i]= in_char; i+=1; if(in_char==0){ i=0; break; } }
Next we need to display the data we received and send that data to the NodeMCU via the software serial ports we set up.
lcd.setCursor(0,0); lcd.print("CN: "); lcd.setCursor(6,0); lcd.print(data); port1.print(data); port1.println("\n"); delay(30);
The code for the PH sensor is nearly identical, with just a few substitutions.
//for PH Wire.beginTransmission(phAddress); Wire.write('r'); Wire.endTransmission(); delay(time_); Wire.requestFrom(phAddress, 20, 1); code = Wire.read(); while(Wire.available()){ in_char = Wire.read(); data[i]= in_char; i+=1; if(in_char==0){ i=0; break; } } lcd.setCursor(0,1); lcd.print("PH: "); lcd.setCursor(6,1); lcd.print(data); port2.print(data); port2.println("\n"); delay(30);
-
5Step 5
NodeMCU
- open preferences In the Arduino IDE and copy the link below in the field where it says "Additional Boards Manager". This is how we can get the Arduino IDE to recognize the NodeMCU
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Open Boards Manager from Tools > Board menu and install esp8266 at the bottom.
- Select NodeMCU esp12e under at Tools > Board Menu
Writing Code: Full code is on Github.
- You'll need the firebase-arduino installed. The other libraries were installed when you installed the Arduino IDE and the esp8266 under boards manager.
- include libraries and set the software serial ports
#include #include #include SoftwareSerial port1(D2,D3); //RX,TX SoftwareSerial port2(D6,D7); //RX,TX
FIREBASE_HOST is the root URL for the db.
- Navigate to project from Firebase console
- Click "Add Firebase to your web app"
- copy contents of databaseURL
The Firebase_Auth is actually the db secret.
- Navigate to project from Firebase Console
- Click the settings icon next to Project Overview
- Click Project settings
- Click Service accounts
- Click Database secrets
#define FIREBASE_HOST "---fill in your own info here--" #define FIREBASE_AUTH "--this is the secret key---" #define WIFI_SSID "--your wifi name---" #define WIFI_PASSWORD "---your wifi password--"
We're going to create a function to pause for a certain amount of time.
void waitFor(int time) { int period = time; unsigned long time_now = millis(); while(millis() < time_now + period){} }
In the setup we are going to set the serial monitors baudrate to 9600, and the 2 ports we're receiving data from to 4800. We'll also need to connect to the internet, and initiate our Firebase connection.
void setup(){ Serial.begin(9600); port1.begin(4800); port2.begin(4800); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting"); while(WiFi.status() != WL_CONNECTED) { Serial.print("."); waitFor(500); } Serial.print("connected: "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); }
Now for the fun stuff in the loop. After writing and Uploading this last bit, you should be sending sensor data to Firebase and it should be visible from the project database section of the project.
void loop(){ port1.listen(); delay(200); while(port1.available()>0){ float val = port1.parseFloat(); if(port1.read()== '\n'){ Serial.print("CON: "); Serial.println(val); Firebase.setFloat("CON", val); break; } } port2.listen(); delay(200); while(port2.available()>0){ float val = port2.parseFloat(); if(port2.read()== '\n'){ Serial.print("PH: "); Serial.println(val); Firebase.setFloat("PH", val); break; } } waitFor(1000); }
-
6Step 6
Set Auth rules in Firebase
- Navigate to project from Firebase Console
- Click Database under Develop
- Click the Rules tab
make sure the rules look like this and change if necessary
{ "rules": { ".read": "auth != null", ".write": "auth != null" } }
-
7Step 7
Angular Web App
Writing code: Full code is on Github. To use, fill in your own credentials in the envroment.ts and run in these commands in the project root folder
npm install ng serve -o
or build your own
- Navigate to your Angular projects file or create one if don't already have one.
- Open a terminal in the Angular project folder.
ng new IotSensorApp
install Firebase and Angularfire2
npm install firebase angularfire2 --save
To get a live reload and see the changes you make to the app as you save it
ng serve -o
-
8Step 8
Get your Firebase credentials
- sign in to Firebase
- click project from console
- click "Add Firebase to your web app"
- copy everything in the config brackets
copy your Firbase credentials over to the enviroment.ts file in the Angular project.
src/enviroments/enviroment.ts
export const environment = { production: false, firebase: { apiKey: 'fill in your own info', authDomain: 'fill in your own info', databaseURL: 'fill in your own info', projectId: 'fill in your own info', storageBucket: 'fill in your own info', messagingSenderId: 'fill in your own info' } };
-
9Step 9
Now we'll generate the components and services. After each line hit enter.
- Open terminal
- Make sure you're in the project root file "src".
ng g c login ng g c main ng g c main/con ng g c main/ph ng g s services/auth ng g s services/authguard
-
10Step 10
Add all the imports we'll need at the top of the page in the app.module.ts file
src/app/app.module.ts
import { Routes, RouterModule } from '@angular/router'; import { FormsModule } from '@angular/forms'; import { AngularFireModule } from 'angularfire2'; import { AngularFireDatabaseModule } from 'angularfire2/database'; import { AngularFireAuthModule } from 'angularfire2/auth'; import { environment } from '../environments/environment'; import { AuthService } from './services/auth.service'; import { AuthguardService } from './services/authguard.service';
The appRoutes object array we create is going to give us some errors but we'll fix that after we'll fix that soon in our authguard, and auth service files.
src/app/app.module.ts
const appRoutes: Routes = [ { path: '', component: MainComponent, canActivate: [AuthguardService] }, { path: 'login', component: LoginComponent } ];
Under imports add the modules you will need.
src/app/app.module.ts
imports: [ BrowserModule, FormsModule, RouterModule.forRoot(appRoutes), AngularFireAuthModule, AngularFireModule.initializeApp(environment.firebase), AngularFireDatabaseModule ],
Then add your services to providers.
src/app/app.module.ts
providers: [AuthService, AuthguardService],
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.