Friday 8 February 2019

Raspberry Pi Sending Sensor Data to Thingspeak


Raspberry Pi Sending Dht22 Sensor Data to Thingspeak:
In this project we are going to interface dht22 sensor to raspberry pi. In this we are going to explain you about how we can get sensor data in cloud. Here we are using thingspeak as a cloud for getting sensor data.

Component Used:

Raspberry Pi:s
This is the latest version of raspberry pi. In this we have inbuilt Bluetooth and wi-fi, unlike previously we have to use Wi-Fi dongle in one of its usb port. There are total 40 pins in RPI3. Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins.) There are 4 USB Port and 1 Ethernet slot, one HDMI port, 1 audio output port and 1 micro usb port and also many other things you can see the diagram on right side. And also we have one micro sd card slot wherein we have to installed the recommended Operating system on micro sd card. There are two ways to interact with your raspberry pi. Either you can interact directly through HDMI port by connecting HDMI to VGA cable, and keyboard and mouse or else you can interact from any system through SSH.




DHT22 sensor:

DHT22 capacitive humidity sensing digital temperature and humidity
module is one that contains the compound has been calibrated digital signal output of the temperature and humidity sensors. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability.





Thingspeak Working:
So till now you got the software and hardware required in this project. So Now It's time for thingspeak. So what is thingspeak:-> ThingSpeak is an open source Internet of Things (IoT) application and API to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network.

So for getting the graph and sensor data in thingspeak first you have to create an account in thingspeak. After creating the account now just sign in the account. Now you need to create a channel so click on New Channels shown in above figure. now give name to your channel and fill some of the things like description and field1 and field2. We can make up to 8 field for a single channel. Here we need only 2 channels as we are getting temperature and humidity from dht22 sensor.

Now after creating the channel you need to go to API Keys and get the key of that channel this key you will use in your python script.





Circut Diagram:





Voice Recognition System Using Arduino


Voice Recognition System Using Arduino:

Introduction to Our Project:
In this project we are using Arduino, Bluetooth Module(HC-05) and Smart phone. Here we are going to recognize our voice through one smartphone App and for that purpose we have connected one led to pin number 13 of arduino. So first we have to connect our app to Arduino through HC-05 bluetooth module. So we have to enable our bluetooth in smartphone and then we have to connect to Arduino through HC-05. After getting the successful connection when we'll open that app and we will say 'switch on the light' (as we have written in our code) so our led will turn on and if we say 'switch off the light' so our led will turn off. So you can say anything as you have to modify your code for that and also you can control anything even any electrical appliances as well. Here we have chosen one led for that.

Software Used:

Installation of Arduino IDE:
You can download the latest version of Arduino IDE from the below link-

https://www.arduino.cc/en/Main/Software




we are using one smartphone app named AMR_Voice. Here below is the link to download





Component Used:

1) Arduino UNO:
Arduino/Genuino 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.



2) HC-05 Bluetooth Module: HC05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module,designed for transparent wireless serial connection setup.The HC-05 Bluetooth Module can be used in a Master or Slave configuration, making it a great solution for wireless communication.This serial port bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04External single chip Rluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature).




Circuit Diagram:
Here you can see how hc-05 and one single led is connected to Arduino uno. You have to make sure one thing that Tx of HC-05 should be connected to Rx of Arduino and Rx of Hc-05 is connected to Tx of Arduino.

VCC(HC-05)--------------------5V of Arduino(3.3V of Arduino),

GND(HC-05)--------------------GND of Arduino

Rx(HC-05)-----------------------Tx of Arduino

Tx(HC-05)------------------------Rx of Arduino









Vehicle Tracking System


Vehicle Tracking System Using Gps Modem:

This GPS based vehicle tracking system based on the arduino using global positioning system (GPS) and global system for mobile communication (GSM).

Project Description:
This is a two-way GPS communication system wherein communication is done in both ways with GPS satellites. This project uses only one GPS device and two-way communication is achieved using a GSM modem. GSM modem with a SIM card used here implements the same communication technique as in a regular cellphone.The system can be mounted in your vehicle in a hidden or suitable compartment. After this installation, you can easily track your vehicle using your mobile phone by dialling the mobile number of the SIM attached to the GSM modem. When you want then You will get the location of the vehicle in the form of an SMS on your mobile phone.



Component Used:

a) GPS Module:
GPS modules typically put out a series of standard strings of information, under something called the National Marine Electronics Association (NMEA) protocol.



b) GSM MODULE (SIM-900):
This is a GSM/GPRS-compatible Quad-band cell phone, which works on a frequency of 850/900/1800/1900MHz and which can be used not only to access the Internet, but also for oral communication (provided that it is connected to a microphone and a small loud speaker) and for SMSs. Externally, it looks like a big package (0.94 inches x 0.94 inches x 0.12 inches) with L-shaped contacts on four sides so that they can be soldered both on the side and at the bottom. Internally, the module is managed by an AMR926EJ-S processor, which controls phone communication, data communication (through an integrated TCP/IP stack), and (through an UART and a TTL serial interface) the communication with the circuit interfaced with the cell phone itself. The processor is also in charge of a SIM card (3 or 1,8 V) which needs to be attached to the outer wall of the module. In addition, the GSM900 device integrates an analog interface, an A/D converter, an RTC, an SPI bus, an I²C, and a PWM module. The radio section is GSM phase 2/2+ compatible and is either class 4 (2 W) at 850/ 900 MHz or class 1 (1 W) at 1800/1900 MHz. The TTL serial interface is in charge not only of communicating all the data relative to the SMS already received and those that come in during TCP/IP sessions in GPRS (the data-rate is determined by GPRS class 10: max. 85,6 kbps), but also of receiving the circuit commands (in our case, coming from the PIC governing the remote control) that can be either AT standard or AT-enhanced SIMCom type. The module is supplied with continuous energy (between 3.4 and 4.5 V) and absorbs a maximum of 0.8 A during transmission. Figure is given below.




c) ARDUINO UNO:
Arduino/Genuino 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. Figure is given below.



Applications of Project
1) You can locate your stolen vehicle easily using your mobile (gsm).

2) It can be used for trucks carrying valuable goods, to keep track of the status of delivery and location of the truck at all times.

3) You can easily install it in any vehicle such as cars, boats and motorbikes. An SMS will inform your vehicle position.



Code of Project:
#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>
SoftwareSerial gps(10,11); // RX, TX

//String str="";
char str[70];
String gpsString="";

char *test="$GPGGA";

String latitude="No Range      ";
String longitude="No Range     ";

int temp=0,i;
boolean gps_status=0;

void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
  gps.begin(9600);

  lcd.print("Vehicle Tracking");
  lcd.setCursor(0,1);
  lcd.print("System using gps");
  delay(2000);
  gsm_init();
  lcd.clear();
  Serial.println("AT+CNMI=2,2,0,0,0");
  lcd.print("GPS Initializing");
  lcd.setCursor(0,1);
  lcd.print("GPS not in Range");
  get_gps();
  delay(2000);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0,1);
  lcd.print("GPS is Ready");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  temp=0;
}

void loop()
{
  serialEvent();
  if(temp)
  {
    get_gps();
    tracking();
  }
}

void serialEvent()
{
  while(Serial.available())
  {
    if(Serial.find("Track Vehicle"))
    {
      temp=1;
      break;
    }
    else
    temp=0;
  }
}

void gpsEvent()
{
  gpsString="";
  while(1)
  {
   while (gps.available()>0)            //checking serial data from GPS
   {
    char inChar = (char)gps.read();
     gpsString+= inChar;                    //store data from GPS into gpsString
     i++;
     if (i < 7)                     
     {
      if(gpsString[i-1] != test[i-1])         //checking for $GPGGA sentence
      {
        i=0;
        gpsString="";
      }
     }
    if(inChar=='\r')
    {
     if(i>65)
     {
       gps_status=1;
       break;
     }
     else
     {
       i=0;
     }
    }
  }
   if(gps_status)
    break;
  }
}

void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag=1;
  while(at_flag)
  {
    Serial.println("AT");
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      at_flag=0;
    }
   
    delay(1000);
  }

  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag=1;
  while(echo_flag)
  {
    Serial.println("ATE0");
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      echo_flag=0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag=1;
  while(net_flag)
  {
    Serial.println("AT+CPIN?");
    while(Serial.available()>0)
    {
      if(Serial.find("+CPIN: READY"))
      net_flag=0;
    }
    delay(1000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  delay(1000);
  lcd.clear();
}

void get_gps()
{
   gps_status=0;
   int x=0;
   while(gps_status==0)
   {
    gpsEvent();
    int str_lenth=i;
    latitude="";
    longitude="";
    int comma=0;
    while(x<str_lenth)
    {
      if(gpsString[x]==',')
      comma++;
      if(comma==2)       
      latitude+=gpsString[x+1];    
      else if(comma==4)       
      longitude+=gpsString[x+1];
      x++;
    }
    int l1=latitude.length();
    latitude[l1-1]=' ';
    l1=longitude.length();
    longitude[l1-1]=' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Long:");
    lcd.print(longitude);
    i=0;x=0;
    str_lenth=0;
    delay(2000);
   }
}

void init_sms()
{
  Serial.println("AT+CMGF=1");
  delay(400);
  Serial.println("AT+CMGS=\"+9100000000\"");   // you have enter your mobile no.
  delay(400);
}

void send_data(String message)
{
  Serial.println(message);
  delay(200);
}

void send_sms()
{
  Serial.write(26);
}

void lcd_status()
{
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  return;
}

void tracking()
{
    init_sms();
    send_data("Vehicle Tracking Alert msg:");
    send_data("Your Vehicle Current Location:");
    Serial.print("Latitude:");
    send_data(latitude);
    Serial.print("Longitude:");
    send_data(longitude);
    send_data("Thank you");
    send_sms();
    delay(2000);
    lcd_status();
}


Virtual World Using Arduino



Creating a Virtual World Using Arduino and Python:

Introduction to Our Project:
how to create a simple virtual world using vPython library.In this project we are using Arduino and Ultasonic Sensor for sensing the virtual world. The virtual world is use in real time based on measurements from the arduino and ultrasonic sensor. In this project you can use how to combine Arduino, Python, and vPython library to create a virtual world i.e virtual object updated based on sensor measurements.
Installation of All Software:
Arduino IDE:
Installation of Arduino IDE: You can download the latest Arduino IDE from this link:

https://www.arduino.cc/en/Main/Software




Python:
Download and Install Python 2.7.8.for windows. Link is given below:

https://www.python.org/downloads/windows/

Pyserial:
Download and Install Pyserial version 2.7 for windows. Link is given below:

https://learn.adafruit.com/arduino-lesson-17-email...


vPython:
Download and install the Vpython library for windows. Link is given below:




Component Used:
1) Arduino UNO:
Arduino/Genuino 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.



2)Ultrasonic sensor:
This is the HC-SR04 ultrasonic ranging sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.



Circuit Description:
First we are going to connect ultrasonic sensor with Arduino board. Then according to program our ultrasonic sensor going to generate a trigger signal which is going to receive by our echo pin of Ultrasonic Sensor. Then we are going to run our arduino code. According to Arduino code our Ultrasonic Sensor detect the distance of any object.

Here are the connections of our circuit:

Ultrasonic Sensor---Arduino UNO

GND---------------------GND

Echo------------------- pin 11

Trig..........................pin13

Vcc.........................5v




Code of the Project:

Step to run Code:
1) Firstly you can run Arduino code.

2) After that You can run python script, before running python script you can install Pyserial and vPython.

Arduino Code:

int trigPin=13; //Sensor Trig pin connected to Arduino pin 13
int echoPin=11;  //Sensor Echo pin connected to Arduino pin 11
float pingTime;  //time for ping to travel from sensor to target and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
 
  digitalWrite(trigPin, LOW); //Set trigger pin low
  delayMicroseconds(2000); //Let signal settle
  digitalWrite(trigPin, HIGH); //Set trigPin high
  delayMicroseconds(15); //Delay in high state
  digitalWrite(trigPin, LOW); //ping has now been sent
  delayMicroseconds(10); //Delay in low state
 
  pingTime = pulseIn(echoPin, HIGH);  //pingTime is presented in microceconds
  pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
  targetDistance= speedOfSound * pingTime;  //This will be in miles, since speed of sound was miles per hour
  targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.
  targetDistance= targetDistance*63360;    //Convert miles to inches by multipling by 63360 (inches per mile)
 
  Serial.println(targetDistance);
 
  delay(100); //delay tenth of a  second to slow things down a little.
}


Python Script:
import serial #Import Serial Library
from visual import * #Import all the vPython library

arduinoSerialData = serial.Serial('com3', 9600) #Create an object for the Serial port. Adjust 'com11' to whatever port your arduino is sending to.
measuringRod = cylinder( radius= .1, length=6, color=color.yellow, pos=(-3,-2,0))
lengthLabel = label(pos=(0,5,0), text='Target Distance is: ', box=false, height=30)
target=box(pos=(0,-.5,0), length=.2, width=3, height=3, color=color.green)
while (1==1):  #Create a loop that continues to read and display the data
    rate(20)#Tell vpython to run this loop 20 times a second
    if (arduinoSerialData.inWaiting()>0):  #Check to see if a data point is available on the serial port
        myData = arduinoSerialData.readline() #Read the distance measure as a string
        print myData #Print the measurement to confirm things are working
        distance = float(myData) #convert reading to a floating point number
        measuringRod.length=distance #Change the length of your measuring rod to your last measurement
        target.pos=(-3+distance,-.5,0)
        myLabel= 'Target Distance is: ' + myData #Create label by appending string myData to string
        lengthLabel.text = myLabel #display updated myLabel on your graphic