P5.js codes in side bloggers

p5.js is a JavaScript library that starts with the original goal of Processing—to make coding accessible for artists, designers, educators, and beginners—and reinterprets this for today's web.

So you have made your p5.js code at your local server or with processing ide, and now you are trying to publish it over internet. Publishing over internet is quite a long process and might cost you a little. Here I have came with a solution to put your processing code over internet using bloggers. Its free and fast, easy to use.

Make your code using p5.js either using local server of using processing ide. After verifying that code, put that inside the given area below. Don,t modify the other codes, you might end-up in errors.

Open bloggers -> themes ->Edit Html ->Paste the code below

Code below:  

<?xml version="1.0" encoding="UTF-8" ?>

<html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>

 <head>

  <meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/> 

  <b:if cond='data:blog.isMobile'> 

   <meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/> 

  <b:else/> 

   <meta content='width=1100' name='viewport'/> 

  </b:if> 

  <b:include data='blog' name='all-head-content'/>

  <title><data:blog.pageTitle/></title>

  <b:skin><![CDATA[

   /* 

    body { 

     font: $(body.font); 

     color: $(body.text.color); 

     background: $(body.background); 

     padding: 0 $(content.shadow.spread) $(content.shadow.spread) $(content.shadow.spread); 

     $(body.background.override) margin: 0; 

     padding: 0; 

    }

   

  ]]></b:skin>

 <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js'/>

    <script>

 <!--Paste in between-->     

      const barWidth = 20;

let lastBar = -1;


function setup() {

  createCanvas(720, 400);

  colorMode(HSB, width, height, 100);

  noStroke();

}


function draw() {

  let whichBar = mouseX / barWidth;

  if (whichBar !== lastBar) {

    let barX = whichBar * barWidth;

    fill(barX, mouseY, 66);

    rect(barX, 0, barWidth, height);

    lastBar = whichBar;

  }

}

<!--Paste in between-->

    </script>

 </head>

<body>

  <b:section class='main' id='main' showaddelement='yes'/>

  </body>

</html>

Using HCSR04 - Ultrasonic Sensor


How the Ultrasonic Sensor works:
Ultrasonic sensors work by emitting sound waves at a frequency too high for humans to hear. They then wait for the sound to be reflected back, calculating distance based on the time of the journey. This is similar to how radar measures the time it takes a radio wave to return after hitting an object.While some sensors use a separate sound emitter and receiver, it’s also possible to combine these into one package device, having an ultrasonic element alternate between emitting and receiving signals. This type of sensor can be manufactured in a smaller package than with separate elements, which is convenient for applications where size is at a premium.
Requirements:

Hardwares
  • Arduino Uno
  • HCSR04 Module
  • Jumper wires
  • LED series with 200 ohm resister(here we will use in-built led on 13 pin)
Softwares
Circuit Diagram

Code to be run:
//In this project, if a object appears in front of Ultrasonic Sensor with in the range 30-50 cm, the led will glow for 5 seconds.

#include <HCSR04.h>

HCSR04 hc(2,3);//initialisation class HCSR04 (trig pin , echo pin)
const int led= 13;
const int uplimit= 50, lowlimit= 30; //Any object between 30cm to 50cm to trigger led//

void setup()
  Serial.begin(9600); 
  pinMode(13,OUTPUT);
}

void loop()
  int distance = hc.dist();
  Serial.println(distance); 
  if( (distance>=lowlimit) && (distance<= uplimit))//OBJECT IN RANGE=LED ON FOR 5 SECS
  {
    digitalWrite(led, HIGH);
    delay(5000);
    digitalWrite(led, LOW);
  }
}


Code to Re-Connect Blynkserver Automatically

Issue: Sometimes the hardware(eg. Nodemcu) doesn't connect to router automatically, when there is a break in connection.




Solution: 
In this we'll add a timer. When there is no connection, the timer will start and try to reconnect in every specified time interval. to make this happen we need a library called as simple timer.
Extract this library to the library folder in Arduino folder in my documents.

Write the  following code:

#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

SimpleTimer timer;    //Creating simple timer variable 

char auth[] = "MxLDc********************KtUI";

char ssid[] = "**********";
char pass[] = "**********";

void setup()
{
  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000, reconnectBlynk); //Setting interval to 10 seconds to Run function"reconnectBlynk"
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}
void loop()
{
  
  if (Blynk.connected()) {
    Blynk.run();
  }
  if (!Blynk.connected()) {
    timer.run();
  }
}

IOT Robot with NodeMCU and Arduino using Blynk.

Introduction:

Controlling robots wirelessly is great fun. There are many methods available through which you can control your robot wirelessly.
They are:
  1.  RF remote controller
  2.  Bluetooth signal
  3.  IR signal
  4.  Wifi or IOT etc...
Here I have made a project of robot controlled over IOT using blynk app,arduino and nodemcu.

Things needed

  • Arduino
  • Nodemcu(Esp8266)
  • 2 DC motors and Motor driver
  • LCD display(may or may not added)
  • Batteries or any other power source
  • Blynk Application 
  • Jumper wires etc.

Step 1: Building the Body of Robot

I Build the robot with Sun-board and card board gluing them with super glue. I used old mobile batteries as source and stick them to body. here are some pictures of my build.


Step 2: Connection of different elements

  • Connect two dc motors to the motor driver. for more about motor drivers follow this:https://www.ganeshgadgets.co.in/2017/09/line-follower-part-2-motor-driver.html
  • Connect arduino to the motor driver. use enable of motor driver with PWM inputs of arduino.
  • Power up nodemcu with arduino from 5v pin. Here the idea is when arduino receives digital output from nodemcu at its input pins it would do certain actions.
  • 5 outputs from nodemcu(D0-D4) is fed to 5 pins of arduino(A0 toA5 -here digital pins are used so pin 14 to pin 19).
  • Example when D0 of nodemcu is high, Arduino receives signal and command noter driver to go forward. 
Code example:
if ( digitalRead(a0) == HIGH ) //forward//
 {
  lcd.setCursor(0, 1);
  lcd.print("FORWARD ");
  digitalWrite(af, HIGH);
  digitalWrite(ar, LOW);
  digitalWrite(bf, HIGH);
  digitalWrite(br, LOW);
 }

                   Step 3: Programming Nodemcu and Arduino

                  Code:
                  #include <LiquidCrystal.h>
                  LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //16x2 lcd interface

                  int en = 3;//a-right motor  b-Left motor //
                  int af = 6;int ar = 7;
                  int bf = 5;int br = 4;

                  int a0=14 , a1=15 , a2= 16 ,a3= 17, a4= 18;//from nodemcu D0 to D4//

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

                   pinMode(en,OUTPUT);
                   pinMode(ar,OUTPUT);pinMode(af,OUTPUT);
                   pinMode(bf,OUTPUT);pinMode(br,OUTPUT);

                   pinMode(a0,INPUT); pinMode(a1,INPUT); pinMode(a2,INPUT);
                   pinMode(a3,INPUT); pinMode(a4,INPUT);

                   digitalWrite(en,HIGH);
                  // loading();
                  }

                  void loop() {
                    
                    if ( digitalRead(a0) == HIGH ) //forward//
                   {
                    lcd.setCursor(0, 1);
                    lcd.print("FORWARD "); 
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, LOW);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, LOW);
                   }
                     if (digitalRead(a1) == HIGH) //backward//
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("BACKWARD"); 
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a2) == HIGH)  //RIGHT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("RIGHT     ");     
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br,LOW);
                        } 
                    if (digitalRead(a3) == HIGH)//LEFT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("LEFT      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar,LOW);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a4) == HIGH)//STOP
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("STOP      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                      }  
                    else
                    {
                    lcd.setCursor(0, 1);
                    lcd.print("        ");          
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                     }

                  Conclusion:

                  You can easily build this. you can add lights to the robot and also other features using nodemcu. here is working video of the robot.
                  https://youtu.be/UsY_pJP5PVc

                  Also like and subscribe the channel.

                  RCA composite cable for Raspberry Pi -Solved Problem

                  Converting your old CRT TV to a Raspberry Pie display is matter of great excitement. Raspberry Pi comes with many OS such as Raspbian OS, Retro Gaming OS-"Retropie", Media Centre OS-"OSMC" etc are helping getting good User experience.

                  When it comes to Old CRT TV they don't have in-built HDMI ports Instead they have AV ports. You might have seen AV cable between your set-up box and TV.

                  • To play via R-Pi you need HDMI to AV converter (expensive and not discussed here)
                  or
                    • RCA and AV composite cable
                    What problem arises!!!
                    There is bit difference between pin configuration on Raspberry Pi and other devices. This has been shown below.

                    So it is clear that the pin "video" and "ground"on 3.5mm jack is interchanged in case of RPi. To solve this you should buy RPi specified cables or DIY a female connector like me. So needed item are:
                    • AV female pins
                    • 3.5mm RCA pin
                    • wires and soldering material
                    Solder the wire according to the given figure below.
                    The out come looks like this.

                    Plug it to your TV and enjoy gaming and media like never before. Humming sound may arises due to interference.
                    **In OSMC OS goto setting and find Audio output option, there change the option to AV mode, then you will find zero noise or humming sound.
                    **You can buy readily modified cables at adafruit here thelink.
                    ##Thank you##

                    “SOLAR TRACKER” USING ARDUINO


                    Solar power is renewable energy source and Solar panel helps in converting the solar power to electric power.
                    Solar tracker is a device which is used to sense solar intensity and rotate the solar panel in that respective direction. It would help in getting maximum solar energy through the solar panel and to its electrical conversion.

                    #wiki_stuffs: Orientation and inclination

                    A solar cell performs the best when its surface is perpendicular to the sun's rays, which change continuously over the course of the day and season. It is a common practice to tilt a fixed PV module (without solar tracker) at the same angle as the latitude of array's location to maximize the annual energy yield of module. For example, rooftop PV module at the tropics provides highest annual energy yield when inclination of panel surface is close to horizontal direction.
                    #wiki_stuffs: A solar tracker is a device that orients a payload toward the Sun. Payloads are usually solar panelsparabolic troughsfresnel reflectorslenses or the mirrors of a heliostat.
                    Things we need!!
                    • 1.      Solar panel (not necessarily a big one a mini could be better)
                    • 2.      DC motor(servo better if you know coding it)
                    • 3.      Motor driver
                    • 4.      Board, Wood piece or panel holding structure.
                    • 5.      Arduino and jumper wires
                    • 6.      Two IR (Infrared) sensors and resistor and diodes.
                    • 7.      Power source (12V or a power bank might work great)
                    • 8.    Incandescent bulb for testing purpose
                    Whats the Idea??
                    The idea is mounting two sensors and two ends of the solar panel and measuring the solar intensity via Arduino and then Arduino commands to tilt the panel toward that direction in which there is more intensity until the intensity of both the sensors became nearly equal. The tilting action can be done by motor and driving circuit.


                    Concept diagram for solar tracker.



                    Build IR Sensor!!


                    • You can easily find IR Receivers near by electronics store and build the above circuit.
                    • Don't forget to place diodes at output it will decrease interference.
                    • SEE REF:http://www.ganeshgadgets.co.in/2017/08/


                    How it looks when it is built!!





                    Coding!!!
                    Coding is simple one. That is the tilting process going on until the difference between the sensor values become less than desired value.
                    ////////////////////////////Code Solar tracker////////////////////////////////////
                    int br = 3;//motor output reverse
                    int bf = 2;//motor output forward //you can use enable at pwm output or make iy short to 5v.

                    int a4=0,a5=0; //analog sensor input
                    int approx=10; //difference limit
                    void setup() {

                      pinMode(bf,OUTPUT);
                      pinMode(br,OUTPUT);
                      pinMode(A4,INPUT);
                      pinMode(A5,INPUT);
                      Serial.begin(9600);

                    }

                    void loop() {
                     a4=analogRead(A4);
                     a5=analogRead(A5);

                     Serial.print(a4);
                      Serial.print(' ');
                      Serial.print(a5);
                      Serial.print(' ');
                      Serial.print(a5-a4);
                      Serial.println(' ');


                    if(a4>a5)
                    {
                    int diff=a4-a5;
                        if(diff > approx)
                        {
                           digitalWrite(bf,HIGH);
                           digitalWrite(br,LOW);
                        }
                        else{digitalWrite(bf,HIGH);
                             digitalWrite(br,HIGH);}
                     }

                    if(a4<a5)
                    {
                    int diff=a5-a4;
                        if(diff > approx)
                        {
                           digitalWrite(bf,LOW);
                           digitalWrite(br,HIGH);
                        }
                         else{digitalWrite(bf,HIGH);
                             digitalWrite(br,HIGH);}
                      } 
                     delay(50);
                     }
                    //////////////////////////////end//////////////////////////////////////

                    Its a good project for students to start with hope you like it.

                    IOT Switch using NodeMcu and Blynk app

                    The Internet of Things (IoT) is the network of physical devices, vehicles, home appliances, and other items embedded with electronicssoftwaresensorsactuators, and connectivity which enables these things to connect, collect and exchange datacreating opportunities for more direct integration of the physical world into computer-based systems, resulting in efficiency improvements, economic benefits, and reduced human exertions.(that's IOT from wiki)

                    A simple beginners IOT based switching action is done in this project.

                    Things we need in this project is:
                    1. NodeMcu
                    2. 1 led with 200ohm resister.
                    3. Arduino IDE and Blynk library
                    4. Blynk App on your phone.

                    What's NodeMcu??
                    NodeMCU is an open source IoT platform.It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.The term "NodeMCU" by default refers to the firmware rather than the development kits.(source: https://en.wikiphttps://en.wikipedia.org/wiki/NodeMCUedia.org/wiki/NodeMCU)



                    First try to install NodeMcu board!!
                    1. Go to: tools\board\board manager\esp8266 (search online)
                    else if not found
                    2. goto file\preferences then look for additional board manager urls. paste "http://arduino.esp8266.com/stable/package_esp8266com_index.json" and repeat step-1 install esp8266 board from there.

                    Blynk Library:
                    Search for blynk Library or simply download it from:https://github.com/blynkkk/blynk-library

                    After downloading it:
                    1. Decompress and paste the folder in Arduino library present in documents. (e.g. paste it at C:\Users\*****\Documents\Arduino\libraries
                    2. Start arduino IDE and you can see custom example of BLYNK library at file\examples.
                    3. Connect nodeMce to PC. choose correct board,in my case-NodeMCU 1.0(ESP 12E module). Select the correct COM port(select the com which appears after connecting nodeMcu).
                    4. In arduino IDE go to:files\examples\blynk\boards_wifi\esp8266_standalone.
                    5. 3 things to edit here a-"YourAuthToken", b-"YourNetworkName", c-"YourPassword"
                        'b' is your wifi network name (must connceted to internet) and 'c' is password set for that wifi network.  "YourAuthToken"-this will be discussed later after using the blynk app. After getting the authToken replace it and burn the code to nodeMcu.
                    6. Press reset. Watch connection Status on serial monitor. 

                    Jobs with the blynk App:
                    1. Download blynk App





                    2.Open the app login with FB or other methods.
                    3.Click on New project. Name the project(e.g. Iotswitch_gg). Choose Device: NodeMCU. Then create.
                    4.Authtoken is sent to your mentioned Email. Copy the authtoken and replace it in the code in nodeMCU. You can also get the Authtoken in the project setting.
                    5. Follow the steps in the app.

                    Hope you get it right!!!
                    KEEP VISITING MY BLOG.