Table of Contents

Function Definition: adaio.createdata(feedname = "feed name", data = "0")

Parameters

NameTypeDescriptionExpected ValuesDefault Value
feednamestringThe feedname where the data needs to be sent.String"feed name"
datastringThe data that needs to be sent to the feed.String"0"

Description

The function sends the specified data to the selected feed as a string.

Example

Learn how to connect a DHT sensor to PictoBlox and use the Adafruit IO cloud service to send temperature and humidity data to the cloud. Create a dashboard to visualize the temperature and humidity data with the help of line chart and gauge elements.

We will use the Adafruit IO cloud service to send data from a humidity and temperature sensor to the cloud in the Python Coding Environment of PictoBlox. Adafruit IO is a cloud service that allows you to send data from sensors and other devices to the cloud, where it can be stored and analyzed.

Adafruit IO Key

You can find the information about your account once you log in from here:

Note: Make sure you are login on Adafruit IO: https://io.adafruit.com/

DHT Sensor Connection to Quarky

DHT sensors have 3 pins: GND, VCC, and Signal. You have to connect the following 3 pins to the Quarky Expansion Board:

  1. GND to Ground Pin of Quarky Expansion Board
  2. VCC to 3.3V or VCC Pin of Quarky Expansion Board
  3. Signal to the D3 (Digital Pin) of the Quarky Expansion Board

Code for Stage Mode

# This code is used to connect to the internet and measure the temperature and humidity of the house.
# First, the Quarky object  are created.
quarky = Quarky()

# Time module is imported.
import time

# AdaIO object is created.
adaio = AdaIO()

# IoTHouse object is created.
house = IoTHouse()

# Then, the connection to Adafruit IO is made.
adaio.connecttoadafruitio("STEMNerd", "aio_UZBB56f7VTIDWyIyHX1BCEO1kWEd")

# The feeds for temperature and humidity are created.
adaio.createfeed("Temperature")
adaio.createfeed("Humidity")

# A while loop is used to measure the temperature and humidity continously.
while True:
  # Temperature is measured using the dhtmeasure function.
  adaio.createdata("Temperature", house.dhtmeasure(1, "D3"))
  # The loop pauses for 1 second.
  time.sleep(1)

  # Humidity is measured using the dhtmeasure function.
  adaio.createdata("Humidity", house.dhtmeasure(2, "D3"))
  # The loop pauses for 5 seconds.
  time.sleep(5)

 

The following feeds are created:

Creating Dashboard

Follow the steps:

  1. Go to the dashboard and click on New Dashboard.
  2. Add the Dashboard Name and Description and click on Create.
  3. Open the New Dashboard. Click on the Setting icon in the top right corner and then click on Create New Block.
  4. From the options, click on the line chart.
  5. Select the Temperature Feed and click on Next Step.
  6. Add the Block Title and the Y-Axis Minimum – Maximum value. Click on Create Block.
  7. You will find the block added on the dashboard.
  8. Add a Humidity block as well. Also, add two gauge elements showing the current temperature and humidity value.
  9. Click on the Setting button and Edit Layout to align all the buttons.
Read More
Learn how to create an IoT House Monitoring System that sends humidity, temperature, plant soil moisture, gas, and light sensor data to the cloud on Adafruit IO servers in PictoBlox Python Environment. Get step-by-step instructions on creating a dashboard with sensors and more.

This example shows how to create an IoT House Monitoring system that sends humidity, temperature, plant soil moisture, gas, and light sensor data to the cloud on Adafruit IO servers in PictoBloc Python Environment.

Adafruit IO Key

You can find the information about your account once you log in from here:

 

Adafruit IO Key

You can find the information about your account once you log in from here:

Note: Make sure you are login on Adafruit IO: https://io.adafruit.com/

Sensor Connection to Quarky

We are using 4 sensors in this project:

  1. DHT sensors have 3 pins: GND, VCC, and Signal. You have to connect the following 3 pins to the Quarky Expansion Board:
    1. GND to Ground Pin of Quarky Expansion Board
    2. VCC to 3.3V or VCC Pin of Quarky Expansion Board
    3. Signal to the D3 (Digital Pin) of the Quarky Expansion Board
  2. LDR sensors have 4 pins: GND, VCC, DO, and AO. You have to connect the following 3 pins to the Quarky Expansion Board:
    1. GND to Ground Pin of Quarky Expansion Board
    2. VCC to 3.3V or VCC Pin of Quarky Expansion Board
    3. AO to the A3 (Analog Pin) of the Quarky Expansion Board
  3. The gas sensor has the following connections:
    1. GND Pin connected to GND of the Quarky Expansion Board.
    2. VCC Pin connected to VCC of the Quarky Expansion Board.
    3. AO (Signal Pin) connected to Analog Pin A1 of the Quarky Expansion Board
  4. Moisture Sensor: The moisture sensor provides real-time moisture reading from the soil. The moisture sensor connections are as follows:
    1. GND Pin connected to GND of the Quarky Expansion Board.
    2. VCC Pin connected to VCC of the Quarky Expansion Board.
    3. AO (Signal Pin) connected to Analog Pin A2 of the Quarky Expansion Board

Python Code

# The following code connects to a device, reads sensor values and sends them to a data storage.
# First, the necessary packages are imported.
import time
import math

# Then, three objects are created: one for the IoT house with the sensors and one for the AdaIO and one for Quarky.
house = IoTHouse()
adaio = AdaIO()
quarky = Quarky()

# Variables used by the code are created and initialized.
RS_of_Air = 0
R0 = 0
b = 1.413
m = -0.473

# User Defined Functions

# This function calibrates the gas sensor.
def Get_RO_Calibrated():
  Sensor_Value = 0.1
  # This loop reads the sensor value 20 times.
  for i in range(0, 20):
    Sensor_Value += house.gassensorvalue("A1")
  # This line calculates the average of the 20 readings.
  Sensor_Value = (Sensor_Value / 20)
  
  # This line calculates the RS_of_Air variable.
  RS_of_Air = ((4095 - Sensor_Value) / Sensor_Value)
  
  # This line calculates the R0 variable.
  R0 = (RS_of_Air / 9.8)
  time.sleep(1)


# This function reads the gas sensor.
def Get_Gas_Sensor_Reading():
  # This line reads the sensor value.
  Sensor_Value = house.gassensorvalue("A1")
  # This line checks if the sensor value is 0.
  if (Sensor_Value == 0):
    # This line returns 0 if the sensor value is 0.
    return 0
  else:
    # This line calculates the RS_of_Air variable.
    RS_of_Air = ((4095 - Sensor_Value) / Sensor_Value)
    # This line calculates the RS_RO_Ratio variable.
    RS_RO_Ratio = (RS_of_Air / R0)
    # This line calculates the PPM_in_Log variable.
    PPM_in_Log = (((math.log(RS_RO_Ratio)) - b) / m)
    # This line calculates the PPM variable.
    PPM = (pow(10, PPM_in_Log))
    # This line returns the PPM value.
    return PPM

# This line calls the Get_RO_Calibrated() function.
Get_RO_Calibrated()

# This line connects the program to the AdaIO data storage.
adaio.connecttoadafruitio("STEMNerd", "aio_UZBB56f7VTIDWyIyHX1BCEO1kWEd")

# This line sets the pin to read the moisture sensor.
house.setmoisturepin("A3")

# This loop reads the sensors, prints their values and sends them to the data storage.
while True:
  # This line reads the temperature from the DHT sensor on pin D3 and sends it to the data storage.
  Temperature = house.dhtmeasure(1, "D3")
  adaio.createdata("Temperature", Temperature)
  time.sleep(4)
  
  # This line reads the humidity from the DHT sensor on pin D3 and sends it to the data storage.
  Humidity = house.dhtmeasure(2, "D3")
  adaio.createdata("Humidity", Humidity)
  time.sleep(4)
  
  # This line reads the light from the light sensor on pin A2 and sends it to the data storage.
  Light = house.ldrvalue("A2")
  adaio.createdata("Light", Light)
  time.sleep(4)
  
  # This line reads the moisture from the moisture sensor and sends it to the data storage.
  Moisture = house.readmoisture()
  adaio.createdata("Moisture", Moisture)
  time.sleep(4)
  
  # This line calls the Get_Gas_Sensor_Reading() function to read the gas sensor and sends the value to the data storage.
  PPM = Get_Gas_Sensor_Reading()
  adaio.createdata("Gas Sensor", PPM)
  time.sleep(4)

Creating Dashboard

Follow the steps:

  1. Go to the dashboard and click on New Dashboard.
  2. Add the Dashboard Name and Description and click on Create.
  3. Open the New Dashboard. Click on the Setting icon in the top right corner and then click on Create New Block.
  4. From the options, click on the line chart.
  5. Select the Temperature Feed and click on Next Step.
  6. Add the Block Title and the Y-Axis Minimum – Maximum value. Click on Create Block.
  7. You will find the block added on the dashboard.
  8. Add other blocks for the Humidity, Light, Gas, and Moisture as well.
  9. Click on the Setting button and Edit Layout to align all the buttons.
Read More
All articles loaded
No more articles to load