Visitors

Thursday, July 6, 2017

IoT Pet Feeder



story :

 This IoT pet feeder is our first IoT project with circuito.io! We are happy to share it with our community to demonstrate how simple it can be to make basic IoT projects with circuito.io. We are also excited to share this project with you because it's based on a product that we worked on in the past called Playdog. You can make the feeder for your pets at home - it's both fun JPand useful.



Hardware components :

1- Arduino Arduino UNO & Genuino UNO

2- PIR Motion Sensor (generic)       

3- Everything ESP ESP8266 ESP-0 
                  
4- Speaker: 0.25W, 8 ohms             



Once you've selected the components you waLunant, click on Generate and our engines will start working on your circuit and will generate your circuito reply. The reply has three parts:
1. BoM - A list of all the components you'll need for the project, including auxiliary parts such as resistors and capacitors.
2. Step-by-step wiring guide - shows you how to connect all your components to the Arduino board using a breadboard.
3. Code - a sample code for your circuit. This code is not specific for the pet feeder project, but rather it is a sample code that creates an interaction between the different components in your circuit.
To Upload the code, follow these steps:
  • Download the code from the circuito.io reply
  • Extract it to your computer
  • Open with Arduino IDE
  • Upload to your Arduino
4. Once everything is set up, replace the sample code from the circuito reply with the code in this tutorial. Make sure to leave the //Include Libraries and //Pin Definitions at the top of the code, and also keep all the libraries that are on the original code from circuito.io.
4. Connectivity - this section will guide you how to configure the connection of your project to the internet. Since you're not going to use the sample code from circuito, but rather the code provided in this tutorial, if you click "create dashboard" you'll have to configure the dashboard manually.
If you want to use the pre-set dashboard we used, download the attached pet_feeder_dashboard html file and open it in your browser. Then follow the instructions below.
- Click on “Clone" and create a copy of the dashboard for your project.
- Choose a unique ‘thingName’.
You can find your thingname in the firmware.ino.
- Click on the settings icon at the top of the page.

Assembly :


Now that you have the electronics set up, it's time to put the parts together.
We designed a 3d printed casing for the servo, the PIR sensor and the speaker.
The .stl files are attached here. This part isn't mandatory and you can choose to connect it in a different way, it's really up to you, but look how nice and colorful it is.




code :
const int ServoRestPosition   = 20;  //Starting position
const int ServoTargetPosition = 150; //Position when event is detected
unsigned int HoorayLength          = 6;                                                      // amount of notes in melody
unsigned int HoorayMelody[]        = {NOTE_C4, NOTE_E4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5}; // list of notes. List length must match HoorayLength!
unsigned int HoorayNoteDurations[] = {8      , 8      , 8      , 4      , 8      , 4      }; // note durations; 4 = quarter note, 8 = eighth note, etc. List length must match HoorayLength!

unsigned int comeLength          = 3;
unsigned int comeMelody[]        = {NOTE_C5, NOTE_G5, NOTE_C5};
unsigned int comeNoteDurations[] = {8      , 8      , 8};

ESP8266 wifi(WIFI_PIN_RXD,WIFI_PIN_TXD);
Servo servo;
PIR pir(PIR_PIN_SIG);
PiezoSpeaker piezoSpeaker(PIEZOSPEAKER_PIN_SIG);

int pirCounter = 0;
// ====================================================================
// vvvvvvvvvvvvvvvvvvvv ENTER YOUR WI-FI SETTINGS  vvvvvvvvvvvvvvvvvvvv
//
const char *SSID     = "YOURWIFI"; // Enter your Wi-Fi name 
const char *PASSWORD = "YOURPASSWORD" ; // Enter your Wi-Fi password
//
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ====================================================================


// These Dweet tokens have been auto generated for you.
char* const inputToken  = "12b2cbb8-3f8e-11e7-a810-0242ac110028_input";
char* const outputToken = "12b2cbb8-3f8e-11e7-a810-0242ac110028_output";

Dweet dweet( &wifi, inputToken, outputToken);

/* This code sets up the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. */
void setup() {
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    Serial.println("start");
    
    if (!wifi.init(SSID, PASSWORD))
    {
        Serial.println(F("Wifi Init failed. Check configuration."));
        while (true) ; // loop eternally
    }
    servo.attach(SERVO_PIN);
    servo.write(ServoRestPosition);
    delay(100);
    servo.detach();
}

/* This code is the main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. */
void loop() {

    bool pirVal = pir.read();
    
    //SET DWEETS
    dweet.setDweet("pir", pirVal );
    dweet.setDweet("pirCounter",  pirCounter);
    
    
    dweet.sendDweetKeys();
    
    
    if (pirVal)
    {
        pirCounter++;
        // The servo will rotate to target position and back to resting position with an interval of 500 milliseconds (0.5 seconds) 
        servo.attach(SERVO_PIN);         // 1. attach the servo to correct pin to control it.
        servo.write(ServoTargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
        delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.write(ServoRestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
        delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
        
        // The Piezo Speaker light will play a beep for half a second, wait for another 500ms(half a second) and then play a tune
        piezoSpeaker.tone(400);                                                    // 1. plays a 400Hz beep. Change the value in the brackets (400) for a higher or lower beep.
        delay(500);                                                               // 2. keeps playing it for 500ms
        piezoSpeaker.off();                                                        // 3. stops the beep
        delay(500);                                                               // 4. waits 500ms                   
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        delay(500);                                                               // 4. waits 500ms
    }
    
    
    //GET DWEETS  
    dweet.receiveDweetEvents();
    
    
    if(strcmp(dweet.getValue() , "servo") == 0)
    {
        Serial.println(F("servo was pressed!"));
        // The servo will rotate to target position and back to resting position with an interval of 500 milliseconds (0.5 seconds) 
        servo.attach(SERVO_PIN);         // 1. attach the servo to correct pin to control it.
        servo.write(ServoTargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
        delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.write(ServoRestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
        delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
    }
    else if(strcmp(dweet.getValue() , "piezoSpeaker") == 0)
    {
        Serial.println(F("piezoSpeaker was pressed!"));
        // The Piezo Speaker light will play a beep for half a second, wait for another 500ms(half a second) and then play a tune
        piezoSpeaker.tone(400);                                                    // 1. plays a 400Hz beep. Change the value in the brackets (400) for a higher or lower beep.
        delay(500);                                                               // 2. keeps playing it for 500ms
        piezoSpeaker.off();                                                        // 3. stops the beep
        delay(500);                                                               // 4. waits 500ms                   
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        delay(500);                                                               // 4. waits 500ms
    }
    else if(strcmp(dweet.getValue() , "playGame") == 0)
    {
        Serial.println(F("Playing Game!"));
        while (!pir.read())
        {
          piezoSpeaker.playMelody(comeLength, comeMelody, comeNoteDurations);
          delay(500);
        }
        
        servo.attach(SERVO_PIN);
        servo.write(ServoTargetPosition);
        delay(1000);
        servo.write(ServoRestPosition);
        delay(1000);
        servo.detach();
        
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        
        delay(100);
    }
}






















Earthquake Detector Alarm using Arduino



An earthquake is an unpredictable natural disaster that causes damage to lives and property. It happens suddenly and we cannot stop it but we can be alerted from it. In today’s time, there are many technologies which can be used to detect the small shakes and knocks, so that we can take precautions prior to some major vibrations in earth. Here we are using Accelerometer ADXL335 to detect the pre-earthquake vibrations. Accelerometer ADXL335 is highly sensitive to shakes and vibrations along with all the three axes. Here we are building an Arduino based Earthquake 
Detector .



Components Required:

  • Arduino UNO
  • Accelerometer ADXL335
  • 16x2 LCD
  • Buzzer
  • BC547 transistor
  • 1k Resistors
  • 10K POT
  • LED
  • Power Supply 9v/12v
  • Berg sticks male/female
Accelerometer:
Pin Description of accelerometer:
  1. Vcc         5 volt supply should connect at this pin.
  2. X-OUT   This pin gives an Analog output in x direction
  3. Y-OUT   This pin give an Analog Output in y direction
  4. Z-OUT   This pin gives an Analog Output in z direction
  5. GND      Ground
  6. ST          This pin used for set sensitivity of sensor


Arduino code :
#include<LiquidCrystal.h>      // lcd Header

LiquidCrystal lcd(9,8,7,6,5,4);   // pins for LCD Connection

#define buzzer 12 // buzzer pin

#define led 13  //led pin

#define x A0  // x_out pin of Accelerometer

#define y A1  // y_out pin of Accelerometer
#define z A2  // z_out pin of Accelerometer

/*variables*/

int xsample=0;
int ysample=0;
int zsample=0;
long start;
int buz=0;

/*Macros*/

#define samples 50
#define maxVal 20   // max change limit
#define minVal -20    // min change limit
#define buzTime 5000  // buzzer on time

void setup() 

{
  lcd.begin(16,2);  //initializing lcd
  Serial.begin(9600); // initializing serial
  delay(1000);
  lcd.print("EarthQuake ");
  lcd.setCursor(0,1);
  lcd.print("Detector    ");
  delay(2000);
  lcd.clear();
  lcd.print("Circuit Digest ");
  lcd.setCursor(0,1);
  lcd.print("Saddam Khan    ");
  delay(2000);
  lcd.clear();
  lcd.print("Calibrating.....");
  lcd.setCursor(0,1);
  lcd.print("Please wait...");
  pinMode(buzzer, OUTPUT);
  pinMode(led, OUTPUT);
  buz=0;
  digitalWrite(buzzer, buz);
  digitalWrite(led, buz);
  for(int i=0;i<samples;i++)      // taking samples for calibration
  {
    xsample+=analogRead(x);
    ysample+=analogRead(y);
    zsample+=analogRead(z);
  }

  xsample/=samples;   // taking avg for x

  ysample/=samples;     // taking avg for y
  zsample/=samples;   // taking avg for z
  
  delay(3000);
  lcd.clear();
  lcd.print("Calibrated");
  delay(1000);
  lcd.clear();
  lcd.print("Device Ready");
  delay(1000);
  lcd.clear();
  lcd.print(" X     Y     Z   ");
}

void loop() 

{
    int value1=analogRead(x);   // reading x out
    int value2=analogRead(y);   //reading y out
    int value3=analogRead(z);   //reading z out

    int xValue=xsample-value1;    // finding change in x

    int yValue=ysample-value2;    // finding change in y
    int zValue=zsample-value3;    // finding change in z

  /*displying change in x,y and z axis values over lcd*/

    lcd.setCursor(0,1);
    lcd.print(zValue);
    lcd.setCursor(6,1);
    lcd.print(yValue);
    lcd.setCursor(12,1);
    lcd.print(zValue);
    delay(100);

  /* comparing change with predefined limits*/

    if(xValue < minVal || xValue > maxVal  || yValue < minVal || yValue > maxVal  || zValue < minVal || zValue > maxVal)
    { 
      if(buz == 0)
      start=millis();   // timer start
       buz=1;       // buzzer / led flag activated
    } 

   else if(buz == 1)        // buzzer flag activated then alerting earthquake

   {
      lcd.setCursor(0,0);
      lcd.print("Earthquake Alert   ");
      if(millis()>= start+buzTime)    
      buz=0;
   }
   
    else
    {
      lcd.clear();
      lcd.print(" X     Y     Z   ");
    }

    digitalWrite(buzzer, buz);    // buzzer on and off command

    digitalWrite(led, buz);   // led on and off command

  /*sending values to processing for plot over the graph*/

    Serial.print("x=");
    Serial.println(xValue);
    Serial.print("y=");
    Serial.println(yValue);
    Serial.print("z=");
    Serial.println(zValue);  
    Serial.println(" $");
}







































Tuesday, July 4, 2017

A new ransomware exploit dubbed "Petya" struck major companies and infrastructure sites this week, following last month's WannaCry ransomware attack, which wreaked havoc on more than 300,000 computers across the globe. Petya is believed to be linked to the same set of hacking tools as WannaCry.
Petya already has taken thousands of computers hostage, impacting companies and installations ranging from Ukraine to the U.S. to India. It has impacted a Ukrainian international airport, and multinational shipping, legal and advertising firms. It has led to the shutdown of radiation monitoring systems at the Chernobyl nuclear facility.
Europol, the international law enforcement agency, could not provide operational details on the attack, spokesperson Tine Hollevoet told the E-Commerce Times, but it was trying to "get a full picture of the attack" from its industry and law enforcement partners.
Petya "is a demonstration of how cybercrime evolves at scale and, once again, a reminder to business of the importance of taking responsible cybersecurity measures," Europol Executive Director Rob Wainwright said in a Wednesday update.
Unlike Wannacry, the Petya attack does not include any type of 'kill switch,' according to Europol.
Variant Characteristics
The U.S. Computer Emergency Readiness Team on Tuesday began fielding numerous reports about the Petya ransomware infecting computers around the world, and noted that this particular variant encrypts the master boot records of Windows computers and exploits vulnerabilities in the Server Message Block.
The RANSOM_PETYA.SMA variant uses as infection vectors both the EternalBlue exploit, which was used in the WannaCry attack, and the PsExec tool, which is a Microsoft utility used to run processes using remote access, according to Trend Micro.
Users should apply the MS17-010 security patch, disable TCP port 445, and restrict accounts with administrator group access, the firm recommended.
The Petya variant uses the rundll32.exe process to run itself, and encryption is carried out using perfc.dat, a file located in the Windows folder, Trend Micro said. The ransomware adds a scheduled task and reboots the computer system after one hour. The Master Boot record is modified, allowing encryption to take place, and a ransom note is displayed with a fake CHKDSK notice.
The Petya exploit uses a hardcoded bitcoin address, making decryption more labor-intensive than it was during the WannaCry attack. However, users similarly are asked to pay US$300 to release the data. An estimated $7,500 had been paid as of Tuesday, Trend Micro estimated. However, that number could change as the attacks spread.
Many companies failed to upgrade their computer systems properly following the WannaCry attack, said Gaurav Kumar, CTO at RedLock.
WannaCry exploited legacy Windows systems that had not been patched, even though Microsoft issued an update in March, he told the E-Commerce Times.
Governments should mount coordinated efforts to fight cyberattacks, according to Access Now, an advocate for digital rights and privacy.
The Petya attack's use of the EternalBlue exploit shows that government agencies should not be stockpiling vulnerabilities, the group argued, as the exploit has been linked to the Shadow Brokers' leak of an exploit created by the National Security Agency.
"Governments should promote patching by developing and codifying vulnerabilities equities processes and through support of coordinated disclosure programs," said Drew Mitnick, policy counsel at Access Now.
Corporations Caught
Pharmaceutical giant Merck & Co. on Tuesday confirmed that its computer network was compromised by the attack, and said it was investigating the matter.
International law firm DLA Piper confirmed that its advanced warning systems detected suspicious activity that apparently was linked to a new variant of the Petya malware. The firm said it had taken down its systems to prevent the spread, and that it had enlisted forensic experts and was cooperating with FBI and UK National Crime Agency investigators.
Advertising and public relations firm WPP said it was working with its IT partners and law enforcement agencies to take precautionary measures, restore services where they have been disrupted, and keep the impact on clients, partners and people to a minimum. The company has taken steps to contain the attack and is working to return to normal operations as soon as possible, while protecting its systems.
International shipping firm A.P. Moeller-Maersk reported that a number of company IT systems were down following the attack and said that it had shut down a number of systems to contain the problem. APM terminals were down in a number of ports, and the Port Authority of New York and N.J. issued a warning to delay arrivals in light of APM's system issues

Sunday, July 2, 2017

Air Quality Monitoring Device Using Arduino



ABOUT THIS PROJECT

So, whilst thinking of a good demonstration for the Opensensors platform, we thought why not see how polluted our workplace is by hooking up a sensor to publish a continuous data stream to the Opensensors messaging broker.


For this we need an easy to pick up and use sensor, we settled on the Shinyei PPD-42. We’ll use this in order to measure the number of potentially hazardous small particulates in the air, with an arduino connected to a linux PC (or Raspberry PI).

To run this mini-project you will need:
  1. Shinyei PPD-42
  2. Arduino UNO
  3. Computer with Linux installed (you can use a Raspberry PI)



We are basing this run-through on a project called DustDuino that uses the Shinyei PPD-42 sensor with an arduino and a wifi module. Check it out here. We used this project as our reference when setting up the sensor and writing the Arduino code.





Firstly we follow step 2 of the instructions for hooking up the sensor to the Arduino. Then we download the code from the projects github repository by opening the link for the code DustDuinoSerial.ino selecting raw and saving that page.

Opening this up in the arduino IDE, we now upload it to our Arduino UNO by connecting the Arduino and pressing upload.
You can check the data is coming in by using the Arduino IDE’s serial monitor.
We then need to figure out how to send the incoming serial message to the Opensensors message broker.

To do this we chose to write a Python script. We used the Mosquitto Python module. I’m going to assume that you already have Python installed, as it comes pre-packaged on most versions of Linux. If you don’t have it already, you’ll need to install pip to download and set up the Mosquitto python module. On Ubuntu or Debian this can be done with the following command:
sudo apt-get install python-pip 
Once pip is installed we can install the Mosquitto python client module using the following command:

sudo pip install paho-mqtt


Final code 

import serial
import paho.mqtt.client as mqtt
import time

mqttc = mqtt.Client(client_id="939")
mqttc.username_pw_set("Louis", password="AbcDEFgH")
mqttc.connect("opensensors.io")

ser = serial.Serial('/dev/ttyACM0')  # open first serial port
while True:
message= ser.readline()
print message
mqttc.publish("/users/Louis/ODI/airquality", payload=message, qos=0, retain=False)
time.sleep(1);


















Monday, June 19, 2017

Arduino shield

What is a Shield?

Arduino shields are modular circuit boards that piggyback onto your Arduino to instill it with extra functionality. Want to connect your Arduino to the Internet and post to Twitter? There’s a shield for that. Want to make your Arduino an autonomous rover? There are shields for that. There are dozens (hundreds?) of shields out there, all of which make your Arduino more than just a development board with a blinky LED.
Many Arduino shields are stackable. You can connect many shields together to create a “Big Mac” of Arduino modules. You could, for example, combine an Arduino Uno with a Voice Box Shield, and a WiFly Shield to create a WiFi Talking Stephen Hawking™.
Shields are often supplied with either an example sketch, or a library. So, not only do they just simply plug into your Arduino, but all you need to do to make them work is upload up some example code to the Arduino.

Shield Form Factor

Every Arduino shield must have the same form-factor as the standard Arduino. Power and ground pins on one eight (previously six) pin header, and analog pins on a six-pin header next to that. Digital pins cover the other edge on the other side, an eight-pin header separated from a 10-pin by that weird 0.5" spacing. Some shields also require a connection to the Arduino’s ICSP header (the 2x3 programming header on the end).

Some shields use every pin on the Arduino, while others only use a couple. When stacking shields, it’s important to make sure they don’t use overlapping pins. Some shields communicate with the Arduino via SPII2C, or Serial, and others use the Arduino’s interrupts or analog inputs.

There’s a great variety of Arduino shields out there – too many to ever include in this tutorial. On the next page we’ll go over a handful of the more popular and unique shields.

Shieldstravaganza

Here’s a list of SparkFun’s more popular and unique shields. This isn’t an exhaustive list of all Arduino shields (for that, check out shieldlist.org), but it’s a good collection. They’re sorted into semi-logical categories.
If you’re more visually inclined, check out our ShieldStravaganza Video Series (Part 1Part 2, and Part 3). These three exciting videos are filled to the brim with shields, shields, shields, oh…and more shields.

Prototyping (And Then Some)

Prototyping shields don’t add much functionality to the Arduino, but they do help in other ways. These shields might do something as simple as breaking out the Arduino pins to screw terminals. In general they make wiring to the Arduino easier.