Iva Jerabkova
Published

BristleBot - IoT Data Visualization

Real-time artwork based on collected data.

BeginnerWork in progress2 hours2,402
BristleBot - IoT Data Visualization

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×2
Temperature Sensor
Temperature Sensor
×1
Honeywell Phototransistor
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 110 kohm
Through Hole Resistor, 110 kohm
×1
Breadboard (generic)
Breadboard (generic)
×2
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Snap-on Connector, For 1 9-V Battery
Snap-on Connector, For 1 9-V Battery
×1
DC motor (generic)
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Bristle
×1
Plant
×1
Paprika powder
×1
Paper (size A0)
×1
Wooden Sticks 30 x 1 x 1 cm
×8
Lime Green Tape
×1
Some Glue
×1
Empty Toilet Paper Roll
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Plant

https://create.arduino.cc/projecthub/arduino/plant-communicator-7ea06f

Bristle

Code

Plant

Arduino
Measures temperature, light, mositure.
Writes this data to a channel on ThinkSpeak.
(This is a simplified version of Plant Communicator project https://create.arduino.cc/projecthub/arduino/plant-communicator-7ea06f)
#include <WiFi101.h>
#include<WiFiSSLClient.h>
#include <RTCZero.h>
#include "ThingSpeak.h"

const char* ssid = "";    //  your network SSID (name)
const char* password = "";  // your network password

WiFiClient  ThingSpeakClient;

unsigned long myChannelNumber = 10;
const char * myWriteAPIKey = ""; // your wrie API key from Thinkspeak

RTCZero rtc; // create RTC object

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 28;
const byte hours = 17;

/* Change these values to set the current initial date */
const byte day = 4;
const byte month = 12;
const byte year = 17;


int lightPin = A0; //the analog pin the light sensor is connected to
int tempPin = A1; //the analog pin the TMP36's Vout (sense) pin is connected to
int moisturePin= A2; 

// Set this threeshold accordingly to the resistance you used
// The easiest way to calibrate this value is to test the sensor in both dry and wet earth 
int threeshold= 800; 

bool alert_already_sent=false;
bool email_already_sent=true;
bool already_sent_to_cloud=true;

unsigned long previousMillis = 0;
const long interval = 2000;

void setup() {
  previousMillis = millis();

    Serial.begin(9600);
    while(!Serial);
    delay(2000);
    Serial.print("Connecting Wifi: ");
    Serial.println(ssid);
    while (WiFi.begin(ssid, password) != WL_CONNECTED) {
      Serial.print(".");
      delay(500);
    }
  Serial.println("");
  Serial.println("WiFi connected");
  
  
  rtc.begin(); // initialize RTC 24H format
  rtc.setTime(hours, minutes, seconds);
  rtc.setDate(day, month, year);
  rtc.setAlarmTime(17, 30, 0);  // Set the time for the Arduino to send the email
  
  ThingSpeak.begin(ThingSpeakClient);
  
  rtc.setAlarmTime(0, 0, 0);    //in this way the request is sent every minute at 0 seconds
  rtc.enableAlarm(rtc.MATCH_SS);
  rtc.attachInterrupt(thingspeak_alarm);

}

void loop() {
  
if ((millis () - previousMillis) >= interval) {
  if(!already_sent_to_cloud){
    ThingSpeak.setField(1,get_light());
    ThingSpeak.setField(2,get_temperature());
    ThingSpeak.setField(3,get_average_moisture());
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
    already_sent_to_cloud=true;
    Serial.println("message sent to cloud");
    previousMillis = millis();
  }
  }
}

float get_temperature(){
  int reading = analogRead(tempPin);  
  float voltage = reading * 3.3;
  voltage /= 1024.0; 
  
 // Print tempeature in Celsius
 float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset

 // Convert to Fahrenheit
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 
 return temperatureC;
}
int get_average_moisture(){ // make an average of 10 values to be more accurate
  
  int tempValue=0; // variable to temporarly store moisture value
  for(int a=0; a<10; a++){
    tempValue+=analogRead(moisturePin);
    delay(1000);
  }
  return tempValue/10;
}
int get_light(){
  int light_value=analogRead(A0);
  return light_value;
}

void thingspeak_alarm(){
    already_sent_to_cloud=false;
}

Bristle

Arduino
Reads data from ThingSpeak.
Switches the motors on and off according to the data.
#include "ThingSpeak.h"
#include <WiFi101.h>
const char ssid[] = "";  // your network SSID (name)
const char pass[] = "";   // your network password         
WiFiClient  client;

unsigned long counterChannelNumber = ;            // Channel ID
const char * myCounterReadAPIKey = ""; // Read API Key
const int FieldNumber1 = 1;  // The field you wish to read --- moisture
const int FieldNumber2 = 2;  // The field you wish to read --- temperature
const int FieldNumber3 = 3;  // The field you wish to read --- light

int in2 = 2; int in3 = 3; // Motor A connections
int in4 = 4; int in5 = 5; // Motor B connections

// optimal environmental conditions for your plant
int minMoisture = 1.5;
int maxMoisture = 2;
int minTemperature = 25;
int maxTemperature = 29;
int minLight = 1022;
int maxLight = 1023;

void setup()
{
    Serial.begin(9600);
    while(!Serial);
    delay(2000);
    Serial.print("Connecting Wifi: ");
    Serial.println(ssid);
    while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
      Serial.print(".");
      delay(2000);
    }
    Serial.println("");
    Serial.println("WiFi connected");
    ThingSpeak.begin(client);
    delay(2000);
     
  // Set all the motor control pins to outputs
  pinMode(in2, OUTPUT); pinMode(in3, OUTPUT);pinMode(in4, OUTPUT); pinMode(in5, OUTPUT);
  // Turn off motors - Initial state
  digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW); 
  delay(2000);
}

void loop()
{  //-------------- Read it from Thinkspeak  -------------//
  //----------------Field 1 ----------------//
  int statusCode1 = 0; 
  long moisture = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
  statusCode1 = ThingSpeak.getLastReadStatus();
     if (statusCode1 == 200)
         { Serial.print("|| Moisture: "); Serial.print(moisture); }
  delay(1000);
  //-------------- Field 2 -------------//
  int statusCode2 = 0; 
  long temperature = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
  statusCode2 = ThingSpeak.getLastReadStatus();
       if (statusCode2 == 200)
        { Serial.print(" || Temperature: "); Serial.println(temperature); }
  delay(1000);
 //-------------- Field 3 -------------//
  int statusCode3 = 0; 
  long light = ThingSpeak.readLongField(counterChannelNumber, FieldNumber3, myCounterReadAPIKey);
  statusCode3 = ThingSpeak.getLastReadStatus();
      if (statusCode3 == 200)
        { Serial.print(" || Light: "); Serial.println(light); }
  delay(1000);
  
 //-------------- Do something with the motors  -------------//
           if (moisture > minMoisture && temperature > minTemperature && temperature <= maxTemperature &&  light > minLight)
           { Serial.print(" plant is happy ");
              // put on motor A
              digitalWrite(in2, LOW); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
              delay(2000);
              digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
              delay(2000);    
          }
          else {
                    if (moisture < minMoisture && temperature > maxTemperature)
                    { Serial.print(" plant is in danger ");
                      // put on motor A
                       digitalWrite(in2, LOW); digitalWrite(in3, HIGH); digitalWrite(in4, HIGH); digitalWrite(in5, LOW);
                       delay(2500);
                       digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
                       delay(2000);    
                    }
                    else {
                            if (moisture < maxMoisture && temperature < minTemperature && light < minLight)
                             { Serial.print(" plant is sad ");
                               // put on motor A
                               digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
                               delay(1500);
                               digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
                               delay(2000);    
                             }
                             else
                             { Serial.print(" plant is doing fine ");
                             // put on motor A
                              digitalWrite(in2, LOW); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
                              delay(1500);
                              digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); digitalWrite(in5, LOW);
                              delay(2000);    
                             }
                          }

                   }
          delay(30000);  
}

Credits

Iva Jerabkova

Iva Jerabkova

1 project • 1 follower
Thanks to Arduino CC.

Comments