Project tutorial

Plant Monitoring Using Alexa © GPL3+

Plant monitoring using Arduino, Alexa and RPi.

  • 3,590 views
  • 0 comments
  • 16 respects

Components and supplies

About this project

General Introduction

In this project we will be using Arduino, Raspberry Pi and Alexa for a voice-controlled IoT plant monitoring device.

This system can measure the temperature and light intensity of the surrounding in this plant and give the values to anyone who accesses this skill.

The sensors are connected to the Arduino to read the analog values coming from the sensor. These sensor values are converted into digital values and are sent serially to the Raspberry Pi.

The Raspberry Pi has a server for Alexa running in it. The values are attached to the invoked indents user asks for.

Thus it solves for plant monitoring using voice commands.

This is a sample project and you can expand the project to connect any number of sensors to the Arduino or Raspberry Pi to solve your problem.

Let's get through the steps involved in the prototyping of the plant monitoring system.

Hardware Required

1. Arduino Uno

Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.

2. Raspberry Pi 3

The Raspberry Pi 3 Model B is the third generation Raspberry Pi. It adds wireless LAN & Bluetooth connectivity making it the ideal solution for powerful connected designs.

Raspberry Pi 3 - Model B Features

  • Now 10x Faster - Broadcom BCM2387 ARM Cortex-A53 Quad Core Processor powered Single Board Computer running at 1.2GHz!
  • 1GB RAM so you can now run bigger and more powerful applications.
  • Fully HAT compatible.
  • 40pin extended GPIO to enhance your “real world” projects.
  • Connect a Raspberry Pi camera and touch screen display (each sold separately)
  • Stream and watch Hi-definition video output at 1080.
  • Micro SD slot for storing information and loading your operating systems.
  • 10/100 BaseT Ethernet socket to quickly connect the Raspberry Pi to the Internet.

3. Temperature sensor (lm35)

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than 0.1 oC temperature rise in still air. The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC.

4.LDR (Light-Dependent Resistor)

A photoresistor (or light-dependent resistor, LDR, or photoconductivecell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

Let's see how a photo resistor react in light. Build the circuit above and notice how led brightness change.The resistance value becomes smaller when there is much light in the room. So in the dark the led remains off because the resistance has become very big.

LDR voltage divider

A light-dependent resistor (LDR) connects to a voltage divider circuit, also known as a potential divider (PD), for proper circuit operation. There are two configurations of the circuit depending upon the position of the LDR within the potential divider network.You can have a configuration where the voltage output (Vout) increases as light increases or one where the voltage output decreases as light increases. The following calculators and their respective formulas show how both configurations work.

Raspberry Pi

I used a Raspberry Pi 3 and a fresh Raspbian Strech image downloaded from

https://www.raspberrypi.org/downloads/raspbian/

Two terminal sessions will be needed so using SSH to access the Pi is recommended. Once logged in, enter the following commands to install the required packages and python libraries:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install python2.7-dev python-dev python-pip 
sudo pip install Flask flask-ask
sudo apt-get install python-serial

Ngrok setup

Ngrok is a command-line program that opens a secure tunnel to localhost and exposes that tunnel behind an HTTPS endpoint. ngrok makes it so Alexa can talk to your code right away. Follow the next three steps to generate a public HTTPS endpoint to 127.0.0.1:5000.

Visit https://ngrok.com/download and get the latest Linux ARM release as a zip and unzip inside the home directory:

Next, run it from the command line with:

 ./ngrok http 5000

Your screen should look like the image above. Note the 'Forwarding' URL that starts with HTTPS, it will be used later. Note: Unfortunately the n grok URL changes every time the service is started so it is not a permanent solution if you are trying to run this full time. I'd recommend a service like Yaler or Page Kite if you need a more permanent URL to use with your new Skill.

After Ngrok, make a script (.py) program is given below copy and paste that code in your file.

Arduino

For Arduino part code is given below copy that code and upload it. After uploading the code connect Arduino with RPi serially.

Amazon Website Configurations

1. First create or login to your AWS Developer Account and open your list of Alexa skills.

2. Add new skill

3. Skill Information

Set the Skill Name to 'plant_monitor' and the Invocation Name to the word(s) you want to use to activate the skill. Click 'Next' to continue.

4. Interaction Model

Build the interaction model with the following indents mentioned in the image. This can help us to invoke the actions with respect to the commands as user says.

  • Click on Add new intent, Name it light and add sample utterances which you want to use.
  • Add new intent , temperature and sample utterances.
  • Save model and built it.

5. Configuration Page

Select 'HTTPS' as the Service Endpoint Type and select a region. Enter the ngrok URL and click 'Next'. The URL should be something like:

6. SSL Certificate

Select the 'My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority' option and click 'Next'.

Your skill is ready to work.

Interfacing of Arduio with RPi

Interfacing of LM35, LDR and Arduino

Vo is connected to Analog pin 1 and LM35 is connected to Analog 0.

Testing

If everything was setup correctly you should now see a screen similar to the first image above. The Skill is now enabled and can be accessed through any Amazon Echo device(or at http://echosim.io/) that is connected to your AWS Developer.

As far as I can tell there is nothing stopping someone from running this continuously in a 'development' mode for personal use though... My ultimate goal is to use this to integrate Alexa into my existing Raspberry Pi-based Smart Home setup so that everything can be controlled hands-free. This is my first project so any feedback is appreciated. If you have any questions or trouble setting this up I will do my best to help. Good luck!

Setup

Output Video

Code

Python ScriptPython
from flask import Flask

from flask_ask import Ask, statement, convert_errors

import RPi.GPIO as GPIO

import logging

import serial

import time

temp = 0

light = 0

serial1 = serial.Serial('/dev/ttyACM0',9600) //change according to yours

def caller1():

  read_data = 0

  read1 = serial1.readline()

  read_data = read1.rstrip('\n\r')

  n1 = str (read_data)

  n2 = str (read_data)

  temp = n1[:2]

  print temp

  light = n2[2:]

  return(temp)

def caller2():

  read_data = 0

  read1 = serial1.readline()

  read_data = read1.rstrip('\n\r')

  n2 = str (read_data)

  light = n2[2:]

  return(light)

app = Flask(__name__)

ask = Ask(app, '/')

logging.getLogger("flask_ask").setLevel(logging.DEBUG)

@ask.intent('temperature')

def temperature():

  x = 'The temperature is ' + caller1()

  return statement(x)

@ask.intent('light')

def light():

  x = 'The intensity of light is ' + caller2()

  return statement(x)

if __name__ == '__main__':

  app.run(debug=True)
ArduinoArduino
  int ldr = 1;

  int temperature = 0;

  int tempc;

  void setup() {

  Serial.begin(9600);

  }

  void loop() {

  float val1 = analogRead(0);

  tempc =(5 * val1 * 100) / 1024.00;

  Serial.print(tempc);

  int val2 = analogRead(1);

  val2 = val2 * 0.10;

  Serial.println(val2);

  delay(1000);

  }

Schematics

Interface of Arduino AND Raspberrypi
I20 gkkdot083p
Interface of Arduino with LM35
i1_WpiLBU404W.jfif
Interface of Arduino with LDR
i2_WRxucaiz5W.jfif

Comments

Similar projects you might like

Arduino Uno-Based, Easy-to-Build Pet Feeder

Project tutorial by edr1924

  • 2,153 views
  • 3 comments
  • 20 respects

HOW PIR SENSOR WORK

Project tutorial by DIY Partners

  • 2,797 views
  • 6 comments
  • 21 respects

4-Stroke Digital Clock With Arduino

Project tutorial by LAGSILVA

  • 7,541 views
  • 8 comments
  • 30 respects

RGB Camera Backlight Control with Android Mobile

Project tutorial by DIY Partners

  • 185 views
  • 0 comments
  • 2 respects

"Living Art" Arduino-Controlled Desk Lamp

Project tutorial by Modustrial Maker

  • 1,678 views
  • 0 comments
  • 5 respects
Add projectSign up / Login