You keep hearing about Internet of Things and decide to search around to see what you can learn and where to start, but what you find ? A bunch of resistors you do not understand because your electronic knowledge is equal of a 5 years old kid aka none. If it sounds familiar to you I have good and bad news:

The bad: You will have to study some electronics to do even very basic things.

The good: Not today. (something explodes behind and you don't look back)

p.s: I actually don't know if the good is bad too.

I will give something to motivate you: The easiest introduction to IoT ever made ! In fact this statement is probably not true but the slogan is nice and it's really easy anyway. You won't need to use any resistors or deep knowledge about electronics. We will begin with a simple LED and suddenly your plant will be sending tweets.

To make this thing work follow me and don't try to get fancy ok ? I will list what you will need, and no you can't change nothing in the list because it's sounds like a fancy attitude and you promised to me that wouldn't happen.

LED

Johnny Five is a library to Javascript robotics that make a lot of things easier. After you install it let's make a "Hello World": The LED !

Open your editor of choice and use this snippet:

import five from 'johnny-five'

let board = new five.Board()

board.on('ready', function () {
  new five.Led(13).blink(200)
})

With the LED connected with the positive(+) aka greater leg in the 13 and the negative(-) in the ground like the gif above run your program (fancy alert: don't connect in other PIN that's not the 13, this PIN have a builtin resistor):

$ babel-node my-led-code.js

* I'm assuming that you have babel installed on your machine, case it's not true run this snippet:

$ npm install babel

Now let's see some LED blink to make your family happy:

LCD

So, LED was fun right ? You can have coded space ships already but if you show some LED blinking to your family they will certainly congratulate you and say that your education now can be used for something. Anyway, let's go to the LCD. First of all link all your wires this way:

Our code:

import five from 'johnny-five'

let board = new five.Board()

board.on('ready', function () {
  let lcd = new five.LCD({
    controller: 'PCF8574'
  })

  lcd.useChar('heart')
  lcd.cursor(0, 0).print('We :heart: LCD !')
  lcd.blink()
})

Running our code we can see all the love flowing:

Moisture Sensor

Let's try a sensor to see how it works. Plug your moisture sensor like this:

Adding some johnny-five to the mix:

import five from 'johnny-five'

let board = new five.Board()

board.on('ready', function () {
  let moisture = new five.Sensor({
    pin: 'A0',
    freq: 1000
  })

  moisture.on('change', function (value) {
    console.log(value)
  })
})

Fitting together

What about we show the moisture on the lcd ? Plug all the things !

import five from 'johnny-five'

let board = new five.Board()

board.on('ready', function () {
  let lcd = new five.LCD({
    controller: 'PCF8574'
  })

  let moisture = new five.Sensor({
    pin: 'A0',
    freq: 100
  })

  moisture.on('change', function (value) {
    console.log(value)
    lcd.cursor(0, 0).print(`Moisture: ${value}`)
  })
})

Now we will print on console and LCD the moisture level. Since this sensor is for Botany, why not measure it from a plant right ? Let me introduce you to The Plant (Sorry, I couldn't find a cool name).

The magic happening:

But where is the internet ?

Well, this buzzword IoT needs to make sense right ? Our plant will send to us a direct message on Twitter if the moisture level is below an arbitrary value. We will need the npm package node-twitter for it and Twitter app credentials assigned to our plant profile of course:

import five from 'johnny-five'
import Twitter from 'node-twitter'

let board = new five.Board()
let twitter = new Twitter.RestClient(
  'CONSUMER_KEY',
  'CONSUMER_SECRET',
  'TOKEN',
  'TOKEN_SECRET')

board.on('ready', function () {
  let moisture = new five.Sensor({
    pin: 'A0',
    freq: 10000
  })

  moisture.on('change', function (value) {
    if (value < 90) {
      let options = {
        screen_name: '[email protected]',
        text: 'I need water !' 
      }

      twitter.directMessagesNew(options, function (err, data) {
        if (err) {
          console.error(err)
        } else {
          console.log(data)
        }
      }) 
    } 
  })
})

If you noticed I changed the freq of the sensor a bit because we don't want to receive a thousand messages. Now whenever our plant need water we will receive a message :)

Is it cool or not ? If you don't think it is don't answer, let me think it is !

Wrapping up

Our device is not done yet, the Arduino is using the connection of your machine to send the tweets. We need a wifi shield or something to get a standalone solution.

Sadly it's for another post, I hope you enjoyed this introdution and this has motivated you to create awesome projects with Arduino, sensors and your imagination. See you soon !